Sign in to follow this  
Followers 0
johnmcloud

[SOLVED] Inputbox Rules

11 posts in this topic

#1 ·  Posted (edited)

Hi guys,

I have searched into the forum without find an answer.

I want ot set to an inputbox rules like lenght and most important don't accept some special letter like | or &

I have do this:

$input=GUICtrlRead($Inputbox)
If $input="" Then
MsgBox(16,"Error","Input is empty")
Return
EndIf

$input=GUICtrlRead($Inputbox)
If $input = '<|&">' Then
MsgBox(16,"Error","Special character not allowed:" & @CRLF & '< | & " >')
Return
EndIf

The first work fine, but the second give me error for all inputbox. Some advice?

Thanks

Edited by johnmcloud

Share this post


Link to post
Share on other sites



johnmcloud,

To set the maximum number of characters in an input - look at GUICtrlSetLimit. ;)

To prevent certain characters is a little more complicated, but not at all impossible using the EN_CHANGE message. What characters to want to accept/exclude? :)

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

#3 ·  Posted (edited)

I have write it on first post :) i want esclude this:

&

|

>

<

"

Thanks Melba for support

People can write on inputbox, but if they click OK i need an error message, then i add a GUICtrlSetData($Input,"")

Edited by johnmcloud

Share this post


Link to post
Share on other sites

johnmacloud,

You will have to write your own GUI with an input if you want to use these tricks. An InputBox is a self-contained function and difficult to modify. Hang on a bit and I will see what I can do for you. :)

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

Thanks, i have a basic GUI for the inputbox and a OK button, i don't have posted because i think was easy to check if an inputbox contains a specific letter. But i'm wrong :)

Thanks for help

Share this post


Link to post
Share on other sites

johnmcloud,

Here is a short example of how you might do it: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <WinAPI.au3>

Global $hInput

$sInput = _InputBox("Title", "Prompt")

MsgBox(0, "Input", $sInput)

Func _InputBox($sTitle, $sPrompt)

    $hGUI = GUICreate($sTitle, 500, 500)

    GUICtrlCreateLabel($sPrompt, 10, 10, 480, 20)

    $hInput = GUICtrlCreateInput("", 10, 50, 480, 20)
    ; Limit the input to 10 characters
    GUICtrlSetLimit(-1, 10)

    $hButton_OK = GUICtrlCreateButton("OK", 10, 100, 80, 30)
    $hButton_Can = GUICtrlCreateButton("Cancel", 110, 100, 80, 30)

    GUISetState()

    GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND")

    While 1

        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $hButton_Can
                Return SetError(1, 0, "")
            case $hButton_OK
                Return GUICtrlRead($hInput)
        EndSwitch

    WEnd

EndFunc


Func _WM_COMMAND($hWHnd, $iMsg, $wParam, $lParam)

    ; If it was an update message from our input
    If _WinAPI_HiWord($wParam) = $EN_CHANGE And _WinAPI_LoWord($wParam) = $hInput Then

        ; Read the text
        $sText = GUICtrlRead($hInput)
        ; If there are any banned characters
        If StringRegExp($sText, '&|||<|>|"') Then
            ; Remove them
            GuiCtrlSetData($hInput, StringRegExpReplace($sText, '&|||<|>|"', ""))
        EndIf

    EndIf

EndFunc   ;==>_WM_COMMAND

Please ask if you have any questions. :)

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

#7 ·  Posted (edited)

Here is an adaptation of a recent function I wrote which you might be able to use.

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#Include <GuiButton.au3>

_Input()

Func _Input()
    Local $iError = 0
    Local $sTitle = "Input Test"
    Local $hGUI = GUICreate($sTitle, 225, 55, Default, Default)
    Local $hInput = GUICtrlCreateInput("", 5, 5, 215, 20)
    GUICtrlSetLimit($hInput, 128)
    Local $hCancel = GUICtrlCreateButton("Cancel", 35, 30, 70, 20)
    Local $hOkay = GUICtrlCreateButton("OK", 120, 30, 70, 20)
    GUISetState(@SW_SHOW)

    $dll = DllOpen("user32.dll")
    While 1
        $msg2 = GUIGetMsg()
        If $msg2 = $hCancel Or $msg2 = $GUI_EVENT_CLOSE Then ExitLoop

        $sUserInput = GUICtrlRead($hInput)
        If StringRegExp($sUserInput, '[|?&"<>]') Then
            If  $iError = 0 Then
                GUICtrlSetBkColor($hInput, 0xFFA090)
                $iError = 1
            EndIf
        ElseIf $iError = 1 Then
            GUICtrlSetBkColor($hInput, 0xFFFFFF)
            $iError = 0
        EndIf

        If $msg2 = $hOkay Or (ControlGetFocus ($sTitle) = "Edit1" And _IsPressed("0D")) Then
            If $iError = 0 Then
                MsgBox(0, "Success", "The text is valid")
                ExitLoop
            Else
                MsgBox(262160, "Error", "The text you entered contains illegal characters.")
                _GUICtrlButton_SetFocus($hOkay)
            EndIf
        EndIf
    WEnd
    DllClose($dll)
EndFunc
Edited by czardas

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

StringRegExp($sText, '&|||<|>|"') Then

That's the point :)

If have another question, but if is too long forget it

If i want to set for example only some character ( es. only ABC is allowed ) i can use the same StringRegExp with all the rest of character or there is another method? Thanks for your help

edit: Thanks czardas, is the same of Melba, you have post it at the same time ;)

Edited by johnmcloud

Share this post


Link to post
Share on other sites

The easiest way would be to use the hex value of the ascii characters. Look for this in the help file under StringRegExp()

To see how this works, replace line 24 from my example

If StringRegExp($sUserInput, '[|?&"<>]') Then

With this line

If StringRegExp($sUserInput, '[x22x26x3cx3ex3fx7c]') Then

Share this post


Link to post
Share on other sites

johnmcloud,

To give you a bit of a hint, this will only accept upper and lowercase ABC characters:

; If there are any banned characters
If StringRegExp($sText, "(?i)[^ABC]") Then
    ; Remove them
    GuiCtrlSetData($hInput, StringRegExpReplace($sText, "(?i)[^ABC]", ""))
EndIf

See if you can work it out yourself. Ask if you really get stuck - a minimum of 2 hours from now. :)

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

Thanks guys, all clear

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

  • Similar Content

    • kneze
      search value in text file
      By kneze
      Hi all,
      i would like to enter a vlaue to Inputbox 1 an press button1. Script should search value in a text file and put value after "; " to Inputbox 2.
      #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.2 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <file.au3> $Form1 = GUICreate("Form1", 257, 119, 192, 124) $Input1 = GUICtrlCreateInput("Input1", 15, 35, 121, 21) $Input2 = GUICtrlCreateInput("Input2", 15, 60, 121, 21) $Button1 = GUICtrlCreateButton("Button1", 145, 35, 75, 25) GUISetState(@SW_SHOW) $iLines = _FileCountLines(@ScriptDir & "\data.txt") ;MsgBox(0, "Char read:", $ilines) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 EndSwitch WEnd can anyone help?
      data.txt
    • GeorgeB
      How to restrict inputboxes to specific characters only?
      By GeorgeB
      I'm having trouble in making an input box where I can limit the characters that can be inputted.  Anybody have an idea how this can be done in Auto IT?
      Specifically I would like to create an input field where the user would enter a MAC address.  What I would like to do is to limit the characters that can be inputted to only HEX values (A-F and 0-9 as well as the - character).  This is so that the user cannot input invalid characters. The program is going to be used by very non-technical people, so the idea is to remove as many chances for errors that we can think of.  I would also prefer to limit the field to only 17 characters, so that there is only enough space to enter the MAC address with the - character as the separator.
      Thank you all in advance for any suggestions!
    • DavidFigueroa
      Automatically adding leading zero's to inputbox
      By DavidFigueroa
      I'm trying to create an inputbox that automatically formats numbers with leading zeroes when the updown control is used.  I found an example from Melba23 (see below) that shows a step incremented inputbox, and based on that, I tried to create one that would work, but it does not.
      I am creating separate inputs for hours and minutes, and I want to make sure the inputbox is always 2 digits. And right up front, I don't pretend to really understand the DLLStruct* calls.. 
      Melba23's sample:
      #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <UpDownConstants.au3> $hGUI = GUICreate("Test", 500, 500) $hInput = GUICtrlCreateInput("5000", 10, 10, 100, 20) $hUpDown = GUICtrlCreateUpdown($hInput, BitOR($UDS_WRAP, $UDS_NOTHOUSANDS)) GUICtrlSetLimit($hUpDown, 6000, 5000) GUISetState() GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") While 1     Switch GUIGetMsg()         Case $GUI_EVENT_CLOSE             Exit     EndSwitch WEnd Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)     ; Is it from the UpDown?     If BitAND($wParam, 0xFFFF) = $hUpDown Then         ; Create NMUPDOWN structure         Local $tStruct = DllStructCreate("hwnd;long;int;long;long", $lParam)         ; Is it a change message?         If DllStructGetData($tStruct, 3) = 0xFFFFFD2E Then ; $UDN_DELTAPOS             ; Alter the change value             DllStructSetData($tStruct, 5, 100 * DllStructGetData($tStruct, 5))         EndIf     EndIf EndFunc ;~ The NMUPDOWN structure holds: ;~ 1 - Handle of UpDown ;~ 2 - ControlID of UpDown ;~ 3 - Message type sent by UpDown ;~ 4 - Current value of UpDown ;~ 5 - Change to apply to input (+/-1) And here is my non-working sample (it runs, and the initial value shows correctly, but when you hit the updown, you lose the leading zeroes.
      #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> $hGUI = GUICreate("Window", 300, 100, -1, -1) $Count = 1 Global $hEdit = GUICtrlCreateInput($Count, 15, 15, 100, 30) GUICtrlSetFont(-1, 12, 400, "", "Tahoma") GUICtrlSetData(-1, StringFormat("%03u",$Count)) Global $hUpDown = GUICtrlCreateUpdown(-1) GUICtrlSetLimit(-1, 100, 0) GUISetState() While 1     $hMsg = GUIGetMsg()     Switch $hMsg         Case $GUI_EVENT_CLOSE             Exit     EndSwitch WEnd Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)     ; Is it from the UpDown?     If BitAND($wParam, 0xFFFF) = $hUpDown Then         ; Create NMUPDOWN structure         Local $tStruct = DllStructCreate("hwnd;long;int;long;long", $lParam)         ; Is it a change message?         If DllStructGetData($tStruct, 3) = 0xFFFFFD2E Then ; $UDN_DELTAPOS             ; Alter the change value             $ValueToSet = DllStructGetData($tStruct, 4)             $ValueToSet = StringFormat("%03u", $ValueToSet)             GUICtrlSetData($hEdit, $ValueToSet)         EndIf     EndIf EndFunc  
    • farhadrahman2
      InputBox
      By farhadrahman2
      hey guys, i have a problem .
      I want to search a file in a particular folder and after inserting the name  in the input box i want to make a drop down menu of all the matches and then select it and open it.
      I need the full code .
      so please anyone help me on this one.

    • Quegga
      Mark/Highlight text in inputbox
      By Quegga
      Hey there
      I want to mark the content of an inputbox when you click on the text inside.
      Excample: I have an inputbox which has the data "a". When I click inside the inputbox I want the "a" to be highlighted blue, so I can easily copy-paste it out.
      GUICreate("",300,100) $Input1 = GUICtrlCreateInput("",10,10,50,30) $Input2 = GUICtrlCreateInput("a",100,10,50,30) GUISetState() While True Switch GUIGetMsg() Case -3 Exit EndSwitch WEnd I searched google and the forum and did not find anything.
      Thanks!