Jump to content

[Solved] GUICtrlRead each variable without array


Recommended Posts

Hello, how do I do my GUI to read all variable $b1 $b2 etc... checkboxes states without having to write a line for each checkbox, because I will add many in the future. I tried this but it doesn't read anything:

For $i = 0 To 23
    Assign("b"&$i, GUICtrlCreateCheckbox($i, 10, 30 + (20 * $i), 65, 17))
Next

And:

For $i = 0 To 23
         If GUICtrlRead($b&$i) = $GUI_CHECKED Then ($v&$i) = 2
       Next

Thanks for the help ! :P

Edited by Elliotest
Link to comment
Share on other sites

execute...

$sSomething1 = "test1"
$sSomething2 = "test2"

For $i = 1 To 2
    ConsoleWrite(Execute("$sSomething" & $i) & @CRLF)
Next

put the execute into your GuiCtrlRead

Console Output:

test1
test2

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

3 minutes ago, jdelaney said:

execute...

$sSomething1 = "test1"
$sSomething2 = "test2"

For $i = 1 To 2
    ConsoleWrite(Execute("$sSomething" & $i) & @CRLF)
Next

put the execute into your GuiCtrlRead

I did 

If GUICtrlRead(Execute("$b"&$i)) = $GUI_CHECKED Then (Execute("$v"&$i)) = 2

But still getting 0 to the variable $v1 even if checkbox is checked

Link to comment
Share on other sites

GuiCtrlGetState to get the checked state.

Or, GuiCtrlRead with the second param = 1

Use Eval (forgot about that one)...that one's much safer...execute can run some nasty stuff. (thanks Subz)

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

10 minutes ago, Subz said:

Sorry missed the Assign, you should be able to use GuiCtrlRead(Eval("b" & $i))

If GUICtrlRead(Eval("b"&$i)) = $GUI_CHECKED Then ($v&$i) = 2

Either it doesnt read the checkbox or it doesn't put it in $v1 or else $v variable

8 minutes ago, jdelaney said:

GuiCtrlGetState to get the checked state.

Or, GuiCtrlRead with the second param = 1

I will give it a try

Edit: same thing

Edited by Elliotest
Link to comment
Share on other sites

Oops, my mistake:

Example3()

Func Example3()
    GUICreate("My GUI (GetControlState)")
    Local $idCheckbox = GUICtrlCreateCheckbox("checkbox", 10, 10)
    GUICtrlSetState(-1, 1) ; checked

    GUISetState(@SW_SHOW) ; will display an empty dialog box

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

        EndSwitch
        $b = GUICtrlRead(Eval("idCheckbox"))=$GUI_CHECKED
        ConsoleWrite($b & @CRLF)
    WEnd
EndFunc   ;==>Example

This doesn't have all the required includes.

Edit: Eval works, just didn't remove the '$'

 

You'll need to use 'assign' to set the variable value:

$value1 = "0"
Assign ( "value" & 1, "Test")
ConsoleWrite($value1 & @CRLF)

 

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

2 minutes ago, jdelaney said:

Oops, my mistake...keep using execute, and guictrlread:

Example3()

Func Example3()
    GUICreate("My GUI (GetControlState)")
    Local $idCheckbox = GUICtrlCreateCheckbox("checkbox", 10, 10)
    GUICtrlSetState(-1, 1) ; checked

    GUISetState(@SW_SHOW) ; will display an empty dialog box

    ; Loop until the user exits.
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop

        EndSwitch
        $b = GUICtrlRead(Execute("$idCheckbox"))=$GUI_CHECKED
        ConsoleWrite($b & @CRLF)
    WEnd
EndFunc   ;==>Example

This doesn't have all the required includes.

I think you misunderstood what my program do. It creates 23 checkboxes and read them all in order to after write them in a ini. But for ini I will try to find myself because for now I'm focusing on the data reading of my checkboxes.

Thanks for your answers. 

Link to comment
Share on other sites

I've edited my above post....re-read it.

It answers all your basic questions...if you want specific answers, provide the script for us to fix.

The gui example I provided is to show it's correctly getting the state of the checkbox...keep clicking it, and see the output update.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

2 minutes ago, jdelaney said:

I've edited my above post....re-read it.

It answers all your basic questions...if you want specific answers, provide the script for us to fix.

Func Example()
$hGUI = GUICreate("Example", 1800, 900)
$idClose1 = GUICtrlCreateButton("Close", 1750,850)
For $i = 0 To 23
    Assign("b"&$i, GUICtrlCreateCheckbox($i, 10, 30 + (20 * $i), 65, 17))
Next
GUISetState(@SW_SHOW, $hGUI)
    $idMsg = GUIGetMsg()
    While ($idMsg <> $GUI_EVENT_CLOSE) And ($idMsg <> $idClose1)
       For $i = 0 To 23
         If GUICtrlGetState(Eval("$b"&$i)) = $GUI_CHECKED Then ($v&$i) = 2
       Next
        $idMsg = GUIGetMsg()
     WEnd
For $i = 0 To 23
   Assign("bs"&$i, GUICtrlRead(Eval"$b"&$i))
IniWrite("C:\Users\Elliotest\Desktop\Config.txt","Section1","sec"&$i-1,$bs&$i)
Next
MsgBox(0,"test",$v1)
    GUIDelete($hGUI)
 EndFunc

Here is

Link to comment
Share on other sites

I'm only going to be able to guess what you are trying to do...Too many syntax errors up there...not efficient to keep passing around the same values to new variables either, but I kept it as you provided it:

Example()

Func Example()
    $hGUI = GUICreate("Example", 1800, 900)
    $idClose1 = GUICtrlCreateButton("Close", 1750,850)
    For $i = 0 To 23
        Assign("b"&$i, GUICtrlCreateCheckbox($i, 10, 30 + (20 * $i), 65, 17))
    Next
    GUISetState(@SW_SHOW, $hGUI)
    $idMsg = GUIGetMsg()
    For $i = 0 To 23
        If GuiCtrlRead(Eval("b"&$i)) = $GUI_CHECKED Then Assign("v"&$i,2)
        Assign("bs" & $i, GUICtrlRead(Eval("b" & $i)))
        IniWrite("Config.txt","Section1","sec" & $i,Eval("bs"&$i))
    Next
    GUIDelete($hGUI)
EndFunc

 

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

15 minutes ago, jdelaney said:

The gui example I provided is to show it's correctly getting the state of the checkbox...keep clicking it, and see the output update.

I will try this tomorrow because I'm tired and I don't understand anything now. Thank you for the help really. :)

Link to comment
Share on other sites

Added in a debug messagebox...just set the checks, and then close the box, and it will set the INI...it's setting the ini with the state, and not with True/False for checked/unchecked

Example()

Func Example()
    $hGUI = GUICreate("Example", 1800, 900)
    $idClose1 = GUICtrlCreateButton("Close", 1750,850)
    For $i = 0 To 23
        Assign("b"&$i, GUICtrlCreateCheckbox($i, 10, 30 + (20 * $i), 65, 17))
    Next
    GUISetState(@SW_SHOW, $hGUI)
    $idMsg = GUIGetMsg()
    MsgBox(1,1,"set the checkboxes")
    For $i = 0 To 23
        If GuiCtrlRead(Eval("b"&$i)) = $GUI_CHECKED Then Assign("v"&$i,2)
        Assign("bs" & $i, GUICtrlRead(Eval("b" & $i)))
        IniWrite("Config.txt","Section1","sec" & $i,Eval("bs"&$i))
    Next
    GUIDelete($hGUI)
EndFunc

 

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
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...