DigDeep

GUI Button with InputBox

2 posts in this topic

Hi there,

I wanted to click on $GetInput button to get the InputBox and $OK button displayed. (This works fine)

But when clicking on clicking on $OK button, it does not do anything. basically, if there is nothing typed inside the InputBox then it should give the warning or else show what is typed in.

 

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Global $Form1, $GetInput, $Input, $OK

Func Input()
    Global $TechAliasOutput = "C:\Temp\output.txt"
    $Input = GUICtrlCreateInput("", 245, 180, 170, 24)
    GUICtrlSetData($Input, "")
    $OK = GUICtrlCreateButton("OK", 350, 230, 75, 25, $SS_CENTER)
        GUICtrlSetState($OK, 512)

    Global $Input_Data = (GUICtrlRead($Input))
    $aInfo = GUIGetCursorInfo($Form1)
    If $aInfo[2] Then
        If $aInfo[4] = $Input_Data Then GUICtrlSetData($Input_Data, "")
    EndIf

    Select
        Case $OK = $Input
            If $Input_Data = '' Then
                MsgBox(64, "", "InputBox is empty")

            Else
                MsgBox(0, '', GUICtrlRead($Input))
            EndIf
    EndSelect
EndFunc

#Region
    $Form1 = GUICreate("Form1", 504, 283, -1, -1)
        $GetInput = GUICtrlCreateButton("Input", 200, 230, 75, 25, $SS_CENTER)
    GUISetState(@SW_SHOW)
#EndRegion`


While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

        Case $GetInput
            Input()

EndSwitch
WEnd

 

Share this post


Link to post
Share on other sites



DigDeep,

This seems to work for me:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Global $Input, $OK = 9999 ; $OK must have a placeholder value or the case will fire on every pass
Global $TechAliasOutput = "C:\Temp\output.txt"

$Form1 = GUICreate("Form1", 504, 283, -1, -1)
$GetInput = GUICtrlCreateButton("Input", 200, 230, 75, 25) ; Buttons are automatically centred - and use $BS_ styles in any event
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

        Case $GetInput
            Input()

        Case $OK
            $Input_Data = GUICtrlRead($Input) ; So we read it here after the button is pressed
            If $Input_Data = '' Then
                MsgBox($MB_OK + $MB_ICONINFORMATION, "", "InputBox is empty")
            Else
                MsgBox($MB_OK, '', $Input_Data)
            EndIf
            GUICtrlDelete($Input)
            GUICtrlDelete($OK)
            $OK = 9999 ; Reset placeholder value

    EndSwitch
WEnd


Func Input()
    ;Global $TechAliasOutput = "C:\Temp\output.txt" ; Do not declare Global inside functions

    $Input = GUICtrlCreateInput("", 245, 180, 170, 24)
    ;GUICtrlSetData($Input, "") ; You have already set the input to empty when creatin git on the line above
    $OK = GUICtrlCreateButton("OK", 350, 230, 75, 25)
    GUICtrlSetState($OK, $GUI_DEFBUTTON) ; Why use magic numbers when you can use constants that explain what is going on?

    ;$Input_Data = (GUICtrlRead($Input)) ; if you read the input now there is nothing in it

    ; No idea what this is supposed to do
    ;$aInfo = GUIGetCursorInfo($Form1)
    ;If $aInfo[2] Then
    ;    If $aInfo[4] = $Input_Data Then GUICtrlSetData($Input_Data, "")
    ;EndIf

EndFunc

Please ask if you have any questions.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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