Sign in to follow this  
Followers 0
Negative1

Syntax and variables

16 posts in this topic

Is something like this possible?

$temp is a 4-5 character string. The string is a name of an array once you add "$" to the front of that string and the array bit needs to vari also hints the $y inside the brackets.

I did all this code manually and it was 500 plus lines. Is this possible? If so can i get some help on the syntax or a redesign?

while $y <= "$"&$temp&"["&0&"]"
     GUICtrlSetData($causecode, "$"&$temp&"["&$y&"]")
     $y = $y + 2
WEnd

Thanks,

Negative1


What are we going to do tonight Brain?Same thing we do every night Pinky try to automate the world.

Share this post


Link to post
Share on other sites



while $y <= "$"&$temp&"["&0&"]"
     GUICtrlSetData($causecode, "$"&$temp&"["&$y&"]")
     $y = $y + 2
WEnd

Should be something like:

while $y <= $temp[0]
     GUICtrlSetData($causecode, $temp[$y])
     $y = $y + 2
WEnd

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

It's not what he meant, he can't be so weird ;]. He means, some sort of Eval with 4-5 character long strings (variable names)... Still I see no place for Eval in this case as it will involve another check or loop to use different variable names in the same statement so it's better to handle it via array of variables or something.

Share this post


Link to post
Share on other sites

while $y <= "$"&$temp&"["&0&"]"
     GUICtrlSetData($causecode, "$"&$temp&"["&$y&"]")
     $y = $y + 2
WEnd

Should be something like:

while $y <= $temp[0]
     GUICtrlSetData($causecode, $temp[$y])
     $y = $y + 2
WEnd
Thanks for the post. Dont think this works though. $temp itself is not an array it holds the name of the array to use since i'm using like 20 arrays in this code. $temp holds a string like this:

$temp = FC110

i have an array named

$FC110

while $y <= $FC110[0] ; [0] address of array = total number of array bits.
       guictrlsetdata($causecode, $FC110[$y])
wend

This is what i want it to do but since im using 20+ arrays i want to do it quickly using a variable name for the array to use.

Sorry if this is confusing its difficult for me to explain.

-1


What are we going to do tonight Brain?Same thing we do every night Pinky try to automate the world.

Share this post


Link to post
Share on other sites

So use Eval if the array holds variable names.

Share this post


Link to post
Share on other sites

So use Eval if the array holds variable names.

LMAO

$temp = eval($fcats[$x-1])

wow wow wow that's all i was missing thanks Authenticity!!!


What are we going to do tonight Brain?Same thing we do every night Pinky try to automate the world.

Share this post


Link to post
Share on other sites

BTW M23, nice work around but without any checking ^^ so it's probably the most unnecessary function in the world, i.e.:

Dim $a[2] = [5, 5], _
    $b[2] = [5, 5], _
    $c[2] = [5, 5], _
    $d[2] = [4, 4]
    
Dim $y = 4, $aVars[5] = [4, 'a', 'b', 'c', 'd']

For $i = 1 To $aVars[0]
    ConsoleWrite(_Eval(Eval($aVars[$i]), 0) & @TAB)
Next

ConsoleWrite(@LF)

Func _Eval($Var, $Element)
    Return $Var[$Element]
EndFunc

Share this post


Link to post
Share on other sites

So now Eval works with about 80% of the variables but I cant seam to get it to work with the variables declared here:

dim $c0001[1]
dim $c0002[1]
dim $c0003[1]
dim $c0011[1]
dim $c0012[1]
dim $c0013[1]
dim $c0014[1]
dim $c0015[1]

The problem happens at this line the code.

$temp = eval($causecat)

According to AutoIt Debugger.

$causecat = c0001

@error = 1

so $temp = 0 which causes me to get an error later on when i try to use $temp as an array which its suppose to be.

My best guess is that Eval is having problems with the consecutive zeros?


What are we going to do tonight Brain?Same thing we do every night Pinky try to automate the world.

Share this post


Link to post
Share on other sites

Look at the example above your post. Eval doesn't work with arrays.

Share this post


Link to post
Share on other sites

Look at the example above your post. Eval doesn't work with arrays.

But it is working with all the other arrays in fact it works with one that i named:

dim $j0001[1]

but just not any of the c0001

I really just don't understand why I'm getting an error here


What are we going to do tonight Brain?Same thing we do every night Pinky try to automate the world.

Share this post


Link to post
Share on other sites

Because it should hold the name of the variable and not the variable it-self:

Dim $a1[1] = ['1'], $a2[1] = ['2'], $a3[1] = ['3']
Dim $arr[3] = ['a1', 'a2', 'a3']

ConsoleWrite(Eval($arr[0]) & @LF) ; Won't work

For $i = 0 To 2
    ConsoleWrite(_Eval(Eval($arr[$i]), 0) & @LF)
Next


Func _Eval($avArr, $iElement)
    Return($avArr[$iElement])
EndFunc

