How would I go about loading a text file, or an ini file into a listbox? I cant figure it out.
Printable View
How would I go about loading a text file, or an ini file into a listbox? I cant figure it out.
Code:Public Sub List_Load(TheList As Listbox, FileName As String)
On Error Resume Next
Dim TheContents As String
Dim fFile As Integer
fFile = FreeFile
Open FileName For Input As fFile
Do
Line Input #fFile, TheContents$
TheList.Additem TheContents$
Loop Until EOF(fFile)
Close fFile
End Sub
'Usage:
Call List_Load(List1, "C:\MyFile.txt")
Thanks matt.. just what i needed. :)
Try,
Dim Inputfile As String
Dim InputRec As String
Open InputFile For Input As #1
Do While Not EOF(1)
DoEvents
Line Input #1, IputRec
list1.Additem InputRec
Loop
Close #1
Regards
ahh, sorry tio didnt see your post, but thanks.
sorry to bug you again ..
but what would i need to do to save the file with the data in the listbox?
[Edited by Stephen Bazemore on 10-08-2000 at 01:21 AM]
Matthew ,
Sorry For My poor sample, I didnt know that you r already answer, Your Sample Is The Best ONE!!!.
Btw, How can i used COLOR in the VB-World Form?
Best Regards
Tio
If your talking about how to add color to your code follow this link http://forums.vb-world.net/index.php?action=bbcode and it will tell you exactly how.
You mean code tags?
[code]Your code[/code]
For more, check out the link above.
This function:Quote:
Originally posted by Stephen Bazemore
But what would i need to do to save the file with the data in the listbox?
Usage:Code:Public Sub List_Save(TheList As ListBox, FileName As String)
On Error Resume Next
Dim TheContents As String
Dim fFile As Integer
fFile = FreeFile
'this functions overwrites the file
'so it deletes the file first if it's already there
If Dir$(FileName) <> "" Then
'delete the file
Kill FileName
End If
Open FileName For Output As fFile
For i = 0 To (TheList.ListCount - 1)
Print #1, TheList.List(i)
Next
Close fFile
End Sub
Code:Call List_Save(List1, "C:\MyFile.txt")
Quote:
Originally posted by oetje
This function:Quote:
Originally posted by Stephen Bazemore
But what would i need to do to save the file with the data in the listbox?
Usage:Code:Public Sub List_Save(TheList As ListBox, FileName As String)
On Error Resume Next
Dim TheContents As String
Dim fFile As Integer
fFile = FreeFile
'this functions overwrites the file
'so it deletes the file first if it's already there
If Dir$(FileName) <> "" Then
'delete the file
Kill FileName
End If
Open FileName For Output As fFile
For i = 0 To (TheList.ListCount - 1)
Print #1, TheList.List(i)
Next
Close fFile
End Sub
Code:Call List_Save(List1, "C:\MyFile.txt")
Oops, didn't see that. And you don't really need this part:
The reason being is that the Output will automatically overwrite the file no matter what.Code:If Dir$(FileName) <> "" Then
'delete the file
Kill FileName
End If
Code:Public Sub List_Save(TheList As ListBox, FileName As String)
On Error Resume Next
Dim Save As Long
Dim fFile As Integer
fFile = FreeFile
Open FileName For Output As fFile
For Save = 0 To TheList.ListCount - 1
Print #fFile, TheList.List(Save)
Next Save
Close fFile
End Sub
I thought that if the file looked like this:Quote:
Originally posted by Matthew Gates
The reason being is that the Output will automatically overwrite the file no matter what.
a
b
g
h
i
And then I wrote 3 lines it will look like this:
1
2
3
h
i
No. In keeping with the standard method, Output truncates the file, then begins writing from the beginning. Append opens the file, seeks to the end, and writes from there.
Thanks for all your help guys. I appreciate it alot.
Hi,
Thnaks For The Info....
Regards
Hi,
How can i used COLOR in the VB-World Forum? not in html form - somthing like your sample - with a few COLOR?
Regards
You mean code tags?
[code]your code[/code]
Easy, eh? :rolleyes:
Matthew, Thanks.
You Are My Hero!!!
Best Regards