Sign in to follow this  
Followers 0
Manticore

Loop through 2Darray using Switch Cases

5 posts in this topic

#1 ·  Posted

I'm writing a soft where I have Parent GUI and Child GUI. I have an 2D array which contain 2 GUI element 1 is an InputField and 1 is a Check box. I want make it so that when ever I check the Box it will enable the InputField and vise versa

This is part of the code that is not working

 

  Case $g_hLMenuFrm[0]
            Switch $aGUIMsg[0] ; Now check for the messages for $g_hLMenuFrm[0]
                Case $g_aSIDEItem[1][0] To $g_aSIDEItem[1][(UBound($g_aSIDEItem, 2) - 1)]
                    For $r = 0 To UBound($g_aSIDEItem, 2) - 1
                        If $aGUIMsg[0] = $g_aSIDEItem[1][$r] Then
                            _Enable($g_aSIDEItem[1][$r], $g_aSIDEItem[0][$r])
                        EndIf
                    Next
            EndSwitch

I dont know what am I doing wrong if I write each one out like this then it work:

   

Case $g_hLMenuFrm[0]
            Switch $aGUIMsg[0] ; Now check for the messages for $g_hLMenuFrm[0]
                Case $aGUIMsg[0] = $g_aSIDEItem[1][0]
                    _Enable($g_aSIDEItem[1][0], $g_aSIDEItem[0][0])
                Case $aGUIMsg[0] = $g_aSIDEItem[1][1]
                    _Enable($g_aSIDEItem[1][1], $g_aSIDEItem[0][1])
            EndSwitch

I know that I can do It this way

   

Case $g_hLMenuFrm[0]
            For $r = 0 To UBound($g_aSIDEItem, 2) - 1
                If $aGUIMsg[0] = $g_aSIDEItem[1][$r] Then
                    _Enable($g_aSIDEItem[1][$r], $g_aSIDEItem[0][$r])
                EndIf
            Next

However, I want to know why the Switch Case is not working. I have no idea what I'm doing wrong if someone knows please guide me to a right direction thank you

Share this post


Link to post
Share on other sites



#2 ·  Posted

what kind of data are contained in the array "$ g_aSIDEItem"  ?

1 person likes this

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

#3 ·  Posted

@Chimp thank you for replying me after almost 8 hours i finally found my mistake. Turn out I have been viewing the array dimension wrong. I got it working now 

Share this post


Link to post
Share on other sites

#4 ·  Posted

However, Is there anyway to make this shorter?

 

Func LMenuCheck($default, $menuN)
    For $i = 0 To UBound($g_aLMenu, 1) - 1
        GUISetBkColor($COLOR_WHITE, $g_aLMenu[$i][1])
        If $default Then
            If $i = $menuN Then
                setLMenuLblColor($g_aLMenu[$i][0], "Selected")
                GUISetState(@SW_SHOW, $g_aLMenu[$i][1])
                GUICtrlSetState($g_cBtnBack, $GUI_HIDE)
            Else
                setLMenuLblColor($g_aLMenu[$i][0], "Default")
                GUISetState(@SW_HIDE, $g_aLMenu[$i][1])
            EndIf
        Else
            setLMenuLblColor($g_aLMenu[$i][0], "Default")
            GUISetState(@SW_HIDE, $g_aLMenu[$i][1])
        EndIf
    Next
EndFunc   ;==>LMenuCheck

 

Share this post


Link to post
Share on other sites

#5 ·  Posted

Perhaps this (untested)?
 

Func LMenuCheck($default, $menuN)
    For $i = 0 To UBound($g_aLMenu, 1) - 1
        GUISetBkColor($COLOR_WHITE, $g_aLMenu[$i][1])
        If $default And $i = $menuN Then
            setLMenuLblColor($g_aLMenu[$i][0], "Selected")
            GUISetState(@SW_SHOW, $g_aLMenu[$i][1])
            GUICtrlSetState($g_cBtnBack, $GUI_HIDE)
        Else
            setLMenuLblColor($g_aLMenu[$i][0], "Default")
            GUISetState(@SW_HIDE, $g_aLMenu[$i][1])
        EndIf
    Next
EndFunc   ;==>LMenuCheck

 

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