Jump to content

Simple UDF - InputBox With String Regular Expression


Skizmata
 Share

Recommended Posts

I use this constantly in my work I hope someone else can benefit from it. Helpful input appreciated.

;===============================================================================
;
; Description:      Supplys a input box with optinal string regular expression and
;                   error message descriptor.
; Parameters:       $sInputTitle - InputBox() Title
;                   $sInputPrompt - InputBox() Prompt
;                   $sStringRegExp - The String Regular Expression to check input aginst.
; Optinal Parameters:
;                   $sErrorTitle - Title of error box if string regular expression not met.
;                   $sErrorPrompt - Prompt of error box if string regular expression not met.
;                   $sDefault - The inputbox default text. (See InputBox() for more information)
;                   $sPasswordChar - Password mask char. (See InputBox() for more information)
;                   $iWidth - Width of InputBox() (See InputBox() for more information)
;                   $iHeight - Hight of InputBox() (See InputBox() for more information)
;                   $iLeft - Left location of InputBox() (See InputBox() for more information)
;                   $iTop - Top location of InputBox() (See InputBox() for more information)
;                   $iTimeOut - InputBox() timeout parameter. (See InputBox() for more information)
; Requirements:     None
; Return Value:     Value of InputBox
; Author:           Skizmata
; Notes:            First revision 10-2-07
;
;===============================================================================
Func _InputPerStrRegExp($sInputTitle,$sInputPrompt,$sStringRegExp,$sErrorTitle = "Input Error",$sErrorPrompt = "Input invalid, please give input in standard format.",$sDefault = "",$sPasswordChar = "",$iWidth = -1,$iHeight = -1,$iLeft = Default,$iTop = Default,$iTimeOut = -1)
    While 1
        $sInputReturn = InputBox($sInputTitle,$sInputPrompt,$sDefault,$sPasswordChar,$iWidth,$iHeight,$iLeft,$iTop,$iTimeOut)
        If @error Then
            SetError(@error)
            Return
        EndIf
        If StringRegExp($sInputReturn,$sStringRegExp) Then
            Return $sInputReturn
        Else
            MsgBox(16,$sErrorTitle,$sErrorPrompt)
        EndIf
    WEnd
EndFunc

P.S. I couldn't get the AutoIt tag button to work...

Edited by Skizmata

AutoIt changed my life.

Link to comment
Share on other sites

Thanks Revoked good stuff, I'm just getting into the wide world of SREs previously I had been using long winded If's. This is actually my first attempt at a properly formated UDF so any pointers on how to make it better functionally or better suited to the accepted standards of UDFs here would be fantastic.

AutoIt changed my life.

Link to comment
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
 Share

  • Recently Browsing   0 members

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