Jump to content

Option 'ExpandVarStrings': can I read the variable to read from from a variable?


SadBunny
 Share

Recommended Posts

The following code:

Opt("ExpandVarStrings", True)

$string1 = "something"
$string2 = "another thing"

$try = "this"

$stringToUse="string1"

; Test bit 1
ConsoleWrite("=====" & @CRLF)
ConsoleWrite("Test: '$try$', '$" & $stringToUse & "$'@CRLF@")
ConsoleWrite("-----" & @CRLF)

; Test bit 2
ConsoleWrite("=====" & @CRLF)
ConsoleWrite("Test: '$string2$'@CRLF@")
ConsoleWrite("-----" & @CRLF)

... produces:

Quote

=====
Test: 'this', '$string1$'@CRLF@-----
=====
Test: 'another thing'
-----

Main question: can I read the variable to read from from a variable, like I tried in "Test bit 1"? (If not, then why?)

Second question: if I cannot and if it is because the string expansion is done at "compile time" or something, why does it break the expansion of the "@CRLF@" after the concatenated string as well (but not before - the $try$ is expanded just fine), but then still just outputs a string and doesn't throw any errors?

I don't have a particular thing I'm trying to accomplish; another question about language files just made me remember that I used this option long ago and it helped me greatly for that purpose. This to say that I don't need other approaches. I'm just playing around - I probably wouldn't use the ExpandVarStrings for anything serious at this point anyway :)

Edited by SadBunny
2 tpyos.

Roses are FF0000, violets are 0000FF... All my base are belong to you.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...