how do i load a textfile into a listbox in a form?
Printable View
how do i load a textfile into a listbox in a form?
what you mean text file. like the whole thing or just the name of the text file? the whole text file would be better off in a text box unless you want to list each like as an item in the list box.
i would have to research as i am new but i would google file system movement and opening and closing files. i am sure vb has something similiar to filereader and filewriter in java or fopen and such. once yu open it the text file can be manipulated my reading it and doing what you want with it until EOF.
look for chr(13) and chr(10) to denote end line and such. i would look this up becausE IT IS USEFUL AND TELL YOU THE CODE BUT I AM NEEDING A SMOKE RIGHT NOW. IF I GET NBACK AND YOU WANT SOME MORE LET ME KNOW WHAT WITH THE TEXT FILE YOU WANT TO DO WITH A LISTBOX EXACTLY.
sorry if this doesn;t directly answer your question.
Tryvb Code:
Private Sub Command1_Click() Dim arrLines() As String Dim lngCount As Long Dim i As Long Open "c:\textfile.txt" For Input As #1 arrLines = Split(Input(LOF(1), #1), vbCrLf) Close #1 lngCount = UBound(arrLines) For i = 0 To lngCount List1.AddItem arrLines(i) Next End Sub