It's a silly example but that is why you're getting the error, replace 'a1','a2','a3' with $a1,$a2,$a3 and you'll see.

Share this post


Link to post
Share on other sites

Because it should hold the name of the variable and not the variable it-self:

Dim $a1[1] = ['1'], $a2[1] = ['2'], $a3[1] = ['3']
Dim $arr[3] = ['a1', 'a2', 'a3']

ConsoleWrite(Eval($arr[0]) & @LF) ; Won't work

For $i = 0 To 2
    ConsoleWrite(_Eval(Eval($arr[$i]), 0) & @LF)
Next


Func _Eval($avArr, $iElement)
    Return($avArr[$iElement])
EndFunc

It's a silly example but that is why you're getting the error, replace 'a1','a2','a3' with $a1,$a2,$a3 and you'll see.

Here's the thing though the variable that i am using on to Eval does hold the name according to AutoIt Debugger the line where @error was set to 1 was:

$temp = eval($causecat)

$causecat = c0001 at the time of failure and i have a variable names $c0001

this same copy paste script works if i select the other choices that cause $causecat to equal j0001 or other names for example.

Almost everything is copy and pasted so it is working like 80% like i said however just these c000 groups are causing the error...


What are we going to do tonight Brain?Same thing we do every night Pinky try to automate the world.

Share this post


Link to post
Share on other sites

Can you post a snippet, including how you defined the $causecat variable?, more than that is needed.

Share this post


Link to post
Share on other sites

Can you post a snippet, including how you defined the $causecat variable?, more than that is needed.

Case $msg = $causecatcombo
        
        if GUICtrlRead($femto) = 1 Then
            $x = 2
            while $x <= $fcats[0]
                If GUICtrlRead($causecatcombo) = $fcats[$x] Then
                    $causecat = $fcats[$x-1]
                    $temp = eval($causecat);convert String to array variable
                    GUICtrlSetData($causecodecombo,"");clear cause code combo
                    GUICtrlSetState($causecodecombo,$GUI_ENABLE)
                    $y = 2                  
                    while $y <= $temp[0]
                        GUICtrlSetData($causecodecombo, $temp[$y]);set cause code combo box
                        $y = $y + 2
                    WEnd
                    $x = 999
                EndIf
                $x = $x + 2
            WEnd
        elseif guictrlread($excimer) = 1 Then
            $x = 2
            while $x <= $ecats[0]
                If GUICtrlRead($causecatcombo) = $ecats[$x] Then
                    $causecat = $ecats[$x-1]
                    $temp = eval($causecat);convert String to array variable
                    GUICtrlSetData($causecodecombo,"");clear cause code combo
                    GUICtrlSetState($causecodecombo,$GUI_ENABLE)
                    $y = 2                  
                    while $y <= $temp[0]
                        GUICtrlSetData($causecodecombo, $temp[$y])
                        $y = $y + 2
                    WEnd
                    $x = 999
                EndIf
                $x = $x + 2
            WEnd
        elseif guictrlread($phaco) = 1 Then
            $x = 2
            while $x <= $pcats[0]
                If GUICtrlRead($causecatcombo) = $pcats[$x] Then
                    $causecat = $pcats[$x-1]
                    $temp = eval($causecat);convert String to array variable
                    GUICtrlSetData($causecodecombo,"");clear cause code combo
                    GUICtrlSetState($causecodecombo,$GUI_ENABLE)
                    $y = 2                  
                    while $y <= $temp[0]
                        GUICtrlSetData($causecodecombo, $temp[$y])
                        $y = $y + 2
                    WEnd
                    $x = 999
                EndIf
                $x = $x + 2
            WEnd
        else
            GUICtrlSetData($causecodecombo,"")
            GUICtrlSetState($causecodecombo,$GUI_DISABLE)
        EndIf

Ok so the code works for the first two if statements when $femto or $excimer is = 1 but when i go to the $phaco fails. $pcats[] is an array that the odd cells contain array variable names and even cells contain strings that the user can select that correspond to the variable names. So $causecat= array bit of the string the user selects minus 1 to get the variable name that relates to that string. When i use AutoIt Debugger the value of $causecat is correct.

Hope i explained this well enough. The important part is that it works with the first if and the first elseif but not the second elseif.

thanks for all the time and help.


What are we going to do tonight Brain?Same thing we do every night Pinky try to automate the world.

Share this post


Link to post
Share on other sites

$causecat is correct but compared to what? Is $pcats array hold things like "$something" or "something"? and what about $fcats and $ecats? It still doesn't give the whole picture, sorry.

Share this post


Link to post
Share on other sites

$causecat is correct but compared to what? Is $pcats array hold things like "$something" or "something"? and what about $fcats and $ecats? It still doesn't give the whole picture, sorry.

OMG....

So $pcats array got its values for a text file and the c0001 line of the text file had a space after it so it was read as 6 characters..... ugh.

Sorry for wasting your time and thanks for the help.

-1


What are we going to do tonight Brain?Same thing we do every night Pinky try to automate the world.

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  
Followers 0