Jump to content

Array + Switch problem [RESOLVED]


Recommended Posts

Hi - i have built a GUI with 44 checkboxes belonging to an array of 44 variables...and i want to build a 'switch' to check whenever each one is getting checked or unchecked...my problem is i don't want to build a 'switch' with 44 case options...is there any way around this???

i.e.

I have an array ($Array) with 44 variables each one of them checkboxes...

While 1

$nMsg = GuiGetMsg()

Switch $nMsg

Case $Array[1]

.......

Case $Array[2]

......

Case $Array[3]

......

Is there any ways around that??

Thank you in advance

Edited by ARozanski
Link to comment
Share on other sites

I did something like this a while back. I can't clearly remember what I did but I think it might've been something like this

CODE
While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $array

For $i = 0 To UBound($array)

If $nMsg = $array[$i] Then

MsgBox(0,"Number","You clicked box number: " & $i)

Endif

Next

EndSwitch

WEnd

Link to comment
Share on other sites

You're welcome :P. If that's what you were looking for please put "[RESOLVED]" in your title,that way anyone searching with the same problem can find the solution easier.

Link to comment
Share on other sites

We all start somewhere. It's not a rule but it's good practice to help people out and assuming people actually use the search feature could save someone a needless post.

Link to comment
Share on other sites

also put this

$nMsg >= $Array[1]  And $nMsg <= $Array

so it is going to loop every time a

message happen since you use $array which is

an empty variable and will causes the loop to

run many times when you don't need it

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $nMsg >= $Array[1]  And $nMsg <= $Array[44]
            For $i = 0 To UBound($array)
                If $nMsg = $array[$i] Then
                    MsgBox(0, "Number", "You clicked box number: " & $i)
                EndIf
            Next
    EndSwitch
WEnd
Edited by komalo
[font="Palatino Linotype"][size="3"]AutoIt Script Examples :[/size][/font][font="Palatino Linotype"][size="3"]_CaptureBehindWindowGlass CMD for Windows Vista/Seven[/size][/font][left][/left][font="Palatino Linotype"][size="3"]Non AutoIt Script programs : Border Skin - Aero Glass On XP[/size][/font]
Link to comment
Share on other sites

also put this

$nMsg >= $Array[1]  And $nMsg <= $Array

so it is going to loop every time a

message happen since you use $array which is

an empty variable and will causes the loop to

run many times when you don't need it

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $nMsg >= $Array[1]  And $nMsg <= $Array[44]
            For $i = 0 To UBound($array)
                If $nMsg = $array[$i] Then
                    MsgBox(0, "Number", "You clicked box number: " & $i)
                EndIf
            Next
    EndSwitch
WEnd
How is $array an empty variable? He said his array ($array) had 44 checkboxes. Last time I checked 44 was far from empty.
Link to comment
Share on other sites

How is $array an empty variable? He said his array ($array) had 44 checkboxes. Last time I checked 44 was far from empty.

try this

#NoTrayIcon
Global $Array[10] = [1,2,3,4,5,6,7,8,9,10]
MsgBox("","Array",$Array)

and that was your code

While 1

$nMsg = GUIGetMsg()

Switch $nMsg

Case $array

For $i = 0 To UBound($array)

If $nMsg = $array[$i] Then

MsgBox(0,"Number","You clicked box number: " & $i)

Endif

Next

EndSwitch

WEnd

Edited by komalo
[font="Palatino Linotype"][size="3"]AutoIt Script Examples :[/size][/font][font="Palatino Linotype"][size="3"]_CaptureBehindWindowGlass CMD for Windows Vista/Seven[/size][/font][left][/left][font="Palatino Linotype"][size="3"]Non AutoIt Script programs : Border Skin - Aero Glass On XP[/size][/font]
Link to comment
Share on other sites

Link to comment
Share on other sites

ARozanski

I think this be faster:

#include <GuiConstantsEx.au3>

Opt("GuiOnEventMode", 1)

Global $aCheckbox[44]
Dim $iLeft = 20, $iTop = 5

$hGUI = GUICreate("Test", 400, 300)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

For $i = 0 To UBound($aCheckbox) - 1
    GUICtrlCreateCheckbox("Checkbox " & $i + 1, $iLeft, $iTop, 85, 20)
    GUICtrlSetOnEvent(-1, "_Check")
    
    $iLeft += 85
    If $iLeft >= 350 Then
        $iLeft = 20
        $iTop += 20
    EndIf
Next

GUISetState()

While 1
    Sleep(100)
WEnd

Func _Check()
    ConsoleWrite(GUICtrlRead(@GUI_CtrlId, 1) & " Is checked = " & (GUICtrlRead(@GUI_CtrlId) = $GUI_CHECKED) & @LF)
EndFunc

Func _Exit()
    Exit
EndFunc

:P

Edited by rasim
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...