Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I have a problem comparing data from a text file with a variable

Status
Not open for further replies.

FreedomP

ISP
Jun 28, 2003
14
CA
I have taken data from a text file and placed it in a listbox but I can't compare the data in the listbox to a variable.

counter = 0
Open "C:\MyFiles\Visual Basic 6.0\Excel Storage\Username Storage.txt" For Input As #1
Do While Not EOF(1)
Input #1, AlreadyTaken
List1.AddItem AlreadyTaken '(Display the contents of the file in a listbox, textbox or whatever you prefer)
counter = counter + 1
Loop
Close #1

That puts the data into the listbox but when I try to compare the data with a variable I can't get it to work.
 
In debug mode, make sure that the data in the list box that you are comparing to the variable is what you expect. That is, you may 'think' you are reading a line from the listbox (e.g. "Apple") when in fact you could be reading a different line (e.g. "Orange").
 
Hi,
I am not really clear on what you are wanting to compare here but I can help you I believe.

If you are wanting to compare the data in a list box with a variable you can do it this way.

dim avariable as string

avariable = "hello"

if trim(ucase(lisbox.text))=ucase(avariable) then ...

This should do the trick if I am understanding what you are asking.

Noble


 
Change
List1.AddItem AlreadyTaken
to
List1.AddItem Trim$(AlreadyTaken)
Because
"Hello " does not equal "Hello"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top