usings contains in var check

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I check that a variable 'contains' something?

eg.

myVar = "myfile01203"

If myVar contains "myfile" then
'do something
End if
 
Hi Bruce,

Try something like:

Sub Test01()
Dim myVar As String

' myVar = "myfile01203"

If Len(myVar) > 0 Then
'do something, e.g.
MsgBox myVar
Else
'do something else?
End If
End Sub
 
Not quite what I was thinking. Let me try again.

I want to test whether my Var contains myfile. Any ideas...
 
Hi Bruce,

sStr = "myfile01203"

If myVar = sStr Then
'do something, e.g.
MsgBox myVar
Else
'do something else?
End If
 
Norman said:
Hi Bruce,

sStr = "myfile01203"

If myVar = sStr Then
'do something, e.g.
MsgBox myVar
Else
'do something else?
End If

No, you still dont see what he is saying.

sStr= "My dogs name is spot"

if sStr contains "spot" then
' do this code
end if

I havnt any idea how to do this in vba
in c its simple if(strstr(sStr, "spot"))
{
// do code here
}
I too was looking for this but unfortunately MS doesnt list functions in the
help - you have to already know the function name to find it.
At least thats my experience.
Eric
 
Hi Eric,

I think you have the correct interpretation!

Sub Test01()
Dim myVar As String
Dim sStr As String

myVar = "myfile01203"
sStr = "myfile"
myVar = "myfile01203"
If InStr(1, myVar, sStr, vbTextCompare) Then
'do something, e.g.
MsgBox "myVar contains the substring " & sStr
Else
MsgBox sStr & " not found"
End If
End Sub
 
so, if
myVar="spot"
sStr= "My dogs name is spot"

then
If myVar like sStr & "*" Then
' code will be executed here for sure?
end if

I dont get the & "*" thing, whats that mean?
Eric
 
Norman said:
Hi Eric,

I think you have the correct interpretation!

Sub Test01()
Dim myVar As String
Dim sStr As String

myVar = "myfile01203"
sStr = "myfile"
myVar = "myfile01203"
If InStr(1, myVar, sStr, vbTextCompare) Then
'do something, e.g.
MsgBox "myVar contains the substring " & sStr
Else
MsgBox sStr & " not found"
End If
End Sub
Is that case sensitive? if so how do you ignore case?
if not how do you make it case specific?
Thanks
Eric
 
Hi Eric,
Is that case sensitive?
No.

if not how do you make it case specific?

If InStr(1, myVar, sStr, vbBinaryCompare) Then

---
Regards,
Norman



news:w%vvd.190497$V41.190304@attbi_s52...
 

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

Back
Top