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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

wildcard? 1

Status
Not open for further replies.

ntolani

Programmer
Apr 25, 2002
13
US
I was just wondering whether VBScript allows for the use of wildcards. For example, I'm looking to compare a known string with a list of user inputted strings. If one of the inputted strings contains the known string, I would like to display that string value. It works if the strings match exactly, however I want it to work if the inputted string at least contains the known string. I was thinking a wildcard would work here. What is the best way to go about this? Perhaps a substring comparison? Any help is much appreciated. I thank you in advance.
 
Hi John,
Thanks for your helpful and timely response. I was wondering if there was a different way of doing this without the use of Regular Expressions. I'm actually working on someone else's code that no longer works here and I'm trying to change as little as possible. Basically, he set a variable that has a value of "_test". This is sort of a default value.
variable_1 = "_test"
Later a user inputs a list of strings which become available in a dropdown menu. However, if one of the inputted values is "_test", the pulldown menu should default to this value. If none of the inputted values are "_test", then the pulldown menu defaults to no value. These inputted values are put into an array and checked one at a time against variable_1.
For i = 0 to total
If (variable_1 = array (i)) then
...default the pulldown menu to this value
...else default the pulldown menu to no value " "
End If
Next
What I want to do is modify his code such that it doesn't need to be an exact string match. So if an inputted value was "some_test" or "my_test" the if statement would hold true and the inputted value becomes the default value for the pulldown menu.
I hope this makes a little more sense than my previous question. Again I thank you for your response and would appreciate any other information.
 
Hi Jon,

Thanks for your help. Your code definitely works better than anything else I've tried...but it still doesn't work completely. It allows the script to recognize "_test", but still doesn't match other things like "my_test" or "some_test". Any ideas why it doesn't?
 
Make sure your arguments are in the correct order. If you have them reversed, that would produce the bevahior you describe.

IF INSTR(1,"my_test","_test",1) > 0 THEN

FWIW,

sSearchFor = "_test"
sSearch1 = "my_test"
sSearch2 = "MY_TEST"
sSearch3 = "some_test"

WScript.Echo InStr(1,sSearch1,sSearchFor,1) 'shows 3
WScript.Echo InStr(1,sSearch2,sSearchFor,1) 'shows 3
WScript.Echo InStr(1,sSearch3,sSearchFor,1) 'shows 5 Jon Hawkins
 
Hi Jon,
Your code works. I just had to add it to another area of the code (as I said before, I'm working on someone else's stuff). Thanks so much for the help. I appreciate it.
-Neil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top