Jump to content

Checking what is written in an InputBox


Kjodiz
 Share

Recommended Posts

I'm currently making a script to make work extremely easier, but I can't get it to check the text that is written in the InputBox.

My code at the moment:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Test", 303, 179, 192, 124)
$Input1 = GUICtrlCreateInput("", 96, 32, 121, 21)
$Button1 = GUICtrlCreateButton("Check", 72, 80, 75, 25)
$Button2 = GUICtrlCreateButton("Exit", 160, 80, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
   If $Input1 = "Test" Then
      MsgBox (0,"Success!","Shit Works")
   Else
      MsgBox (0,"Failure","Failed")
   EndIf
   Exit
  
  
        Case $Button2
           Exit
    EndSwitch
WEnd

Help?

Link to comment
Share on other sites

Hello Kjodiz,

GuiCtrlCreateInput is assigned to variable $input1, thus it is the pointer to the control, not what is written in the control. You need to use GuiCtrlRead() to identify what is written in the control.

If GuiCtrlRead($Input1) == "Test" Then

I would also use the '==' operator since you are testing strings rather than values.

Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. 

Link to comment
Share on other sites

I would also use the '==' operator since you are testing strings rather than values.

Realm

I would only use "==" if I were testing strings that have to be of a certain case, as that is a case sensitive comparison operator. Otherwise you could end up with a script that doesn't work as expected.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Thanks to you to BrewManNH :oops:

And another thing:

For this script, I'll be using a lot of 'if's.

For example:

If GuiCtrlRead($Input1) == "Test" Then
      MsgBox (0,"Success!","Shit Works")
 If GuiCtrlRead($Input1) == "Test2" Then
      MsgBox (0,"Success!","Shit Worksagain")

I'm making a list of countries, and I'll need maybe 150 - 200..

Will it be too many 'if's for it to work properly, or will it work? (My "teacher" told me to try to stay away from using too many 'if's)

Is there another way?

Link to comment
Share on other sites

If you are going to use a lot of if statment u will have to use it like this

If GuiCtrlRead($Input1) == "Test" Then
      MsgBox (0,"Success!","Shit Works")
ElseIf GuiCtrlRead($Input1) == "Test2" Then
      MsgBox (0,"Success!","Shit Worksagain")

and then add

EndIf
at the end.

I would suggest as GMK said use switch.

While 1
$msg = GUIGetMsg()
Switch $msg
Case ; add your if statment here
Case ; add your others and so go on
EndSwitch ; end your switch statment

I suggest go and check the switch...case...endswitch at ur helpfiles before using it.

Edited by ileandros

I feel nothing.It feels great.

Link to comment
Share on other sites

Switch is a lot faster than a load of If/Then statements take this:

If GuiCtrlRead($Input1) == "Test" Then
      MsgBox (0,"Success!","Shit Works")
If GuiCtrlRead($Input1) == "Test2" Then
      MsgBox (0,"Success!","Shit Worksagain")

Turn it into this:

Switch GuiCtrlRead($Input1) 
      Case  "Test"
         MsgBox (0,"Success!","Shit Works")
      Case "Test2" 
      MsgBox (0,"Success!","Shit Worksagain")
EndSwitch

Faster and easier to read.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

I wouldn't do it that way when you have a lot of checks.

I would create a 2d array with values to check and then check the array after input has been made.

Something like that

#include <buttonconstants.au3>
#include <editconstants.au3>
#include <guiconstantsex.au3>
#include <windowsconstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Test", 303, 179, 192, 124)
$Input1 = GUICtrlCreateInput("", 96, 32, 121, 21)
$Button1 = GUICtrlCreateButton("Check", 72, 80, 75, 25)
$Button2 = GUICtrlCreateButton("Exit", 160, 80, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $aCheck[2][2] = [    ["Test", "Shit works"], _
                                            ["Test2", "Shit works again"]]
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            CheckInput(GUICtrlRead($Input1), $aCheck)
        Case $Button2
           Exit
    EndSwitch
WEnd

Func CheckInput($value, $array, $row = 0)
    Local $i
    For $i = 0 To UBound($array) - 1
        If $array[$i][$row] = $value Then Return MsgBox(0, "Found", $array[$i][1], 10)
    Next
    Return MsgBox(0, "Found", "Nothing found!")
EndFunc

The function CheckInput() has no error checks!

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

  • 2 weeks later...

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

×
×
  • Create New...