Specify Character Range in function parameter

A

aft3rgl0w

Hello, I'm trying to lookup a value in a textbox on a form. It is in the
format ##a (number-number-letter) and indicates a cycle (such as 07D, 06G,
etc). I am currently using the instr function, trying the following:
varCycle = Instr(Text5,"[0-9][0-9][a-k]") which obviously does not work, as
it's looking for a literal string, not a range. Basically, I want to search
the textbox box for the cycle using the wildcards/ranges and assign it to the
variable. I'm probably way off course but I can't find any other info on
specifying a range of characters in a function. Any help is much appreciated
 
M

Marshall Barton

aft3rgl0w said:
Hello, I'm trying to lookup a value in a textbox on a form. It is in the
format ##a (number-number-letter) and indicates a cycle (such as 07D, 06G,
etc). I am currently using the instr function, trying the following:
varCycle = Instr(Text5,"[0-9][0-9][a-k]") which obviously does not work, as
it's looking for a literal string, not a range. Basically, I want to search
the textbox box for the cycle using the wildcards/ranges and assign it to the
variable. I'm probably way off course but I can't find any other info on
specifying a range of characters in a function.


That's right, InStr does not work with wildcards.

If all you need to do is find a record that meets the
pattern, use the Like operator instead:

Like "##[a-k]"

If you also need to extract that part from a larger text
value, then you'll need to parse the text to find where the
match is located.

If you are feeling really adventurous, you can try using the
RegEx function in the MS VBScript Regular Expressions
library to do it all.
 
A

aft3rgl0w

thanks for confirming that for me. do you have any examples of or know of
any websites with nifo on how to parse the test field or on the RegEx
function? I've not had much experience with that. Thanks again for your help!

Marshall Barton said:
aft3rgl0w said:
Hello, I'm trying to lookup a value in a textbox on a form. It is in the
format ##a (number-number-letter) and indicates a cycle (such as 07D, 06G,
etc). I am currently using the instr function, trying the following:
varCycle = Instr(Text5,"[0-9][0-9][a-k]") which obviously does not work, as
it's looking for a literal string, not a range. Basically, I want to search
the textbox box for the cycle using the wildcards/ranges and assign it to the
variable. I'm probably way off course but I can't find any other info on
specifying a range of characters in a function.


That's right, InStr does not work with wildcards.

If all you need to do is find a record that meets the
pattern, use the Like operator instead:

Like "##[a-k]"

If you also need to extract that part from a larger text
value, then you'll need to parse the text to find where the
match is located.

If you are feeling really adventurous, you can try using the
RegEx function in the MS VBScript Regular Expressions
library to do it all.
 
M

Marshall Barton

aft3rgl0w said:
thanks for confirming that for me. do you have any examples of or know of
any websites with nifo on how to parse the test field or on the RegEx
function?

Parsing a string for that pattern could be along the lines
of this air code:

For k = 1 To Len(thestring) - 2
If Mid(thestring, k, 3) Like "##[a-h]" Then
strCycle = Mid(thestring, k, 3)
Exit For
End If
Next k

Regular expressions are a study topic all their own. There's
a lot of info at the microsoft web site (search for VBscript
RegExp). This might be a place to start:
http://support.microsoft.com/kb/818802
Note that most(?) things about VB6 also apply to VBA and I
am not sure where/what contains RegExp for Vista/A2007
 
A

aft3rgl0w

perfect, thanks so much for all your help!!

Marshall Barton said:
aft3rgl0w said:
thanks for confirming that for me. do you have any examples of or know of
any websites with nifo on how to parse the test field or on the RegEx
function?

Parsing a string for that pattern could be along the lines
of this air code:

For k = 1 To Len(thestring) - 2
If Mid(thestring, k, 3) Like "##[a-h]" Then
strCycle = Mid(thestring, k, 3)
Exit For
End If
Next k

Regular expressions are a study topic all their own. There's
a lot of info at the microsoft web site (search for VBscript
RegExp). This might be a place to start:
http://support.microsoft.com/kb/818802
Note that most(?) things about VB6 also apply to VBA and I
am not sure where/what contains RegExp for Vista/A2007
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top