Jump to content

Select, Case Problems.


Recommended Posts

Current Code:

Func CheckCmd()
    $Check = GUICtrlRead($Main)
    Select
        Case $Check = "Help"
            GUICtrlSetData($Main, "Line1" & @CRLF & "Line2")
        Case $Check = "Clear"
            GUICtrlSetData($Main, "")
    EndSelect
EndFunc     ;==>CheckCmd

When help is typed enter pushed, Line1 Line2 should show etc. Help is appreciated.

Link to comment
Share on other sites

i got this from AutoIT examples folder

While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
                ;When button is pressed, label text is changed
                ;to combobox value
            Case $msg = $button1
                $data = GUICtrlRead($Combo_2)
                GUICtrlSetData($Label_1, $data)
        EndSelect
    WEnd

Hope it helps you.

UnderWorldVN- Just play the way you like it
Link to comment
Share on other sites

i got this from AutoIT examples folder

While 1
        $msg = GUIGetMsg()
        Select
            Case $msg = $GUI_EVENT_CLOSE
                ExitLoop
                ;When button is pressed, label text is changed
                ;to combobox value
            Case $msg = $button1
                $data = GUICtrlRead($Combo_2)
                GUICtrlSetData($Label_1, $data)
        EndSelect
    WEnd

Hope it helps you.

$Main is a edit box.
Link to comment
Share on other sites

#include <Constants.au3>
#include <EditConstants.au3> 
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate('Title', 300, 100)
$Edit = GUICtrlCreateEdit('', 10, 20, 280, 60, BitOR($ES_WANTRETURN, $__EDITCONSTANT_WS_HSCROLL,$ES_AUTOHSCROLL))
$hEdit = GUICtrlGetHandle(-1)

$hOldProc = _WinAPI_GetWindowLong($hEdit, $GWL_WNDPROC)
$hFunc = DllCallbackRegister('WndProc', 'long', 'hwnd;uint;wparam;lparam')
$pFunc = DllCallbackGetPtr($hFunc)

_WinAPI_SetWindowLong($hEdit, $GWL_WNDPROC, $pFunc)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

GUIDelete()
DllCallbackFree($hFunc)
Exit

Func CheckCmd($sString)
    
EndFunc  ;==>CheckCmd

Func WndProc($hwnd, $iMsg, $iwParam, $ilParam)
    If $iMsg = $WM_CHAR Then
        If $iwParam = 13 Then
            Switch GUICtrlRead($Edit)
                Case "help"
                    GUICtrlSetData($Edit, "Line1" & @CRLF & "Line2")
                Case "clear"
                    GUICtrlSetData($Edit, "")
            EndSwitch
        EndIf
    EndIf
    
    Return _WinAPI_CallWindowProc($hOldProc, $hwnd, $iMsg, $iwParam, $ilParam)
EndFunc

Link to comment
Share on other sites

Your code is OK.

Are you sure the function CheckCmd() is called?

You can see that it works:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 347, 120, 192, 124)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$Main = GUICtrlCreateEdit("", 8, 8, 329, 65)
GUICtrlSetData(-1, "")
$Button1 = GUICtrlCreateButton("Button1", 136, 88, 75, 25, $WS_GROUP)
GUICtrlSetOnEvent(-1, "CheckCmd")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Sleep(100)
WEnd

Func CheckCmd()
    $Check = GUICtrlRead($Main)
    Select
        Case $Check = "Help"
            GUICtrlSetData($Main, "Line1" & @CRLF & "Line2")
        Case $Check = "Clear"
            GUICtrlSetData($Main, "")
    EndSelect
EndFunc
Func Form1Close()
    Exit
EndFunc
Edited by enaiman

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

#include <Constants.au3>
#include <EditConstants.au3> 
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate('Title', 300, 100)
$Edit = GUICtrlCreateEdit('', 10, 20, 280, 60, BitOR($ES_WANTRETURN, $__EDITCONSTANT_WS_HSCROLL,$ES_AUTOHSCROLL))
$hEdit = GUICtrlGetHandle(-1)

$hOldProc = _WinAPI_GetWindowLong($hEdit, $GWL_WNDPROC)
$hFunc = DllCallbackRegister('WndProc', 'long', 'hwnd;uint;wparam;lparam')
$pFunc = DllCallbackGetPtr($hFunc)

_WinAPI_SetWindowLong($hEdit, $GWL_WNDPROC, $pFunc)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

GUIDelete()
DllCallbackFree($hFunc)
Exit

Func CheckCmd($sString)
    
EndFunc  ;==>CheckCmd

Func WndProc($hwnd, $iMsg, $iwParam, $ilParam)
    If $iMsg = $WM_CHAR Then
        If $iwParam = 13 Then
            Switch GUICtrlRead($Edit)
                Case "help"
                    GUICtrlSetData($Edit, "Line1" & @CRLF & "Line2")
                Case "clear"
                    GUICtrlSetData($Edit, "")
            EndSwitch
        EndIf
    EndIf
    
    Return _WinAPI_CallWindowProc($hOldProc, $hwnd, $iMsg, $iwParam, $ilParam)
EndFunc

Thank you.

@enaiman

Its called by _ispressed func.

Link to comment
Share on other sites

Its called by _ispressed func.

Then why it failed if it was really called?

I guess you didn't bother to look at my example to see that your function works. Better for me to avoid wasting my time in the future :)

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

Then why it failed if it was really called?

I guess you didn't bother to look at my example to see that your function works. Better for me to avoid wasting my time in the future :)

called used w.e when a button is pressed the func is used.
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...