List Box

I am making a search engine for a phone book. Each line is a person and their work number ie Bob Smith 1234.
Below is the sample from the DOCS pertaining to list box. Here is what I need modified.

  1. I already have a file on the desktop so I DO NOT need to open a dialog box. How do I code that.
  2. I am looking for a certain word in each line ie Bob
  3. I need the persons name, Bob Smith, put in column 1 of the list box
  4. I need 1234 in column 2 of the list box
  5. I would like the list box to be aligned left.
  6. I need column 1 named NAME, and column 2 named Number, default is 0 and 1. Cant figure out how to name the column.

any help would be greatly appreciated.

[code] Dim f As FolderItem
Dim textInput As TextInputStream
Dim rowFromFile, oneCell As String
Dim i As Integer
f = GetOpenFolderItem(“text/plain”) // defined as a FileType
If f <> Nil And f.Exists Then
Dim tab As String = ChrB(9)
textInput = TextInputStream.Open(f)
textInput.Encoding = Encodings.MacRoman // strings are MacRoman
While Not textInput.EOF
rowFromFile = textInput.ReadLine

  // Set
  If ListBox1.ColumnCount < CountFields(rowFromFile, tab) Then
    ListBox1.ColumnCount = CountFields(rowFromFile, tab)
  End If
  
  ListBox1.AddRow("")
  For i = 1 To CountFields(rowFromFile, tab)
    oneCell = NthField(rowFromFile, tab, i)
    ListBox1.Cell(ListBox1.ListCount - 1, i - 1) = oneCell
  Next
Wend
textInput.Close

End If[/code]

For Column Headers, put this in the open event of the listbox:

me.heading(0) = “Name”
me.heading(1) = “Number”

To write to the second column in your listbox in your loop:

Listbox1.AddRow “Data here goes in column 1 (0)”
Listbox1.Cell(Listbox1.LastIndex,1) = “Data here goes in column 2 (1)”

Columns are 0 based…

I already have a file on the desktop so I DO NOT need to open a dialog box. How do I code that.

 f = specialfolder.desktop.child("Myfilename.txt")

thanks guys, I’m making progress, will probably have more questions.

I come from 20 years of Applescript (Mac) and 4 years of AutoHotKey (PC). I’m still learning XOJO which I love.

I need to get the text from a text box (John) and need to find that in a text file like this
Adam Curry 555-9876
John Smith 123-4567
John Jones 345-6789
Mary Franks 444-1278

I want to but the first and last name in column 1 and the phone number in column 2

here is what I have so far

[code] dim the_name as string
TextField2.text

Dim f As FolderItem
Dim textInput As TextInputStream
Dim rowFromFile, oneCell As String
Dim i As Integer
f = specialfolder.desktop.child(“CBNphonebook.txt”) //from XOJO forum
If f <> Nil And f.Exists Then
Dim tab As String = ChrB(9)
textInput = TextInputStream.Open(f)
textInput.Encoding = Encodings.MacRoman // strings are MacRoman
While Not textInput.EOF
rowFromFile = textInput.ReadLine

  // Set
  If ListBox1.ColumnCount < CountFields(rowFromFile, tab) Then
    ListBox1.ColumnCount = CountFields(rowFromFile, tab)
  End If
  
  ListBox1.AddRow("")
  For i = 1 To CountFields(rowFromFile, tab)
    // from example
    //oneCell = NthField(rowFromFile, tab, i)
    //ListBox1.Cell(ListBox1.ListCount - 1, i - 1) = oneCell
    
    //from forum
    Listbox1.AddRow "Data here goes in column 1 (0)"
    Listbox1.Cell(Listbox1.LastIndex,1) = "Data here goes in column 2 (1)"
  Next
Wend
textInput.Close

End If[/code]