Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

[SOLVED] Inputbox Rules

Inputbox

  • Please log in to reply
10 replies to this topic

#1 johnmcloud

johnmcloud

    Not an AutoIt MVPs (MVP)

  • Active Members
  • PipPipPipPipPipPip
  • 669 posts

Posted 06 January 2012 - 05:43 PM

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, 06 January 2012 - 06:32 PM.








#2 Melba23

Melba23

    I'm old - what's your excuse?

  • Moderators
  • 21,541 posts

Posted 06 January 2012 - 05:48 PM

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
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
Date_Time_Convert - Easily convert date/time formats, including the language               GUIListViewEx - Insert, delete, move, drag, sort and edit ListView items

#3 johnmcloud

johnmcloud

    Not an AutoIt MVPs (MVP)

  • Active Members
  • PipPipPipPipPipPip
  • 669 posts

Posted 06 January 2012 - 05:49 PM

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, 06 January 2012 - 05:52 PM.


#4 Melba23

Melba23

    I'm old - what's your excuse?

  • Moderators
  • 21,541 posts

Posted 06 January 2012 - 05:57 PM

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
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
Date_Time_Convert - Easily convert date/time formats, including the language               GUIListViewEx - Insert, delete, move, drag, sort and edit ListView items

#5 johnmcloud

johnmcloud

    Not an AutoIt MVPs (MVP)

  • Active Members
  • PipPipPipPipPipPip
  • 669 posts

Posted 06 January 2012 - 06:01 PM

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

#6 Melba23

Melba23

    I'm old - what's your excuse?

  • Moderators
  • 21,541 posts

Posted 06 January 2012 - 06:08 PM

johnmcloud,

Here is a short example of how you might do it: ;)
AutoIt         
#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
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
Date_Time_Convert - Easily convert date/time formats, including the language               GUIListViewEx - Insert, delete, move, drag, sort and edit ListView items

#7 czardas

czardas

  • Active Members
  • PipPipPipPipPipPip
  • 6,979 posts

Posted 06 January 2012 - 06:14 PM

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

AutoIt         
#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, 06 January 2012 - 06:14 PM.


#8 johnmcloud

johnmcloud

    Not an AutoIt MVPs (MVP)

  • Active Members
  • PipPipPipPipPipPip
  • 669 posts

Posted 06 January 2012 - 06:14 PM

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, 06 January 2012 - 06:15 PM.


#9 czardas

czardas

  • Active Members
  • PipPipPipPipPipPip
  • 6,979 posts

Posted 06 January 2012 - 06:30 PM

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


#10 Melba23

Melba23

    I'm old - what's your excuse?

  • Moderators
  • 21,541 posts

Posted 06 January 2012 - 06:30 PM

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
StringSize - Automatically size controls to fit text                                                               ExtMsgBox - A user customisable replacement for MsgBox
Toast - Small GUIs which pop out of the Systray                                                                Marquee - Scrolling tickertape GUIs
Scrollbars - Automatically sized scrollbars with a single command                                   GUIFrame - Subdivide GUIs into many adjustable frames
GUIExtender - Extend and retract multiple sections within a GUI                                      NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes
ChooseFileFolder - Single and multiple selections from specified path tree structure      Notify - Small notifications on the edge of the display
Date_Time_Convert - Easily convert date/time formats, including the language               GUIListViewEx - Insert, delete, move, drag, sort and edit ListView items

#11 johnmcloud

johnmcloud

    Not an AutoIt MVPs (MVP)

  • Active Members
  • PipPipPipPipPipPip
  • 669 posts

Posted 06 January 2012 - 06:32 PM

Thanks guys, all clear





Also tagged with one or more of these keywords: Inputbox

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users