Kiwi Ranger

Hello,

I need to know how to read multiple lines from a text file and and put them each into different comboboxes and also how do I put a text file into a list box and have each line as an option

Thanks for your help



Re: Visual Basic Express Edition A little help with text files...

Syed Fasih

Hello
Please let us know the structure of the file you want to use to load in Drop downs

Thanks








Re: Visual Basic Express Edition A little help with text files...

Andrew DeVaughn

This code assumes that there is a rich Text Box(RichTextBox1) and a menu(Menu1)

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim rct As String

Menu1.Items.Clear()

For Each rct In RichTextBox1.Lines

Menu1.Items.Add(rct)

Next

End Sub






Re: Visual Basic Express Edition A little help with text files...

Kiwi Ranger

Its just like this

 

--------textfile------< xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

beef

flour

water

 

So just one or two words a line and I want to be able to show the whole text file in a list box, and have each line as an option. Also its the same for the combobox, i want each line from the textfile to be a option\

 

Sorry if I am not making it clear :)

 





Re: Visual Basic Express Edition A little help with text files...

Lars Breiter

Try this, it should work:

'For the Comboboxes use this:

Dim str() As String
Dim s As String
Dim x As Integer = 0
Dim sr As System.IO.StreamReader = New IO.StreamReader([PathToFile])

s = sr.ReadLine

While IsNothing(s) = False
ReDim Preserve str(x)
str(x) = s
s = sr.ReadLine
x += 1
End While
sr.Close()

'Add Element to each Combobox
ComboBox1.Items.Add(str(0))
ComboBox2.Items.add(str(1))

'For Textbox:
Dim srT As System.IO.StreamReader = New IO.StreamReader([PathToFile])
txtText.text = srT.ReadToEnd





Re: Visual Basic Express Edition A little help with text files...

Kiwi Ranger

Cool thanks for your help :-)