ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   usings contains in var check (https://www.excelbanter.com/excel-programming/318917-usings-contains-var-check.html)

Bruce

usings contains in var check
 
How do I check that a variable 'contains' something?

eg.

myVar = "myfile01203"

If myVar contains "myfile" then
'do something
End if



Norman Jones

usings contains in var check
 
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

---
Regards,
Norman



"Bruce" wrote in message
...
How do I check that a variable 'contains' something?

eg.

myVar = "myfile01203"

If myVar contains "myfile" then
'do something
End if





Bruce

usings contains in var check
 
Not quite what I was thinking. Let me try again.

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

"Norman Jones" wrote:

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

---
Regards,
Norman



"Bruce" wrote in message
...
How do I check that a variable 'contains' something?

eg.

myVar = "myfile01203"

If myVar contains "myfile" then
'do something
End if






Norman Jones

usings contains in var check
 
Hi Bruce,

sStr = "myfile01203"

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

---
Regards,
Norman



"Bruce" wrote in message
...
Not quite what I was thinking. Let me try again.

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




Eric[_26_]

usings contains in var check
 
Norman Jones wrote:

Hi Bruce,

sStr = "myfile01203"

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

---
Regards,
Norman



"Bruce" wrote in message
...
Not quite what I was thinking. Let me try again.

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


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


Bruce

usings contains in var check
 
Eric,

Ive got it;

If myVar like sStr & "*" Then

Bruce

"Eric" wrote:

Norman Jones wrote:

Hi Bruce,

sStr = "myfile01203"

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

---
Regards,
Norman



"Bruce" wrote in message
...
Not quite what I was thinking. Let me try again.

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


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



Norman Jones

usings contains in var check
 
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
---
Regards,
Norman



"Eric" wrote in message
news:jzvvd.755094$8_6.482955@attbi_s04...
Norman Jones wrote:

Hi Bruce,

sStr = "myfile01203"

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

---
Regards,
Norman



"Bruce" wrote in message
...
Not quite what I was thinking. Let me try again.

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


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




Eric[_26_]

usings contains in var check
 
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


Bruce wrote:

Eric,

Ive got it;

If myVar like sStr & "*" Then

Bruce

"Eric" wrote:

Norman Jones wrote:

Hi Bruce,

sStr = "myfile01203"

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

---
Regards,
Norman



"Bruce" wrote in message
...
Not quite what I was thinking. Let me try again.

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


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




Eric[_26_]

usings contains in var check
 
Norman Jones wrote:

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
---
Regards,
Norman

Is that case sensitive? if so how do you ignore case?
if not how do you make it case specific?
Thanks
Eric


Norman Jones

usings contains in var check
 
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



"Eric" wrote in message
news:w%vvd.190497$V41.190304@attbi_s52...




All times are GMT +1. The time now is 06:31 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com