Passing text file into ComboBox

Hi, I am trying to read a text file and populate each line from the file into the ComboBox.

I have this code


Dim t As TextInputStream
Dim f As FolderItem
Dim dlg As OpenDialog


dlg = New OpenDialog

f = dlg.ShowModal() // open open dialog for selecting a file to load

if f<> nil then
  t = f.OpenAsTextFile // open selected text file

  ComboBox1.InitialValue = t.ReadAll

else
  //user cancelled
end

Return True

Apparently, I need to loop through each line in the text and then pass it into the ComboBox.InitialValue.

I would appreciate any help.

Thank you in advance,

Val

This is an another attempt to solve the challenge


Dim t As TextInputStream
Dim f As FolderItem
Dim dlg As OpenDialog
Dim s As String
Dim last As Integer
Dim i As Integer


dlg = New OpenDialog

f = dlg.ShowModal() // open open dialog for selecting a file to load

if f<> nil then
  t = f.OpenAsTextFile // open selected text file
  s = t.ReadAll
  //ComboBox1.InitialValue = t.ReadAll
else
  //user cancelled
end
//ComboBox1.InitialValue=str(s)

For i = 1 To last
  Window1.ComboBox1.AddRow(NthField(s, ",",i))
Next

Return True

It does not work too. I am not sure why.

This is the next attempt.

A text file is read into the TextArea2. I try to pass info from that TextArea into the ComboBox


Dim t As TextInputStream
Dim f As FolderItem
Dim dlg As OpenDialog
Dim s As String
Dim last As Integer
Dim i As Integer
Var stream As BinaryStream



dlg = New OpenDialog

f = dlg.ShowModal() // open open dialog for selecting a file to load
If f <> Nil Then
  stream = BinaryStream.Open(f, False)
  Do
    TextArea2.AddText(stream.Read(1000, Encodings.UTF8))
  Loop Until stream.EndOfFile
  stream.Close
End If


last = CountFields(TextArea2.Text, ",")

for i As Integer = 1 to last
  Window1.ComboBox1.AddRow(NthFields(TextArea2.Text, "," , i))
next

Return True

This line is having a problem


Window1.ComboBox1.AddRow(NthFields(TextArea2.Text, "," , i))

Finally, this code work with the text file that has entries separated with comas.


Dim t As TextInputStream
Dim f As FolderItem
Dim dlg As OpenDialog
Var s As String
Var last As Integer
Var stream As BinaryStream



dlg = New OpenDialog

f = dlg.ShowModal() // open open dialog for selecting a file to load
If f <> Nil Then
  stream = BinaryStream.Open(f, False)
  Do
    Window1.TextArea2.AddText(stream.Read(1000, Encodings.UTF8))
  Loop Until stream.EndOfFile
  stream.Close
End If

s=Window1.TextArea2.Text



last = CountFields(Window1.TextArea2.Text, ",")

for i As Integer = 1 to last
  Window1.ComboBox1.AddRow(NthField(s, "," , i))
next

Return True