Jump to content

Is there a way to adjust a variable to compare with the script itself?


Recommended Posts

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

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.  

 

Link to comment
Share on other sites

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!

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...