Bagel Posted April 4, 2021 Share Posted April 4, 2021 I tried to looking into this quite a while ago and didn't really get anywhere. Again, I find myself needing to do this and am taking another stab at it. I've done some searching and can't find a way to get this to work. What I need to do is be able to construct a string that matches the name of a variable and then have the script I'm writing return the value of that variable using the constructed string. Below is an example: $Test6_Time = 86 $identifier = 6 $string = "$Test" & $identifier & "_Time" ConsoleWrite( "This is the actual variable: " & $Test6_Time & @CRLF & "This is the constructed variable: " & Eval($string) & @CRLF ) I thought that Eval() might do the trick but I obviously don't understand quite how Eval() works as it fails silently. Can anyone provide some help with this? Link to comment Share on other sites More sharing options...
TheXman Posted April 4, 2021 Share Posted April 4, 2021 (edited) $Test6_Time = 86 $identifier = 6 $string = "Test" & $identifier & "_Time" ConsoleWrite( "This is the actual variable: " & $Test6_Time & @CRLF & "This is the constructed variable: " & Eval($string) & @CRLF ) Console This is the actual variable: 86 This is the constructed variable: 86 Let's see if you can spot the difference. If not, click on "Reveal hidden contents". Spoiler When using Eval, the string that makes up the variable name should not include the "$". Edited April 4, 2021 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Bagel Posted April 4, 2021 Author Share Posted April 4, 2021 Oh it's you again! Now that's not fair, I included the "$" this time! Now what am I ACTUALLY missing? TheXman 1 Link to comment Share on other sites More sharing options...
Bagel Posted April 4, 2021 Author Share Posted April 4, 2021 Oh my god. Link to comment Share on other sites More sharing options...
TheXman Posted April 4, 2021 Share Posted April 4, 2021 2 minutes ago, Bagel said: Oh my god. Does that mean you figured it out? CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Bagel Posted April 4, 2021 Author Share Posted April 4, 2021 Not completely but I'm trying to figure out how to use it my scenario. Eval is still failing silently and I'm looking at Assign(). Link to comment Share on other sites More sharing options...
TheXman Posted April 4, 2021 Share Posted April 4, 2021 Did you not run my example? Also, did you not reveal the hidden contents, which is the explanation? CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Bagel Posted April 4, 2021 Author Share Posted April 4, 2021 Oh I see what I did. Thanks! Link to comment Share on other sites More sharing options...
JockoDundee Posted April 4, 2021 Share Posted April 4, 2021 40 minutes ago, Bagel said: Oh my god. @TheXman, I think he’s giving you a compliment TheXman 1 Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Bagel Posted April 4, 2021 Author Share Posted April 4, 2021 And kicking myself. In fleshing out some of my code I just made ANOTHER error in omitting an "$" where there should have been one. At least I was the one who caught it this time. Link to comment Share on other sites More sharing options...
TheXman Posted April 4, 2021 Share Posted April 4, 2021 (edited) 8 minutes ago, Bagel said: I just made ANOTHER error in omitting an "$" where there should have been one. Actually, the problem this time was the exact opposite. You added a "$" where one should not have been. $string = "$Test" & $identifier & "_Time" Should have been $string = "Test" & $identifier & "_Time" Edited April 4, 2021 by TheXman Musashi 1 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Bagel Posted April 4, 2021 Author Share Posted April 4, 2021 (edited) Yep, apparently I have some sort of subconscious issue that's crossing my wires when the "$" is involved. Not sure the forums can help me with that. Actually, I think this time it was a conceptual issue regarding variables. It's ingrained in me that variables MUST begin with a "$" and I think that led me to make an implicit assumption about what Eval() was doing. Conceptually, Eval() and Assign() etc. are a bit abstract to me. Thanks again for the help! Edited April 4, 2021 by Bagel Link to comment Share on other sites More sharing options...
JockoDundee Posted April 5, 2021 Share Posted April 5, 2021 4 hours ago, Bagel said: Yep, apparently I have some sort of subconscious issue that's crossing my wires when the "$" is involved. Perhaps the crossed wires come from the differing requirements of the sister functions Eval and Execute, as shown here: Eval: Local $iA = Eval("iB") Execute: Local $iA = Execute("$iB + 1") To my mind, Eval should be called Recall() (to go with Assign()), and Execute should be renamed Eval() cuz thats what it does. Musashi 1 Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
jchd Posted April 5, 2021 Share Posted April 5, 2021 And both functions should only be used in extremely rare, very specific situations. IMHO: never in regular code. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
JockoDundee Posted April 5, 2021 Share Posted April 5, 2021 2 hours ago, jchd said: IMHO: never in regular code. jchd 1 Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now