Jump to content
Sign in to follow this  
SadBunny

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

Recommended Posts

SadBunny

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.

Share this post


Link to post
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
Sign in to follow this  

  • Similar Content

    • Burgs
      By Burgs
      Hello,
        I'd like to be able to create variables 'on the fly' by reading in some data from an SQLite database.  Using this data i'd like to create variables.  The data would be separated by colons (":")...'colon delimited'.  I would perform a 'StringSplit' on the data to create arrays holding each colon separated value.  Ideally I could then use these strings to create variables from them...possible?
        I know it cannot be done just piecing a string together such as "var = "$_" & 'some string'"... 
        I think it might work using the 'Assign' command...and there is an 'Opt' option to 'ExpandVarStrings' which seems to indicate it is possible to include a "$" within a string...however the documentation is a bit spotty on that.
        Can anybody confirm that these might be the best practices to create variables dynamically?  ...Perhaps there is another method I'm not thinking of...?   I thank you in advance.  Regards.  
×