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

1 person likes this

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

    • funkey
      By funkey
      Hello,
      it's quite often, that someone asks how to change the texts of the MsgBox buttons or the InputBox buttons or how to change the position of ta MsgBox. Since years I use CBT hooks for that, but now I made a small UDF out of it for the ease of use. Of course you can build your own GUI or use already existing UDFs to do the same, but I like this way and you can hack (hook) the inbuild InputBox.
       
      HookDlgBox.au3
      #include-once #include <WinAPI.au3> Global Const $tagCBT_CREATEWND = "ptr lpcs;HWND tagCBT_CREATEWND" Global Const $tagCREATESTRUCT = "ptr lpCreateParams;handle hInstance;HWND hMenu;HWND hwndParent;int cy;int cx;int y;int x;LONG style;ptr lpszName;ptr lpszClass;DWORD dwExStyle" Global $g__hProcDlgBox = DllCallbackRegister("__DlgBox_CbtHookProc", "int", "int;int;int") Global $g__TIdDlgBox = _WinAPI_GetCurrentThreadId() Global $g__hHookDlgBox = _WinAPI_SetWindowsHookEx($WH_CBT, DllCallbackGetPtr($g__hProcDlgBox), 0, $g__TIdDlgBox) Global Const $g__MaxDlgBtns = 5 ; maximum of 5 buttons to rename text Global Const $g__MaxDlgItemId = 11 ; maximun ID of buttons to search is 11 as this is the maximun used in Messagebox Global $g__DlgBoxPosX, $g__DlgBoxPosY, $g__DlgBoxWidth, $g__DlgBoxHeight Global $g__aDlgBoxBtnText[$g__MaxDlgBtns] Global $g__DlgBtnCount = 0 _DlgBox_SetDefaults() OnAutoItExitRegister("__DlgBox_UnregisterHook") Func _DlgBox_SetButtonNames($TxtBtn1 = Default, $TxtBtn2 = Default, $TxtBtn3 = Default, $TxtBtn4 = Default, $TxtBtn5 = Default) $g__aDlgBoxBtnText[0] = $TxtBtn1 $g__aDlgBoxBtnText[1] = $TxtBtn2 $g__aDlgBoxBtnText[2] = $TxtBtn3 $g__aDlgBoxBtnText[3] = $TxtBtn4 $g__aDlgBoxBtnText[4] = $TxtBtn5 $g__DlgBtnCount = @NumParams EndFunc ;==>_DlgBox_SetButtonNames Func _DlgBox_SetPosition($x = Default, $y = Default) ;only for MsgBox, not working and not needed for InputBox $g__DlgBoxPosX = $x $g__DlgBoxPosY = $y EndFunc ;==>_DlgBox_SetPosition Func _DlgBox_SetSize($w = Default, $h = Default) $g__DlgBoxWidth = $w $g__DlgBoxHeight = $h EndFunc ;==>_DlgBox_SetSize Func _DlgBox_SetDefaults() $g__DlgBoxPosX = Default $g__DlgBoxPosY = Default $g__DlgBoxWidth = Default $g__DlgBoxHeight = Default For $i = 0 To UBound($g__aDlgBoxBtnText) - 1 $g__aDlgBoxBtnText[$i] = Default Next EndFunc ;==>_DlgBox_SetDefaults Func __DlgBox_CbtHookProc($nCode, $wParam, $lParam) Local $tcw, $tcs Local $iSearch = 0 Local $ahBtn[$g__DlgBtnCount] If $nCode < 0 Then Return _WinAPI_CallNextHookEx($g__hHookDlgBox, $nCode, $wParam, $lParam) EndIf Switch $nCode Case 3 ;5=HCBT_CREATEWND If _WinAPI_GetClassName(HWnd($wParam)) = "#32770" Then ;Dialoig window class $tcw = DllStructCreate($tagCBT_CREATEWND, $lParam) $tcs = DllStructCreate($tagCREATESTRUCT, DllStructGetData($tcw, "lpcs")) If $g__DlgBoxPosX <> Default Then DllStructSetData($tcs, "x", $g__DlgBoxPosX) If $g__DlgBoxPosY <> Default Then DllStructSetData($tcs, "y", $g__DlgBoxPosY) If $g__DlgBoxWidth <> Default Then DllStructSetData($tcs, "cx", $g__DlgBoxWidth) If $g__DlgBoxHeight <> Default Then DllStructSetData($tcs, "cy", $g__DlgBoxHeight) EndIf Case 5 ;5=HCBT_ACTIVATE For $i = 1 To $g__MaxDlgItemId If IsHWnd(_WinAPI_GetDlgItem($wParam, $i)) Then If $g__aDlgBoxBtnText[$iSearch] <> Default Then _WinAPI_SetDlgItemText($wParam, $i, $g__aDlgBoxBtnText[$iSearch]) $iSearch += 1 If $iSearch >= UBound($ahBtn) Then ExitLoop EndIf Next EndSwitch Return _WinAPI_CallNextHookEx($g__hHookDlgBox, $nCode, $wParam, $lParam) EndFunc ;==>__DlgBox_CbtHookProc Func __DlgBox_UnregisterHook() _WinAPI_UnhookWindowsHookEx($g__hHookDlgBox) DllCallbackFree($g__hProcDlgBox) EndFunc ;==>__DlgBox_UnregisterHook Func _WinAPI_SetDlgItemText($hDlg, $nIDDlgItem, $lpString) Local $aRet = DllCall('user32.dll', "int", "SetDlgItemText", _ "hwnd", $hDlg, _ "int", $nIDDlgItem, _ "str", $lpString) Return $aRet[0] EndFunc ;==>_WinAPI_SetDlgItemText  
      Simple example to see how to use it
      #include "HookDlgBox.au3" _DlgBox_SetButtonNames("1", "two", "3") MsgBox(4, "Test 1", "Custom button texts") _DlgBox_SetPosition(20, 20) MsgBox(66, "Test 2", "Custom position and button texts") _DlgBox_SetButtonNames("Submit", "Don't submit", "Don't know") InputBox("Test 3", "Where were you born?", "Planet Earth") _DlgBox_SetSize(800, 800) InputBox("Test 4", "Where were you born?", "Planet Earth") _DlgBox_SetSize(Default, 800) MsgBox(66, "Test 5", "Strange but working") _DlgBox_SetButtonNames(Default, "Wait", "What?") _DlgBox_SetSize(Default, Default) _DlgBox_SetPosition(500, 500) MsgBox(66, "Test 6", "So far so good!") _DlgBox_SetDefaults() MsgBox(6, "Test 7", "Default position and button texts") Hope you like it.
       
      Best regards
      funkey
      HookDlgBox Example.au3
      HookDlgBox.au3
    • IAMK
      By IAMK
      Hello,
       
      I know you can set flags, e.g. 1, 2, 3 to change the buttons in a MsgBox from "OK" + "Cancel" to "Yes" + "No" + "Cancel", etc...
      However...
      1- Is it possible to manually say what the buttons say? E.g. "Pass" + "Fail"?
      2- Is it possible to do that with an InputBox rather than a MsgBox?
      3- What in your opinion would be better design for the user? A ) Pressing "Fail" on a MsgBox creates a "InputBox" with only a textbox and "Submit" button? B ) Only being able to press "Fail" on an InputBox if the textbox is not empty?
       
      Thank you in advance.
    • StudioMaker
      By StudioMaker
      Hey anyone knows how i can have a inputbox that is connected to an HotKeySet? Like if u put in like "a" in the inputbox it sets the hotkey to "a"?
       
    • akira2891
      By akira2891
      Hi,
      I was wondering is this all inputs can be done in 1 box with 3 fields and not to use another gui.
      And how can i validate data for example if i don't enter username he prompt me a message box all time until field is empty.
      I try like this but it give me a msgbox and continue on another field.
      $username = InputBox("Add new user", "Username", "", "", 200, 130, Default, Default, 0) if $username <> " " then msgbox(0, "", "Please enter username") endif $email = InputBox("Add new user", "Email", "", "", 200, 130, Default, Default, 0) $password = InputBox("Add new user", "Password", "", "*", 200, 130, Default, Default, 0)  
    • kneze
      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