Click to See Complete Forum and Search --> : Commas and List box


Bill_H
April 4th, 2001, 03:11 PM
Why does a list box "wrap" to a new line or create a new field when it encounters a comma in the following code? ...The commas only cause a "wrap" after a string containing a comma is retrieved from disk and added to List2...

'1 form, 2 list boxes, 2 command buttons

Private Sub Command1_Click()
List1.AddItem "A line with a , comma."
Call SaveData(List1, App.Path & "\ListData.dat")
End Sub

Private Sub Command2_Click()
Call GetData(List2, App.Path & "\ListData.dat")
End Sub

Public Sub SaveData(TheList As ListBox, MyString As String)
Dim SaveList As Long

Open MyString$ For Output Shared As #1

For SaveList& = 0 To TheList.ListCount - 1
Print #1, TheList.List(SaveList&)
Next SaveList&

Close #1
End Sub

Public Sub GetData(TheList2 As ListBox, MyString2 As String)
Dim Item As String

Open MyString2$ For Input Shared As #1

While Not EOF(1)
Input #1, Item$
DoEvents
TheList2.AddItem Item$
Wend

Close #1
End Sub

John G Duffy
April 4th, 2001, 03:58 PM
In sub GetData, change your "Input" statement to "Line Input".
the comma in the input stream is a Basic function delimiting a end of token.

John G

Bill_H
April 4th, 2001, 04:12 PM
It works perfectly!