If Statement With Wildcard Not Working Follow

0
Avatar
Legacy Poster

Hi, I have entered the below IF statement to make a textbox display a value based on a field.

If the field starts with GB the box should display Made in GB, if CZ Made in CZ, anything else Error.

However it doesn't work and I can't find any proper information on what wildcard to use for numbers only.

If I enter a whole serial number it works fine.

 

 

If Format.NamedSubStrings("Serial").Value ="GB********" Then


    value = "Made in GB"


Elseif Format.NamedSubStrings("Serial").Value ="CZ********" Then


    value = "Made in CZ"


Else


    value = "Serial error"


End If 
 

Any ideas? Thank you for reading.

 

2 comments

0
Avatar
Shotaro Ito
Comment actions Permalink

VB Script doesn't have wildcard in IF statement, unlike VBA.

for "begins with" condition, just take 2 characters like

If Left(Format.NamedSubStrings("Serial").Value,2) = "GB" Then...

Besides you can use Regular Expression object for wildcard and more flexible matching - see below.

http://stackoverflow.com/questions/16682155/vbs-compare-strings-using-wildcard

0
Avatar
Legacy Poster
Comment actions Permalink

VB Script doesn't have wildcard in IF statement, unlike VBA.

for "begins with" condition, just take 2 characters like

If Left(Format.NamedSubStrings("Serial").Value,2) = "GB" Then...

Besides you can use Regular Expression object for wildcard and more flexible matching - see below.

http://stackoverflow.com/questions/16682155/vbs-compare-strings-using-wildcard

 

Thank you, works perfectly using begins with.

Please sign in to leave a comment.