Sign in to follow this  
Followers 0
face

GUI button and input field

3 posts in this topic

i need some help with a script

i want to make it so when i click on "iButton1" and/while/if there is a number in the input field i get an output message in "iOutput1"

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

Example()

Func Example()
    Local $hGUI = GUICreate("Calc", 300, 150, -1, -1)
    Local $sString = GUICtrlCreateInput("", 65, 5, 50, 20)

    Local $iButton1 = GUICtrlCreateButton("Button1", 5, 5, 50, 20)
    Local $iButton2 = GUICtrlCreateButton("Button2", 5, 25, 50, 20)
    Local $iButton3 = GUICtrlCreateButton("Button3", 5, 45, 50, 20)
    Local $iButton4 = GUICtrlCreateButton("Button4", 5, 65, 50, 20)
    Local $iButton5 = GUICtrlCreateButton("Button5", 5, 85, 50, 20)
    Local $iButton10 = GUICtrlCreateButton("Clear", 5, 105, 50, 20)
    Local $iOutput1 = GUICtrlCreateLabel("", 125, 5, 150, 20, $SS_SUNKEN)
        Local $iOutput2 = GUICtrlCreateLabel("", 125, 25, 150, 20, $SS_SUNKEN)
    Local $iOutput3 = GUICtrlCreateLabel("", 125, 45, 150, 20, $SS_SUNKEN)
    Local $iOutput4 = GUICtrlCreateLabel("", 125, 65, 150, 20, $SS_SUNKEN)
    Local $iOutput5 = GUICtrlCreateLabel("", 125, 85, 150, 20, $SS_SUNKEN)
    Local $iOutput6 = GUICtrlCreateLabel("", 125, 105, 150, 20, $SS_SUNKEN)


GUISetState(@SW_SHOW, $hGUI)
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
If $sString > 5 Then
    Select
    Case $iButton1
    GUICtrlSetData($iOutput1, "Greater than 5")

                Case $iButton10
                GUICtrlSetData($iOutput1, "")
                GUICtrlSetData($iOutput2, "")
                GUICtrlSetData($iOutput3, "")
                GUICtrlSetData($iOutput4, "")
                GUICtrlSetData($iOutput5, "")
                GUICtrlSetData($iOutput6, "")

 EndSelect
 EndIf
        EndSwitch
    WEnd
    GUIDelete($hGUI)
    Exit
EndFunc

thanks in advance

Share this post


Link to post
Share on other sites



Going by the following line in your example, I'm not entirely sure what you are wanting?

GUICtrlSetData($iOutput1, "Greater than 5")

If you had used that line before GuiSetState then it would be obvious.

So you might benefit from checking out this command - StringIsDigit

But more likely, I would check out the Regular Expression Tutorial in the Help file, for use of commands like - StringRegExp


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You should forget this disturbing and overcomplicating Func Example() and read the helpfile about GuiCtrlRead  :)

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

$hGUI = GUICreate("Calc", 300, 150, -1, -1)
$cInput = GUICtrlCreateInput("", 65, 5, 50, 20)
$iButton1 = GUICtrlCreateButton("Button1", 5, 5, 50, 20)
$iButton2 = GUICtrlCreateButton("Button2", 5, 25, 50, 20)
$iButton3 = GUICtrlCreateButton("Button3", 5, 45, 50, 20)
$iButton4 = GUICtrlCreateButton("Button4", 5, 65, 50, 20)
$iButton5 = GUICtrlCreateButton("Button5", 5, 85, 50, 20)
$iButton10 = GUICtrlCreateButton("Clear", 5, 105, 50, 20)
$iOutput1 = GUICtrlCreateLabel("", 125, 5, 150, 20, $SS_SUNKEN)
$iOutput2 = GUICtrlCreateLabel("", 125, 25, 150, 20, $SS_SUNKEN)
$iOutput3 = GUICtrlCreateLabel("", 125, 45, 150, 20, $SS_SUNKEN)
$iOutput4 = GUICtrlCreateLabel("", 125, 65, 150, 20, $SS_SUNKEN)
$iOutput5 = GUICtrlCreateLabel("", 125, 85, 150, 20, $SS_SUNKEN)
$iOutput6 = GUICtrlCreateLabel("", 125, 105, 150, 20, $SS_SUNKEN)
GUISetState(@SW_SHOW, $hGUI)

While 1
    Switch GUIGetMsg()
           Case $GUI_EVENT_CLOSE
                ExitLoop
           Case $iButton1
                 $number = GuiCtrlRead($cInput)
                 ; check if input contains only digit(s) and/or dot
                 If not StringRegExp($number, '^\d+\.?\d*?$') Then GUICtrlSetData($iOutput1, "Not a number")
                 If $number > 5 Then GUICtrlSetData($iOutput1, "Greater than 5")

           Case $iButton10
                GUICtrlSetData($iOutput1, "")
                GUICtrlSetData($iOutput2, "")
                GUICtrlSetData($iOutput3, "")
                GUICtrlSetData($iOutput4, "")
                GUICtrlSetData($iOutput5, "")
                GUICtrlSetData($iOutput6, "")
        EndSwitch
WEnd
Edited by mikell

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