Jump to content

Issue with Gui multiple Input and set to Variable.


Fadi
 Share

Recommended Posts

Hi,  I'm trying to create a GUI a multiple input, and set the inputs for each field in different variables, so i use then later into my Main function.

This is what i'm trying to create. Any help where is my problem?

#include <GUIConstants.au3>
#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>


Opt("GUIOnEventMode", 1)

HotKeySet("{ESC}", "quit")


$GUI = GUICreate("Information", 280, 280)
GUICtrlCreateLabel("Input1:", 10, 15, 65, 25)
$TE_NumberInput= GUICtrlCreateInput("", 80, 10, 160, 25)
GUICtrlCreateLabel("Input2:", 10, 55, 65, 25)
$LocomotiveID_Input = GUICtrlCreateInput("", 80, 50, 160, 25)
GUICtrlCreateLabel("Input3", 10, 95, 95, 25)
$Direction_Input = GUICtrlCreateCombo("", 80, 90, 160, 25)
GUICtrlSetData(-1, "Item1|item2|item3")
GUICtrlCreateLabel("Input4", 10, 135, 65, 25)
$EngineetPIN_Input = GUICtrlCreateInput("", 80, 130, 160, 25)
$OK = GUICtrlCreateButton("OK", 30, 240, 60, 25)
GUICtrlSetOnEvent($OK, "GetValue")
$CANCEL = GUICtrlCreateButton("CANCEL", 110, 240, 60, 25)
GUICtrlSetOnEvent($CANCEL, "quit")


FUNC GetValue()
    GUISetState()
    $msg = 0
    While $msg <> $GUI_EVENT_CLOSE
        $msg = GUIGetMsg()
        Select
            Case $msg = $OK
                Global $Value1 = GUICtrlRead($Input1)
                Global $Value2 = GUICtrlRead($Input2)
                Global $Value3= GUICtrlRead($Input3)
                Global $Value4 = GUICtrlRead($Input4)
    
                
                exitloop
        EndSelect
    
    Wend
EndFunc


_Main()

FUNC _Main()

            Run("notepad.exe")
            WinWaitActive("Untitled - Notepad")
            Send("Input1: " &$Input1 & "Input2: " &$Input2 & "Input3 :" &$Input3 &"Input4 :" $Input4)
            quit()
EndFunc


Func quit()
    Exit
EndFunc

 

Edited by Melba23
Added code tags
Link to comment
Share on other sites

  • Moderators

Fadi,

You are mixing OnEvent and MessageLoop modes - you cannot do this (well, not unless you are very careful).

Just use OnEvent mode throughout - like this:

#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

HotKeySet("{ESC}", "quit")

Global $Value1, $Value2, $Value3, $Value4

$GUI = GUICreate("Information", 280, 280)
GUISetOnEvent($GUI_EVENT_CLOSE, "quit") ; Here you set the [X] action
GUICtrlCreateLabel("Input1:", 10, 15, 65, 25)
$TE_NumberInput= GUICtrlCreateInput("", 80, 10, 160, 25)
GUICtrlCreateLabel("Input2:", 10, 55, 65, 25)
$LocomotiveID_Input = GUICtrlCreateInput("", 80, 50, 160, 25)
GUICtrlCreateLabel("Input3", 10, 95, 95, 25)
$Direction_Input = GUICtrlCreateCombo("", 80, 90, 160, 25)
GUICtrlSetData(-1, "Item1|item2|item3")
GUICtrlCreateLabel("Input4", 10, 135, 65, 25)
$EngineetPIN_Input = GUICtrlCreateInput("", 80, 130, 160, 25)
$OK = GUICtrlCreateButton("OK", 30, 240, 60, 25)
GUICtrlSetOnEvent($OK, "GetValue")
$CANCEL = GUICtrlCreateButton("CANCEL", 110, 240, 60, 25)
GUICtrlSetOnEvent($CANCEL, "quit")

GUISetState()

; Keep the script running
While 1
    Sleep(10)
WEnd

FUNC GetValue()
    ; Do not declare Global variables inside a function
    $Value1 = GUICtrlRead($TE_NumberInput) ; But do use the correct variable to denote the control to read
    $Value2 = GUICtrlRead($LocomotiveID_Input)
    $Value3= GUICtrlRead($Direction_Input)
    $Value4 = GUICtrlRead($EngineetPIN_Input)

    _Main()

EndFunc

FUNC _Main()
    ; This just writes to the SciTE console rather then Notepad
    ConsoleWrite("Input1: " & $Value1 & @CRLF & "Input2: " & $Value2 & @CRLF & "Input3 :" & $Value3 & @CRLF & "Input4 :" & $Value4 & @CRLF)
    quit()
EndFunc

Func quit()
    Exit
EndFunc

There are one or two other comments I have added to your code - please ask if you have any questions.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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