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!

Text Input Question 2

Status
Not open for further replies.

Calypso06

Programmer
Feb 18, 2005
15
US
Hello,
I am trying to input a text file into 3 list boxes. But before I do this I must remove "|" and put the the string before it into its respective listbox.

example

Text file:
7|12 Pack Pepsi|4.99

'the lists should look like

list1:
7

list2:
12 Pack Pepsi

list 3:
4.99

Thank you in advance
 
Check out the split function. It will take a string like you have and convert it into an array of substrings by splitting it on a specific character.


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Yeah easy:

Code:
Dim a() As String
a = Split("7|12 Pack Pepsi|4.99", "|")
list1.AddItem a(0)
list2.AddItem a(1)
list3.AddItem a(2)

It is much better not to have list1, list2, etc but array of the lists: list(). So you would replace "list1.AddItem a(0) etc" with (in case you have many lists) :

Code:
for i = 0 to UBound(a)
  list(i).AddItem a(0)
Next


-hope helped
-bclt
 
Ouppss

for i = 0 to UBound(a)
list(i).AddItem a(i)
Next

-
 
Something like this:

Code:
Dim StrToSplit As String
Dim StrSplit() As String

StrToSplit = "7|12 Pack Pepsi|4.99"

StrSplit = Split(StrToSplit, "|") 

MsgBox StrSplit(0) 'Displays "7"
MsgBox StrSplit(1) 'Displays "12 Pack Pepsi"
MsgBox StrSplit(2) 'Displays "4.99"

Except, obviously, the SreToSplit variable comes from the text file!

The StrSplit(0) through to StrSplit(2) can then be assigned to your list boxes...

Hope this helps!

Tim
 
Genuises. thank god for tek-tips! It was the simple stuff that got me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top