String Comparison

colelinux
09-08-2003, 01:15 AM
I've asked a lot of question today.. lol..
however... i encounter another problem again! ARGH!

I tried to compare 2 strings using this:

Dim obj1 As String
Dim obj2 As String
obj1 = "*" & Text1.Text & "*"
obj2 = Text2.Text

If obj2 Like obj1 Then
MsgBox "Similar"
Else
MsgBox "Not Similar"
End If

obj1 is cole, and obj2 is MJ Cole.. and it works

When i move these codes to the actual program i'm working on.. which is a little bit different:


Dim obj1 As String
Dim obj2 As String

obj1 = "*" & txt_query.Text & "*"
obj2 = lst_artist.List(lst_artist.ListIndex)

If obj2 Like obj1 Then
MsgBox "Similar"
Else
MsgBox "Not Similar"
End If


obj1 is taken from a textbox, and obj2 is taken from the name of an item in a listbox.

I'm pretty sure obj1 is cole, and obj2 is MJ Cole... but the it shows out the message box "Not Similar"

Why? Why? Why in the world?

irri
09-08-2003, 01:27 AM
Just add some breakpoints, and the check if obj2 actually get't the correct value from the listbox.

colelinux
09-08-2003, 01:29 AM
i tried that... the strings are correct.. something is wrong......

colelinux
09-08-2003, 01:55 AM
i tried changing cole to Cole and it works!
but i don't want it to... detect whether it's upper or lower.. what should i do? any ideas?

SpaceFrog
09-08-2003, 02:10 AM
Convert strings to lower case and compare after:
obj1 = lcase("*" & txt_query.Text & "*")
obj2 = lcase(lst_artist.List(lst_artist.ListIndex))

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum