gettingstarted
[Top] [All Lists]

Re: Reading in text from a file into a ListBox with 2 columns

To: Getting Started <gettingstarted at lists dot realsoftware dot com>
Subject: Re: Reading in text from a file into a ListBox with 2 columns
From: Phil Heycock <pheycock at bellsouth dot net>
Date: Sat, 29 Jan 2005 22:32:44 -0500
Delivered-to: gettingstarted at lists dot realsoftware dot com
Hi, Paul,

Taking this a step further, consider making the 'write-to-file' a part of
the custom ListBox class functionality, as well. Add another method:

Sub writeToTextFile(t As TextOutputStream)
    Dim row As Integer
    // Write the first row to file
    t.WriteLine concatenateRow(row) // row is zero (0) here
    // Write the remaining rows, if any... delimited
    For row = 1 To ListCount - 1
        t.WriteLine EndOfLine + concatenateRow(row)
    next
End Sub

Your PushButton.Action event would contain this code, calling a method
('saveListBox') in the Window:

Sub Action()
    If ListBox1.ListCount > 0 Then
        saveListBox
    Else
        Beep
        MsgBox "The ListBox is empty. Nothing to save."
    End If
End Sub

Sub saveListBox ()

    dim f as FolderItem = PreferencesFolder.Child("filename.plist")
    dim t as TextOutputStream = f.CreateTextFile

    If t <> nil Then
        ListBox1.writeToTextFile t
        t.close
    Else
        Beep
        MsgBox "File not opened. Nothing saved."
    End If
    
End Sub


>> Function contatenateRow(row As Integer) As String
>>     Dim col As Integer
>>     Dim rowTxt As String = Cell(row, col) // col is zero (0) here
>>     For col = 1 To ColumnCount - 1
>>         rowTxt = rowTxt + HT + Cell(row, col)
>>     Next
>>     Return rowTxt
>> End Function

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>