WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

How To
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Validate WIL Variable Name

 Keywords: Validate WIL Variable Name Var Substitution StrClean Reserved Keyword 3074 Expression Continues Past Expected End 3054 Unrecognizable Item Found on Line 3055 Variable Name Over 30 Characters Too Long

Question:

I need to validate commandline input. The user passes a parameter that is used as a WIL variable, using variable subtitution. How can I confirm the user input a Valid WIL variable name?

Answer:

There are rules about which varaible names can be used. If you name a variable something like, "852Path", you'll get an error message that says something about, "Expression continues past expected end."

You should also add code to confirm the user is not passing a restricted keyword ( For, Select, Pause etc). The WIL.CLR file contains a list of functions and keywords.

input = 'abc'   ; ok
;input = '1abc'  ; bad - remove int as first charater
;input = 'abc?' ; bad -  replace ? with _
;input = 'abcdefghijklmnopqrstuvwxyz0123456789' ; bad - to many chars, truncate to 30
;input = 'Pause' ; bad - function name
;input = 'Select' ; bad - keyword name

; Don't allow first character to be a number, remove if found
If IsInt(StrSub( input, 1, 1 )) Then input = StrSub( input, 2, -1 )
; Replace all non-var characters with underscore
alpha="abcdefghijklmnopqrstuvwxyz0123456789@_" ; allowed
; Truncate length  to 30 characters
input = StrSub( input, 1, 30 )
input = StrClean( input, alpha, "_", @FALSE, 2 )

;Confirm its not a keyword, if so append a leading underscore
clrfile = DirHome() : "wil.clr"
flag = IniReadPvt( "keywords", input, 0, clrfile )
If flag != 0 Then input = '_':input

%input% = 'hello world'
Pause('Variable : ', %input% )
Exit


Article ID:   W17951
Filename:   Validate WIL Variable Name.txt
File Created: 2013:02:26:10:40:50
Last Updated: 2013:02:26:10:40:50