syntax instr()

W

wba

Hi all,

I want to be able to control if the two leftmost
characters in a string are numbers, e.g. if left$(strVar,
2) = "04"

My code reads :

If InStr(Left$(strCourse, "0123456789") = 0

'

I don't seem to be able to get the syntax right though.

Can anyone help ?

Thank you very much,

W
 
N

Newbie

Try something like: (not tested)

Function instrprob()
Dim strCourse As String
Dim orgst As String

strCourse = "09"
orgst = "0123456789"

If InStr(strCourse, Left(orgst, 2)) Then
MsgBox "Correct"
Else
MsgBox "Incorrect"
End If
End Function

hth
 
M

Marshall Barton

wba said:
I want to be able to control if the two leftmost
characters in a string are numbers, e.g. if left$(strVar,
2) = "04"


I don't think InStr is much help for this. If you just want
to see if the left most two characters are both decimal
digits, you could use this:

If strVar Like "##*" Then
 

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