Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF then Wild Card 1

Status
Not open for further replies.

saw15

Technical User
Jan 24, 2001
468
US
Can I use a wild card in vbscript within a if then statement ? Basically I am looking for any version of IE or NN.

Example:

If variable = "IE" or variable = "NN*" then
variable = true
else
variable = false
End if

Help / comments appreciated.
 
Take a look at the RegExp object

Hope This Help
PH.
 
Yes, RegExp object is the best way and you need to get familiar with all it capabilities and nuances, but if you only need a simple way to check a fixed number of characters at the beginning of a string, then this also would work:

Code:
If inStr("IE,NN",left(variable,2)) Then

If you're not sure if they'll be uppercase, then you can ignore upper and lower this way:

Code:
If inStr("IE,NN",ucase(left(variable,2))) Then
 
first a correction for dbMark : you have to split your "IE,NN" into two inStr() searches - what you have above searches for the exact string "IE,NN" rather than either "IE" or "NN".

Secondly, if you only want to check the first two chars of variable - then there's no need to use inStr:

Code:
Dim blnFound, strBrowser

strBrowser = &quot;IE V6.0(...)&quot; '<- get browser line here
strBrowser = left(strBrowser, 2) 'get first 2 chars only

If (strBrowser = &quot;IE&quot; OR strBrowser = &quot;NN&quot;) then 
 blnFound = true
else
 blnFound = false
End if

hope you can work it out from there


Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
Or even:
Code:
Dim strBrowser, blnFound

strBrowser = &quot;IE V6.0(...)&quot; '<- get browser line here
strBrowser = Left(strBrowser, 2) 'get first 2 chars only

blnFound = (strBrowser = &quot;IE&quot; Or strBrowser = &quot;NN&quot;)

Or yet even:
Code:
Dim aryBrowsers, strBrowser, blnFound

aryBrowsers = Array(&quot;IE&quot;, &quot;NN&quot;)

strBrowser = &quot;IE V6.0(...)&quot; '<- get browser line here
strBrowser = Left(strBrowser, 2) 'get first 2 chars only

blnFound = UBound(Filter(aryBrowsers, strBrowser, True, vbTextCompare)) > -1

The last example makes it easy to check for multiple matches.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top