Jump to content

Assigning a Variable to a Variable within a loop


Recommended Posts

Hello,

I am trying to loop through 15 times and change the variable each time but I do not think it is working even know it is showing the proper variable ($C14Select) in the messagebox popup. 

Essentially I have 15 iterations of $C14Select, but each one goes up in number, ie. $C15Select, $C16Select, etc. For each loop I am trying to change the variable to the corresponding $C__Select variable. When I change $C14Select in the messagebox portion to eval($C14Select) I do not get anything back so I am not sure if I am using that right either..

Note: all of my variables are already defined prior to this portion of the code.

Is there something I am doing wrong or should the below code be working properly?

 

$CHN = 14 
Global $CArray[15]
For $i = 0 to UBound($CArray) -1
$C14Select = "$C"&$CHN&"Select"

IF number(GUICtrlRead($C14Select)) = 1 then


MsgBox($MB_SYSTEMMODAL, "Title", GUICtrlRead($C14Select), 10)
endif

$CHN = $CHN + 1 

Next

 

 

Edit: Looks like this seems to give me the proper results in Messagebox:

$CHN = 14 
Global $CArray[10]
For $i = 0 to UBound($CArray) -1
            $CRR = "CRR" & $CHN
            $CExtract = StringSplit($CRR, " ")
$C14Select = GUICtrlRead(Eval("C"&$CHN&"Select"))


If Number($CExtract[2]) >= 15 and number($C14Select) = 1 Then

MsgBox($MB_SYSTEMMODAL, "Title", $CRR & ": " & $C14Select, 10)
endif

$CHN = $CHN + 1 

Next

 

 

Edited by Nick3399
Link to post
Share on other sites

You would have to use Assign/Eval to get a string as a variable, alternatively you could just change your controls to use an array for example:

#include <GUIConstantsEx.au3>

Global $g_idCheckbox[6] = [5]
Example()

Func Example()
    Local $iYAxis = 10
    Local $hGUI = GUICreate("Example", 300, 170)
    For $i = 1 To $g_idCheckbox[0]
        $g_idCheckbox[$i] = GUICtrlCreateCheckbox("Item " & $i, 10, $iYAxis, 185, 20)
        GUICtrlSetState(-1, Random(0,1,1))
        $iYAxis += 25
    Next
    Local $idProcess = GUICtrlCreateButton("Process", 10, $iYAxis, 185, 30)
    GUISetState(@SW_SHOW, $hGUI)
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idProcess
                For $i = 1 To $g_idCheckbox[0]
                    If GUICtrlRead($g_idCheckbox[$i]) = $GUI_CHECKED Then
                        MsgBox(0, "", GUICtrlRead($g_idCheckbox[$i], 1) & " = Checked")
                    Else
                        MsgBox(0, "", GUICtrlRead($g_idCheckbox[$i], 1) & " = Unchecked")
                    EndIf
                Next
        EndSwitch
    WEnd
EndFunc

 

Link to post
Share on other sites
16 minutes ago, Subz said:

You would have to use Assign/Eval to get a string as a variable, alternatively you could just change your controls to use an array for example:

#include <GUIConstantsEx.au3>

Global $g_idCheckbox[6] = [5]
Example()

Func Example()
    Local $iYAxis = 10
    Local $hGUI = GUICreate("Example", 300, 170)
    For $i = 1 To $g_idCheckbox[0]
        $g_idCheckbox[$i] = GUICtrlCreateCheckbox("Item " & $i, 10, $iYAxis, 185, 20)
        GUICtrlSetState(-1, Random(0,1,1))
        $iYAxis += 25
    Next
    Local $idProcess = GUICtrlCreateButton("Process", 10, $iYAxis, 185, 30)
    GUISetState(@SW_SHOW, $hGUI)
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $idProcess
                For $i = 1 To $g_idCheckbox[0]
                    If GUICtrlRead($g_idCheckbox[$i]) = $GUI_CHECKED Then
                        MsgBox(0, "", GUICtrlRead($g_idCheckbox[$i], 1) & " = Checked")
                    Else
                        MsgBox(0, "", GUICtrlRead($g_idCheckbox[$i], 1) & " = Unchecked")
                    EndIf
                Next
        EndSwitch
    WEnd
EndFunc

 

Hi - first off thank you for the reply.

I somehow seemed to get my code working without using either of the methods you mentioned. I have only tested so far using Messagebox but I am getting the expected values of 1 for the CXXSelect variables and only getting where value >= 15 and it is selected via GUI.

Do you know why or how this is working?

 

 

$CHN = 14 
Global $CArray[10]
For $i = 0 to UBound($CArray) -1
            $CRR = "CRR" & $CHN
            $CExtract = StringSplit($CRR, " ")
$C14Select = GUICtrlRead(Eval("C"&$CHN&"Select"))


If Number($CExtract[2]) >= 15 and number($C14Select) = 1 Then

MsgBox($MB_SYSTEMMODAL, "Title", $CRR & ": " & $C14Select, 10)
endif

$CHN = $CHN + 1 

Next


 

Edited by Nick3399
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...