Jump to content

Recommended Posts

Posted (edited)

Hi, I've just started learning to write Autoscript (having some "experience" with visual basic and liberty basic, if you consider the latter a "programming language"). I'm writing this little program that has a dialog with an input field, and when the user presses a button it will scan if the user has entered anything in the input and then a) create a msgbox and tell the user what they wrote ^_^ just end if they entered nothing C) have it end if they just entered a space or multiple spaces.

However, I have not worked out the code on the even that they enter spaces _and_ any other character. This is what I have

If GUICTRLRead($input) >= Chr(32) Then

The reason for >= is because I found out with just = it will only want to understand _1_ space :/ so >= is working for me. But if the user enters something before or after spaces it will run with this code.

How could I fix this? I could probably spend all night writing spaghetti code but decided to ask here >_>

Thanks in advance.. here is the so far code if you need it for reference.

;program demonstrates input boxes and msgboxes
#include <GUIConstantsEx.au3>
GUICreate("MsgBox Mkr",300,400)
$button = GUICtrlCreateButton("Close",20,350,60)
$input = GUICtrlCreateInput("",20,100,100,50)
GUISetState(@SW_SHOW)
While 1
    dim $msg = GUIGetMsg()
    Select
    Case $msg = $button
        If GUICTRLRead($input) <> "" then
            If GUICTRLRead($input) >= Chr(32) Then
                MsgBox(0,"Hi","You said space, hehehe")
                Exit
            Else
                MsgBox(0,"Hi",GUICtrlRead($input))
                Exit
            EndIf
        EndIf
        Exit
    Case $msg = $GUI_EVENT_CLOSE
    Exit
    EndSelect
WEnd
Edited by Travis
  • Moderators
Posted

Travis,

Another way is to look at the first character of the input and see if it is a space:

;program demonstrates input boxes and msgboxes
#include <GUIConstantsEx.au3>
GUICreate("MsgBox Mkr", 300, 400)
$button = GUICtrlCreateButton("Close", 20, 350, 60)
$input = GUICtrlCreateInput("", 20, 100, 100, 50)
GUISetState(@SW_SHOW)
While 1
    Dim $msg = GUIGetMsg()
    Select
        Case $msg = $button
            $sInput = GUICtrlRead($input) ; <<<<<<<<<<<<  read the input then use the result in the If statements
            If $sInput <> "" Then
                If StringLeft($sInput, 1) = Chr(32) Then
                    MsgBox(0, "Hi", "You said space, hehehe")
                    Exit
                Else
                    MsgBox(0, "Hi", $sInput)
                    Exit
                EndIf
            EndIf
            Exit
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

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:

  Reveal hidden contents

 

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...