Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Stored Variable
#1
Hi,

Sorry if this seems a simple question, I have had a go myself but to no avail. What I want to do is to store a variable, as in this PHP code:

Code:
Copy      Help
<?php
  $test = "hello";
  echo $test
?>

But in QM.

It's only so I don't have to keep typing the same thing out, and when I want to change it, I only have to do it once. It's probably something very simple.

Any help appreciated, thanks.
#2
In QM, variables must be at first declared. Examples:

Code:
Copy      Help
str test ;;declare string variable test
test="hello" ;;assign string
out test ;;display it

;or
str test2="hello" ;;declare and assign in single line
;...


;or
str test3 test4 ;;declare 2 variables in single line

;or
str test5("hello") test6("again") ;;declare 2 variables and assign in single line

;For integer values, use int instead of str. For floating-point - double.
;By default, variables are local. To declare a global variable, use +, eg str+
#3
That is perfect, thank you very much Big Grin

Your software is the most useful I have come across in a very long time, so many uses.....

Gintaras Wrote:In QM, variables must be at first declared. Examples:

Code:
Copy      Help
str test ;;declare string variable test
test="hello" ;;assign string
out test ;;display it

;or
str test2="hello" ;;declare and assign in single line
;...


;or
str test3 test4 ;;declare 2 variables in single line

;or
str test5("hello") test6("again") ;;declare 2 variables and assign in single line

;For integer values, use int instead of str. For floating-point - double.
;By default, variables are local. To declare a global variable, use +, eg str+
#4
Sorry Gintaras, just one more question.

How would I go about making the following to work (the '+ 1' bit)?

Code:
Copy      Help
str test ;;declare string variable test
test="8" ;;assign string
out (test + 1) ;;display test +  1 (=9)

Thanks again.
#5
Use int instead of str, and no quotes.

int test ;;declare integer variable test
test=8 ;;assign integer value
out (test + 1) ;;display test + 1 (=9)

Or, if it must be string, convert it to integer to do calculations:

str test ;;declare string variable test
test="8" ;;assign string

int i=val(test) ;;convert to integer
i=i+1 ;;or just i+1
test=i ;;convert to string

out test


Forum Jump:


Users browsing this thread: 1 Guest(s)