tags:

views:

38

answers:

2

I am trying to compare two strings in VB but compareTo, compare, equals etc all give compile errors.

    If String.Compare(string_one, string_two) = 0 Then
        ...do stuff
    End If
    If String.Equals(string_one, string_two) Then
        ...do stuff
    End If

Now both lines give me the error Compile error: Expected: (

and it highlights the dot after String*.*

Do I need to include something, I normally program C, Java and C# so I am not very familar with VB

Now I am doing this in a very crappy program that uses Microsoft Visual Basic 6.5 is it that these functions just simply do not exist?

+1  A: 

VB6 just uses the = operator:

If string_one = string_two Then
    ''# Do Stuff
End If

For that matter you do it that way in VB.Net as well, though vb.net also allows the .Equals() function in this form:

If string_one.Equals(string_two) Then
    ''# Do Stuff
End If
Joel Coehoorn
wow that makes it easy, I thought I tried that but it always resulted in true.
rolls
A: 

You could also use StrComp function:

StrComp(String1, String2, [Compare As VbCompareMethod = vbBinaryCompare])

Smith