D3fr0s7 Posted May 27, 2020 Share Posted May 27, 2020 I've set up multiple variables that recall colors for 6 sets of data. They are stored in an ini file "Variable". The variables for one set are $VarAA, $VarAB, $VarAC, $VarAD, $VarAE, and $VarAF. The next set is $VarBA, $VarBB, $VarBC, $VarBD, $VarBE, $VarBF, and each of these sets of data are a set from "XA to XF" with the X corresponding to "A to F" for a total of 36 variables. My code looks like this so far, and I know that the code will not work with that $Var[$iAscii]A. My question is, is there a way I can achieve what I'm trying to do? Or do you suggest I try a different method? Any help would be appreciated. I'm trying to make the script adjust the variable it will look for automatically, without me having to code 5 more times the same line of code but with different variables. For the String, the code will work as intended, but not for the Variable. $Var[$iAscii]A - "$Var$iAscii$A", is there like an ExpandVarStrings but for variables in general? AutoItSetOption ( "ExpandVarStrings", 1 ) For $x = 0 to 9 For $i = 65 to 70 ; ASCII character codes for range of "A to F" $iAscii = Chr ( $i ) If $Var[$iAscii]A = IniRead ( "Variable", "$g$.$g$$g$", "Var$iAscii$A" ) Then ; Code to run EndIf Next $x = $x + 1 Next The code is supposed to run when it finds a match between data found (Stored in $Var[X]A) and data within the ini file (Stored in key string "Var$X$A"). I'm asking if it can adjust the variable to look for on its own, much how it can do so with the IniRead string with ExpandVarStrings enabled. Link to comment Share on other sites More sharing options...
therks Posted May 27, 2020 Share Posted May 27, 2020 While I think there's a better way to do this using real arrays, have a look at the Assign and Eval functions. They should help you accomplish what you're doing. My AutoIt Stuff | My Github Link to comment Share on other sites More sharing options...
Nine Posted May 27, 2020 Share Posted May 27, 2020 You cannot run this, the line will give you error: If $Var[$iAscii]A = IniRead ( "Variable", "$g$.$g$$g$", "Var$iAscii$A" ) Then I do not think it is necessary to use this Opt. Make sure you format your string correctly. To help you use some error handling messages (consoleWrite, msgBox). And stay away from assign and eval unless it is totally obviously advantageous. therks 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
D3fr0s7 Posted May 28, 2020 Author Share Posted May 28, 2020 Okay so, I had a look at the Assign and Eval functions and I don't believe they would've helped me accomplish what I wanted to. That or it didn't click with me. However, you're right about arrays being the better option. I looked into arrays more and was able to accomplish my task with the following test code: AutoItSetOption ( "ExpandVarStrings", 1 ) $VarAA = 1 $VarAB = 2 $VarAC = 3 $VarAD = 4 $VarAE = 5 $VarAF = 6 $VarBA = 7 $VarBB = 8 $VarBC = 9 $VarBD = 10 $VarBE = 11 $VarBF = 12 ; Declaring a 2 dimensional array Global $Var[2][6] = [[ $VarAA, $VarAB, $VarAC, $VarAD, $VarAE, $VarAF ],[ $VarBA, $VarBB, $VarBC, $VarBD, $VarBE, $VarBF ]] For $a = 0 to 1 For $b = 0 to 5 If $Var[$a][$b] = ($a*6)+$b+1 Then $VarX = $Var[$a][$b] MsgBox ( 0, "Test", "($a$*6)+$b$+1 = $VarX$" ) EndIf Next Next Thanks a lot for the guidance! therks 1 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