Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
check variable type
#1
1)
How can I check what type a variable is?
example
Macro Macro9
Code:
Copy      Help
ARRAY(int) i

;.
;. code
;.

out "i is 'ARRAY'"



2)
I want to check if file names or folder names end with a number.
I have this code
Macro Macro8
Code:
Copy      Help
str check_string="test_name0"
get_last_char(check_string)
int x=val(check_string)
out x

whith this function
Function get_last_char
Code:
Copy      Help
/

function str&check_string

str char
int q=len(check_string)
char.get(check_string q-1 1)

check_string=char


The problem is that the string "check_string" contains a string that ends with '0' (zero).
The 'val' command returns a zero if number is to big or it is not a number.
If I had a string that was "setup_v1.0" the "out x" would result in 0 in the output window.
But how do I know that zero is based on error or actually based on integer value zero?
#2
1. No. Why need it? If the variable is VARIANT, can check its vt member.

2.
Macro Macro1836
Code:
Copy      Help
str s="setup_v1.0"
if s.len and isdigit(s[s.len-1])
,out "ends with a number"

When need val:
int i j
i=val(s 0 j)
if j
,out "valid number, value %i, number string ends at %i" i j
#3
Ok thank you!
(i needed the first example to check if string or check if int, but there are other ways for that)
#4
I have another rather similar question :

Suppose a string variable s contains the name of another int variable.

Is it possible to output this int variable through s ?

Thanks in advance
#5
No. For normal variables, at run time exists only address, not name.

If need variables where you can have name at run time, can use environment variables, window properties, registry. See QM Help, Variable storage and scope (2). Also can try IStringMap.
#6
Dear Gintaras,

Many thanks for your very prompt reply.
Let me mention that I overcame this case using the following :

Macro temp
Trigger SF12     Help - how to add the trigger to the macro
Code:
Copy      Help
int tBM1=15
str s="tBM1"
str text.from("out " s)
mac newitem("temp_varout" text "Function" "" "\User\Temp" 1|128)

Best regards
Simos
#7
It works when the variable is global.

int+ tBM1=15
#8
Correct, I am sorry I did not say that in the beginning.


Forum Jump:


Users browsing this thread: 1 Guest(s)