Jump to content

Help with Validation Checks


Recommended Posts

Hi everyone,

I've having a problem with writing a couple of validation checks for AutoIt Input Boxes, and I was wondering if someone might be able to help me with the syntax.

Check #1:

$batch_number = InputBox ( "Step 1: Batch Number", "Please enter the number of the batch last scanned and then click Ok (or press Enter) to continue.", "" )
If @error = 1 Then
    DirMove ( "C:\Kodak\XVCS6C_original", "C:\Kodak\XVCS6C" )
    Exit
EndIf
If $batch_number > 0 And $batch_number < 3300000 Then; This is the validation check
    $step1 = $step1 + 1
Else
    $step1 = $step1 + 0
    MsgBox ( 4112, "Error", "The batch number you entered ("&$batch_number&") is not inside the allowable range for this field (i.e. 0 to 3300000). Please click Ok (or press Enter) and re-enter the batch number." )
EndIf

Now, I basically want this dialog box to only accept numbers (no letters anywhere in the string), and the numbers can only be in the range of 0-3300000. The validation check I have there now fails (i.e. accepts the input as valid) if you type in a number and then a letter (e.g. 123a). If you type just a letter, it works fine (it won't accept it). If you type a letter followed by a number (e.g. a123) it works fine (it doesn't accept it). It's just that last case (123a) that I can't work out.

Check #2:

$scan6c_path = InputBox ( "Step 4.5: Scan6C Folder Location", "You have indicated that the IT staff have installed the Kodak software using a G: drive path. Please enter the path to the Scan6C folder and then click Ok (or press Enter) to continue. Entry is not case sensitive.", "" )
If @error = 1 Then
    DirMove ( "C:\Kodak\XVCS6C_original", "C:\Kodak\XVCS6C" )
    Exit
EndIf
$validation1 = StringRegExp ( $scan6c_path, "(?i)g:\\[^0-9]+scan6c\z", 0 ); This is the validation check
If $validation1 = 1 Then
    $step4_5 = $step4_5 + 1
Else
    $step4_5 = $step4_5 + 0
    MsgBox ( 4112, "Error", "The Scan6C folder path you have entered ("&$scan6c_path&") is not one of the allowable values (must be in the format ""g:\path to scan6c folder"") for this field. Please click Ok (or press Enter) and re-enter the Scan6C folder path." )
EndIf

This one is a little (actually, a lot) more complicated. It is basically asking the user to enter a path to a specific folder on the user's G: drive. Now, basically I want the validation check to:

-make sure that the user input starts with "g:\" (without quotes)

-ends with "\scan6c" (without quotes - scan6c is the name of the folder I want the user to input)

-have no characters that are not valid for a Windows path name (e.g. : ? etc)

I did start out this one by trying to use "If $scan6c_path < 0", but that basically rejected everything, even when you typed in a valid path. I then realised that it couldn't be done using the normal = < > operators, it could only be done by regexp - and regexp is something I just don't get. I've read a number of different guides on regexp over time, and no matter how simple the guide is, I just don't understand regexp. The regexp line I have there now was basically the result of a few hours of wild guesses - and it still doesn't work correctly. Any help on either of these two validation checks would be appreciated.

Regards,

CM

Link to comment
Share on other sites

A simple fix would be to use Number() to convert the string that is returned by the input box into a number... but you might also want to look at IsInt

Dim $step1
$batch_number = InputBox("Step 1: Batch Number", "Please enter the number of the batch last scanned and then click Ok (or press Enter) to continue.", "")
If @error = 1 Then
    DirMove("C:\Kodak\XVCS6C_original", "C:\Kodak\XVCS6C")
    Exit
EndIf

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
$batch_number = Number($batch_number);;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

If $batch_number > 0 And $batch_number < 3300000 Then; This is the validation check
    $step1 = $step1 + 1
Else
    $step1 = $step1 + 0
    MsgBox(4112, "Error", "The batch number you entered (" & $batch_number & ") is not inside the allowable range for this field (i.e. 0 to 3300000). Please click Ok (or press Enter) and re-enter the batch number.")
EndIf

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

I think...

; #1
If Not StringRegExp($batch_number, '[^\d]', 0) And $batch_number > 0 And $batch_number < 3300000 Then
    ;good stuff
Else
    ;bad stuff
EndIf

; #2
If StringRegExp($scan6c_path, '(?i)\Ag:\\([^\\/:*?"<>|]+\\)*scan6c\z', 0) Then
    ;good stuff
Else
    ;bad stuff
EndIf

Although I'm not that comfortable with RegExp either...

Edit: added case-insensitivity.

Edited by Siao

"be smart, drink your wine"

Link to comment
Share on other sites

...I then realised that it couldn't be done using the normal = < > operators, it could only be done by regexp...

"...couldn't be done..."

http://www.autoitscript.com/forum/index.ph...st&p=353575

I'll let you chew on how best to integrate those into your code.

You can add one "If line" to those in the post mentioned above that will check for "g:\" using StringTrimRight and another "If line" to check for "\scan6c" using StringTrimLeft

OR

You can tell the user to provide the "middle part" of the path... you will add the drive letter and final folder name.

OR

Use FileSelectFolder with an Initial/start directory of "g:\"

OR

any number of other options...

...hope this helps...

[size="1"][font="Arial"].[u].[/u][/font][/size]

Link to comment
Share on other sites

Hi everyone,

Thank you for the replies.

herewasplato: That first solution (convert it to a number) was a solution I hadn't thought of, thanks for pointing it out to me. It's actually a clever idea that. And I probably shouldn't have typed the words "couldn't be done" now that you've pointed out that yes, it can actually be done that way :whistle: Next time I think I will say "Can anyone tell me if this could be done this way" :lmao:

Siao: Both of those regexp lines work in my testing. The batch number is now not accepted if there is a letter anywhere in the string, and the scan6c path is now not accepted unless it begins with g:\ and ends with scan6c. I ended up implementing your solutions rather than the others posted, yours was the simplest (it's a work project I'm working on out of work hours, so I don't want to spend too much time on it and your lines fitted the bill nicely than you very much). From looking through the AutoIt helpfile again (the stringregexp function) I now understand the first regexp (the batch number one), but my eyes glazed over when I tried to interpret the scan6c path one - but I'm happy to know that it works without quite knowing how it works ;)

Regards,

CM

Edited by romulous
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...