Solved retrieve text file content into listbox but not retrieve after comma

maruli

New member
Local time
Today, 12:15
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:
Total gamble, the comma is the column seperator. try replacing out the comma for a semi column or pipe simbol, see if that helps.
 
do you want not to truncate your List Item?

...
...
While Not EOF(1)
Line Input #1, strListItems
FileList.AddItem """" & strListItems & """"
x = x + 1
Wend
...
 
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.
 
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?
 
I guess I was confused by the wording. Who knows.
Happy New Year :0
 
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)
 
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
 
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

Back
Top Bottom