Mysticism with compare strings...

Discorez

Member
Licensed User
Longtime User
BList contains values from "1" to "10".
I need to find an element index on its text value.

Simple code below, always returns -1...

Why?! :BangHead:

For example, sValue = 4
B4X:
Sub GetIndexByName(sValue As String) As Integer
   For i = 0 To Blist.Count -1
        Item.Value = BList.GetItem(i)
        If StrCompare(sValue, Item.Text, cCaseInsensitive) = 0 Then Return i 'Dont work!
        If sValue = Item.Text Then Return i 'Dont work too!
        If sValue = i Then Return i 'It work if i = 4...
   Next
   Return -1
End Sub

Any problem with the Item.Text?
 

mjcoon

Well-Known Member
Licensed User
Why?! :BangHead:
Any problem with the Item.Text?

Why not put your code into a complete minimal program and attach it so anyone can run it and watch what happens within the IDE?

A bList is a GUI object. Does it display properly when you have set it up?

Why not include some MsgBox lines just to show what values you are manipulating?

Mike.
 

mjcoon

Well-Known Member
Licensed User
What sort of object is "Item"?

I assumed it was a bListItem, as in
item.Value = list.GetItem(n)
per suggestion in bList.chm. It is all a bit sensitive to the setting up of the bList!

So it would be good to have some background information...

(I have not yet used bList.dll.)

Mike.
 

Discorez

Member
Licensed User
Longtime User
Very much I apologize... Today all works normally. :signOops:
Anything in the code didn't change. I dont know, why... Very strange...

agraham
msg = sValue & CRLF & item.Text
msgbox(msg, "")

yesterday, I did it, MSGBOX shows 4 4 (4 - find value & 4 item text value) but at comparing strings aren't identical. The cycle is done by the following iteration and function returns -1
 

Discorez

Member
Licensed User
Longtime User
or other non-displaying character in it
agraham, You are genius! :)
Correctly, lengths of lines were various...
Msgbox(StrLength(aName) & " " & StrLength(Item.Text))
shows 1 & 2

Many thanks!
 
Top