Solved retrieve text file content into listbox but not retrieve after comma (1 Viewer)

maruli

New member
Local time
Today, 17:11
Joined
May 18, 2020
Messages
6
hi...iam beginner need help..

I want to insert (retrieve) text file which is consist of multiple line into list box
Example:
1170302000386 X18 COBA 1 20,000,000 41 1,000,000 258,333 1,258,333 19,000,000 60
1170302000399 X18 COBA 2 33,333,320 41 1,666,667 430,555 2,097,222 31,666,653 60

then I used code like this:
Code:
Dim f As Office.FileDialog
Dim str As String
FileList.RowSource = ""
Dim strListItems As String
Dim data As String

Set f = Application.FileDialog(msoFileDialogFilePicker)
f.AllowMultiSelect = False
f.Title = "Choose File"
f.Filters.Clear
f.Filters.Add "TXT", "*.txt*"
If f.Show Then
str = Application.FileDialog(msoFileDialogOpen).SelectedItems(1)
Open str For Input As #1
   While Not EOF(1)
    Line Input #1, strListItems
    FileList.AddItem strListItems
    x = x + 1
   Wend
Close #1
FileName = str
End If


then the result like this:
1170302000386 X18 COBA 1 20
1170302000399 X18 COBA 2 33

my question is:
Why after comma is missing then continue to next row and so on and so on.

Please..probably u can help me so the text can retrieve all the content in the line


Thx
 
Last edited by a moderator:

namliam

The Mailman - AWF VIP
Local time
Today, 11:11
Joined
Aug 11, 2003
Messages
11,696
Total gamble, the comma is the column seperator. try replacing out the comma for a semi column or pipe simbol, see if that helps.
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 18:11
Joined
May 7, 2009
Messages
19,169
do you want not to truncate your List Item?

...
...
While Not EOF(1)
Line Input #1, strListItems
FileList.AddItem """" & strListItems & """"
x = x + 1
Wend
...
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:11
Joined
Feb 19, 2002
Messages
42,970
Use Instr() to find the location of the first coma. Use that location in the Left() function to limit the part of the string you select.
 

Gasman

Enthusiastic Amateur
Local time
Today, 10:11
Joined
Sep 21, 2011
Messages
14,038
Use Instr() to find the location of the first coma. Use that location in the Left() function to limit the part of the string you select.
I *thought* the o/p wanted everything on the line and that they were losing anything after that first comma?
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 06:11
Joined
Feb 19, 2002
Messages
42,970
I guess I was confused by the wording. Who knows.
Happy New Year :0
 

Cronk

Registered User.
Local time
Today, 21:11
Joined
Jul 4, 2013
Messages
2,770
I also think the OP was querying the truncation of the string. Looks like the list box is treating the commas as column separators and if the list box was multicolumn, the rest would probably be in those columns.

To fix it to have the whole string in one column use
Code:
    FileList.AddItem chr(34) & strListItems & chr(34)
 

maruli

New member
Local time
Today, 17:11
Joined
May 18, 2020
Messages
6
do you want not to truncate your List Item?

...
...
While Not EOF(1)
Line Input #1, strListItems
FileList.AddItem """" & strListItems & """"
x = x + 1
Wend
...
txh bro...it works:):D:D
 

maruli

New member
Local time
Today, 17:11
Joined
May 18, 2020
Messages
6
I also think the OP was querying the truncation of the string. Looks like the list box is treating the commas as column separators and if the list box was multicolumn, the rest would probably be in those columns.

To fix it to have the whole string in one column use
Code:
    FileList.AddItem chr(34) & strListItems & chr(34)
txh bro...it works :D:D:D
 

Users who are viewing this thread

Top Bottom