hello,
does anyone know how to load different lines from a file into different textboxes eg. line1 from a textfile goes into text1.text, line 2 from a file goes into text2.text and so on
thanks
Printable View
hello,
does anyone know how to load different lines from a file into different textboxes eg. line1 from a textfile goes into text1.text, line 2 from a file goes into text2.text and so on
thanks
Well it depends on how many TextBoxes you have.
VB Code:
Dim FileIn As String Open "C:\Your.txt" For Input As #1 ' Open file for input. Line Input #1, FileIn ' Read line of data. Text1.Text = FileIn Line Input #1, FileIn ' Read line of data. Text2.Text = FileIn Line Input #1, FileIn ' Read line of data. Text3.Text = FileIn Close #1 ' Close file.
another way..
VB Code:
Dim tmp() As String Open "C:\File.txt" For Input As #1 tmp() = Split(Input(LOF(1), 1), vbCrLf) Close #1 'each line of the file is now in the array tmp() Text1 = tmp(0) Text2 = tmp(1) Text3 = tmp(2) 'etc... 'or even better 'Create an array of textboxes 'Make a new textbox.. call it txtData 'now copy & paste it back on the form.. it will ask if you want an array 'yes.. paste as many more as you need.. For x = 0 To txtData.Count - 1 txtData(x) = tmp(0) Next
thanks guys
i'll use statics one as it is shorter