|
Post by untaimed18 on Jun 8, 2020 14:00:10 GMT -5
This is probably something easy to do, but I cannot figure out how to add two or more variables and place the SUM into another variable to be displayed. Is this possible in Liberty Basic? I've searched the help file and cannot get this to work. Any help would be appreciated.
|
|
|
Post by Chris Iverson on Jun 8, 2020 14:01:59 GMT -5
If the variables are already numeric variables, it's fairly straightforward.
sum = num1 + num2
If the variables are strings, you'll need to convert them to numbers first before adding them, using the VAL() function.
sum = val(num1$) + val(num2$)
|
|
|
Post by untaimed18 on Jun 8, 2020 14:24:39 GMT -5
Thanks Chris! I'll give that a try. I was attempting to use sum=val(num$+num2$).
|
|
|
Post by Chris Iverson on Jun 8, 2020 14:32:59 GMT -5
Ahh, yeah. That will... function, but it won't work. Not in the way you expect.
Basically, what that code does is this:
num$ = "12" num2$ = "34"
sum = val(num$+num2)
If you step through it:
sum = val("12"+"34")
Then
sum = val("1234")
Then
sum = 1234
Just as in the order of operations for mathematics, everything inside the parenthesis specifying arguments to a function are fully evaluated BEFORE executing the function. So num$ + num2$ is resolved first, and the combined string is passed into val().
|
|
|
Post by untaimed18 on Jun 8, 2020 14:42:58 GMT -5
Got it! Thanks!
|
|