Jump to content

Loop through 2Darray using Switch Cases


Recommended Posts

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

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

 

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...