CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2001
    Posts
    2

    Commas and List box

    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




  2. #2
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: Commas and List box

    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

  3. #3
    Join Date
    Apr 2001
    Posts
    2

    Thanks John!!!

    It works perfectly!


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured