Jump to content
Sign in to follow this  
Kjodiz

Checking what is written in an InputBox

Recommended Posts

Kjodiz

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?

Share this post


Link to post
Share on other sites
kylomas

kjodiz,

See GuiCtrlRead() in the help file. You are currently accessing the controlid, not the controls data.

kylomas

Edited by kylomas

Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites
Realm

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.  

Share this post


Link to post
Share on other sites
Kjodiz

Thanks very much guys! :oops:

I'd post the finished script here if it could be at some help for you guys, but as it will just be repetitive norwegian 'bullshit', I don't see the point ...

Share this post


Link to post
Share on other sites
BrewManNH

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

Share this post


Link to post
Share on other sites
Kjodiz

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?

Share this post


Link to post
Share on other sites
GMK

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

I would suggest using Switch...Case...EndSwitch.

Share this post


Link to post
Share on other sites
ileandros

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.

Share this post


Link to post
Share on other sites
BrewManNH

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

Share this post


Link to post
Share on other sites
UEZ

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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  

  • Similar Content

    • oceanwind
      By oceanwind
      Hi All:
       How to set the input border color?
      tks in advance
    • Shirdish_chakravarthi
      By Shirdish_chakravarthi
      Hello Guys this is my gui and i need the numeric value typed in the highlighted  inputbox. if this value is greater than 1 i need to perform some operations
      \
       
      Here is the summary about that field which i got from wininfo tool

      i tried writing the code as shown below.. but the msgbox is popping up empty value..when the same code is pasted under some button action i am able to access the value present in the field..but when placed alone as written in the attached script i am unable to fetch it... 

      here i am using the valu present in the field

      can you guys tell me what's wrong??? or how can i get that value?
       
      My_GUI.au3

    • Seminko
      By Seminko
      Hey,
      i would like to set a value into an INPUT field.
      Checked the _IEFormElementSetValue function but that does require _IEFormGetObjByName and this is where the problem comes in. The input field I want to write to is not a part of a form tag. It is part of a table.
      <input type="text" class="w2" id="nabidka_vozidel_formular_tach_od" name="nabidka_vozidel_formular_tach_od" onchange="GLOBAL.pocetInzerceNZ(&quot;nabidka_vozidel_formular&quot;,&quot;tach_od&quot;,&quot;&quot;);" autocomplete="off"> I tried this but that didn't work:
      $oDownloadSamples = _IEGetObjById($oIE, "nabidka_vozidel_formular_tach_od") _IEFormElementSetValue($oDownloadSamples, "123") If you want to try the site I'm working with is https://www.tipcars.cz/. There is a menu on the top left hand side and if you click the "vyhledat" button the input fields will show up.
      Thanks
    • way1000
      By way1000
      i'm trying to create a program that let's the user type a word in an input field (gui) and when a button is pressed the letters of the word are replaced by 1 word each from a list of words in a text file
      i created the gui for it but i need help to add some more code to make it work like intented

      each letter of a word should be replaced by a word from a text file
      the text file is a source for replacing letters is a file with 2 columns separated by tab that contains the entire alphabet (26 rows)
       
      please help if possible
       
      i posted an example gui screenshot

    • nacerbaaziz
      By nacerbaaziz
      hello
      Greetings to all
      dears i have a big problem in the bass.dll
      e.g
      If you play an audio file using the bass.dll
      and  You changed the audio output
      Such as setting or removing headphones
      The sound output of bass.dll does not change
      Is there any solution
      If it exists, please give it to me
      Greetings and thanks in advance
      I apologize for my bad English
×