Is it possible to compare a string variable with a string in double quotes or do they both have to be defined string variables?
I know I can use the strComp function but am curious why the other won't work.
Look up StrComp function in VBHelp to check all the options Let me know if this helps
________________________________________________________________
If you are worried about how to post, please check out FAQ222-2244 first
'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
I have checked into using the string compare function but one of my colleagues is trying to do
Dim strVar1 as string
'The strVar1 is filled in the program and he wants to compare it with the value in quotes. If the strVar1 is the same length as the value in quotes shouldn't this type of comparison work? If not should the strVar1 variable have all its blanks removed before doing the comparison.
If strVar1 = "Var1" then
process
else
other process
end
Yes you will need to strip any leading or trailing blanks - look for the Trim() function Let me know if this helps
________________________________________________________________
If you are worried about how to post, please check out FAQ222-2244 first
'There are 10 kinds of people in the world: those who understand binary, and those who don't.'
Try this code, (Notice the "Tt" in test versus Test) and see what happens.
[tt]Option Explicit
Dim S As String
Private Sub Form_Load()
S = "test"
If S = "Test" Then
MsgBox "match"
ElseIf S < "Test" Then
MsgBox "Variable less than"
ElseIf S > "Test" Then
MsgBox "Variable Greater Than" End If
End Sub
[/tt]
Then try this code (Notice "Option Compare Text" and see what happens
[tt]Option Compare Text Option Explicit
Dim S As String
Private Sub Form_Load()
S = "test"
If S = "Test" Then
MsgBox "match"
ElseIf S < "Test" Then
MsgBox "Variable less than"
ElseIf S > "Test" Then
MsgBox "Variable Greater Than" End If
Thank you both for your help. Looks like my colleaque forgot about the trim function. I did too. Once he added the trim function the comparison worked fine.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.