Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Create a name of variable by the content of another variable
#1
Here is a interesting question! :roll:
str s="apple"
str apple ;; varable name is determined by variable content of s.

Can QM create a name of variable by the content of another variable?
like the above example, moreover

int i=2; str s="apple"

Automatically, to create a variable's name through concatenatig i and s variables
the new variables should be similar to

str apple2="any word"
str applepie="other words"

out apple[2]
out apple[pie] ;; the suffix "2" or "pie" are added to "apple" to form a new variable
=========================
Can QM system functions allow variable names to be concatenated through any combination of character
expressions, numeric expressions, or existing variables?
#2
Macro VarVar help
Code:
Copy      Help
;This class allows to use variables whose names can be created at run time, eg from values of other variables.

;Add() creates variable and optionally sets value.
;Set() sets value.
;GetLpstr() gets value as string.
;GetInt() gets value as integer.

;Add2 and other "2" functions allow to compose variable names from 2 parts.

;Add() functions trow error if the variable already exists.
;Other functions throw error if the variable does not exist.
;The errors are thrown at run time.

;The scope (local, thread or global) of the variables is the same as of the VarVar variable.
;The variables don't have a type.
;;;;With Add() and Set() functions, value can be string or numeric.
;;;;To get value of lpstr type, use GetLpstr() functions. The value is temporary, so please assign it to a str variable if need to use later.
;;;;To get value of int type, use GetInt() functions.
;;;;To get value of other types (double, long), add member functions that would get lpstr and convert it to other type.


;EXAMPLES

#compile "__VarVar"
VarVar v

str s="apple"
int i=2

v.Add(s "green") ;;createvariable apple="green"
out v.GetLpstr(s) ;;out apple
v.Set(s 5) ;;apple=5
out v.GetInt(s) ;;out apple

v.Add2(s i "red") ;;createvariable apple2="red"
out v.GetLpstr2(s i) ;;out apple2
v.Set2(s i 10) ;;apple2=10
out v.GetInt2(s i) ;;out apple2


Attached Files
.qml   VarVar.qml (Size: 2.77 KB / Downloads: 314)


Forum Jump:


Users browsing this thread: 1 Guest(s)