Sign in to follow this  
Followers 0
ojef1

Trouble getting my first GUI to work

9 posts in this topic

I'm trying to make a GUI that accepts 3 values: row, lastRow, and delay and I'm having all kinds of problems with it. I want to have 3 integer values stored in each variable ($row, $lastRow, and $delay), which is why I use the Number() function. Eventually, I want to put in tests to verify the inputs are valid integers and the range is valid, etc. But for now I'd just like to get it working. Right now the msgbox i put in indicates each variable equals nothing ... It says "first row is (blank) @CRLF last row is (blank) @CRLF delay is (blank)"

#include <GUIConstantsEx.au3>
#include <GUIButton.au3>
#include <GUIToolbar.au3>

input()

Func input()    
    GUICreate("Emax", 380, 180, @DesktopWidth / 4 - 160, @DesktopHeight / 4 - 45, -1, 0x00000018)
    
    GUICtrlCreateLabel("Enter the row to start with: ", 10, 5)
    $input1 = GUICtrlCreateInput("", 10, 25, 100, 20)
    $row = GUICtrlRead($input1, 1)
    Number($row)

    GUICtrlCreateLabel("Enter the last row: ", 10, 50)
    $input2 = GUICtrlCreateInput("", 10, 65, 100, 20)
    $lastRow = GUICtrlRead($input2, 1)  
        
    GUICtrlCreateLabel("Enter a time delay (in milliseconds) in case the network is running slow: ", 10, 90, 350, 20)
    $input3 = GUICtrlCreateInput("", 10, 105, 100, 20)  ;slows whole program down
    $delay = GUICtrlRead($input3, 1)    
    Number($delay)
    
    $enterBtn = GUICtrlCreateButton("Enter", 20, 145, 60, 20)
    $cancelBtn = GUICtrlCreateButton("Cancel", 100, 145, 60, 20)
    GUISetState(@SW_SHOW)

    While 1
        $msg = GUIGetMsg()
        
        If $msg = $GUI_EVENT_CLOSE Then
            Exit
        ElseIf $msg = $enterBtn Then
            MsgBox(0, "??", "first row is " & $row & @CRLF & "last row is " & $lastRow & @CRLF & "delay is " & $delay)
            input()
            ;range($row, $lastRow)          
        ElseIf $msg = $cancelBtn Then 
            Exit
        EndIf
    WEnd
EndFunc

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

ojef1,

You are reading the inputs as soon as they are created - so unsuprisingly they are blank. :P

You need to read them when the button is pushed - like this

#include <GUIConstantsEx.au3>
#include <GUIButton.au3>
#include <GUIToolbar.au3>

input()

Func input()
    GUICreate("Emax", 380, 180, @DesktopWidth / 4 - 160, @DesktopHeight / 4 - 45, -1, 0x00000018)

    GUICtrlCreateLabel("Enter the row to start with: ", 10, 5)
    $input1 = GUICtrlCreateInput("", 10, 25, 100, 20)

    GUICtrlCreateLabel("Enter the last row: ", 10, 50)
    $input2 = GUICtrlCreateInput("", 10, 65, 100, 20)

    GUICtrlCreateLabel("Enter a time delay (in milliseconds) in case the network is running slow: ", 10, 90, 350, 20)
    $input3 = GUICtrlCreateInput("", 10, 105, 100, 20)  ;slows whole program down

    $enterBtn = GUICtrlCreateButton("Enter", 20, 145, 60, 20)
    $cancelBtn = GUICtrlCreateButton("Cancel", 100, 145, 60, 20)
    GUISetState(@SW_SHOW)

    While 1
        $msg = GUIGetMsg()

        If $msg = $GUI_EVENT_CLOSE Then
            Exit
        ElseIf $msg = $enterBtn Then
            $row = Number(GUICtrlRead($input1, 1))
            $lastRow = Number(GUICtrlRead($input2, 1))
            $delay = Number(GUICtrlRead($input3, 1))
            MsgBox(0, "??", "first row is " & $row & @CRLF & "last row is " & $lastRow & @CRLF & "delay is " & $delay)
        ElseIf $msg = $cancelBtn Then
            Exit
        EndIf
    WEnd
EndFunc

A couple of other points:

- 1. You need to have a variable to receive the output of Number - as you were doing it, nothing would happen. :D

- 2, You were recalling your function inside the function - this is known as recursion and would very quickly lead to a crash! :)

Take a look at the Recursion tutorial in the Wiki to see why. ;)

All clear? Please ask if not. :)

M23

Edit: Wrong button too soon!

Edited by Melba23

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

#3 ·  Posted (edited)

Move EndFunc to before the While 1.<br><br>

Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

somdcomputerguy,

Are you sure you are in the right thread? :)

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

somdcomputerguy,

Are you sure you are in the right thread? :)

M23

Ya. I was trying to edit my post, then saw you already replied, then I realized my answer was wrong anyway..


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

ok thanks for all the help...i was going the wrong direction trying to figure it out myself and getting more confused....this is the second recursion problem I've ran into in this program, I think I might be developing a bad habit...is there any sort of branch function or something I could use instead if I wanted it to run back through the function (if the inputs were invalid for example)? The way I have it set up was just for testing purposes but I will probably need to do something similar (only with a way out). Thanks again

Share this post


Link to post
Share on other sites

Also do I need to declare my variables outside of the function if I'm going to use them outside of the function?

Share this post


Link to post
Share on other sites

ojef1,

If you want to repeat something like that, use an infinite While...WEnd loop and then an ExitLoop when you want to break out of it.

Do read the tutorial I linked to - if you do not know what you are doing, recursion will crash your system quicker than almost anything else. :)

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
Sign in to follow this  
Followers 0