Jump to content

Converting Switch to Select


 Share

Recommended Posts

Hi all,

I'm not an experienced coder so i'm having some difficulties converting a Switch to a Select. Here is a piece of code to illustrate what i'm trying to do.

This function will normally show a tooltip when i hover over a button in a toolbar.

As commented the Switch is working as intended, but if i use the Select it is not working, it will actually show the "New" tooltip for every button instead of the relative tooltip.

Anyone could give an explanation of what i'm doing wrong? tx alot

EDIT: i want to convert to "Select" because later on i will ad other cases to be checked for instead of only "Case $iCode = $TTN_GETDISPINFOW" in this example.

; Handle WM_NOTIFY messages
Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam, $ilParam
    Local $tInfo, $iID, $iCode
    $tInfo = DllStructCreate($tagNMTTDISPINFO, $ilParam)
    $iCode = DllStructGetData($tInfo, "Code")
    
;~  ********** Select variation (does not work) *****************
    Select
        Case $iCode = $TTN_GETDISPINFOW
            $iID = DllStructGetData($tInfo, "IDFrom")
            Select
                Case $iID
                    Select
                        Case $idNew
                            DllStructSetData($tInfo, "aText", "New")
                        Case $idOpen
                            DllStructSetData($tInfo, "aText", "Open")
                        Case $idSave
                            DllStructSetData($tInfo, "aText", "Save")
                        Case $idHelp
                            DllStructSetData($tInfo, "aText", "Help")
                    EndSelect
            EndSelect
    EndSelect

;~ switch variation (works as intended) **************************
;~  If $iCode = $TTN_GETDISPINFOW Then
;~      $iID = DllStructGetData($tInfo, "IDFrom")
;~      Switch $iID
;~          Case $idNew
;~              DllStructSetData($tInfo, "aText", "New");~
;~          Case $idOpen
;~              DllStructSetData($tInfo, "aText", "Open")
;~          Case $idSave
;~              DllStructSetData($tInfo, "aText", "Save")
;~          Case $idHelp
;~              DllStructSetData($tInfo, "aText", "Help")
;~      EndSwitch
;~  EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Edited by jorgev
Link to comment
Share on other sites

Why do you want to use a Select? The Switch is really recommanded especially when you are comparing always the same var.

Select
    Case $iID = $idNew
        DllStructSetData($tInfo, "aText", "New")
    Case $iID = $idOpen
        DllStructSetData($tInfo, "aText", "Open")
    Case $iID = $idSave
        DllStructSetData($tInfo, "aText", "Save")
    Case $iID = $idHelp
        DllStructSetData($tInfo, "aText", "Help")
EndSelect
Br, FireFox. Edited by FireFox
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...