|
-
Oct 7th, 2000, 11:59 PM
#1
Thread Starter
Addicted Member
How would I go about loading a text file, or an ini file into a listbox? I cant figure it out.
-
Oct 8th, 2000, 12:07 AM
#2
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")
-
Oct 8th, 2000, 12:11 AM
#3
Thread Starter
Addicted Member
Thanks matt.. just what i needed.
-
Oct 8th, 2000, 12:18 AM
#4
Addicted Member
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
-
Oct 8th, 2000, 12:18 AM
#5
Thread Starter
Addicted Member
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]
-
Oct 8th, 2000, 12:23 AM
#6
Addicted Member
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
-
Oct 8th, 2000, 12:29 AM
#7
Thread Starter
Addicted Member
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.
-
Oct 8th, 2000, 12:51 AM
#8
You mean code tags?
[code]Your code[/code]
For more, check out the link above.
-
Oct 8th, 2000, 03:24 AM
#9
Fanatic Member
Originally posted by Stephen Bazemore
But what would i need to do to save the file with the data in the listbox?
This function:
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
Usage:
Code:
Call List_Save(List1, "C:\MyFile.txt")
-
Oct 8th, 2000, 03:47 AM
#10
Originally posted by oetje
Originally posted by Stephen Bazemore
But what would i need to do to save the file with the data in the listbox?
This function:
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
Usage:
Code:
Call List_Save(List1, "C:\MyFile.txt")
Oops, didn't see that. And you don't really need this part:
Code:
If Dir$(FileName) <> "" Then
'delete the file
Kill FileName
End If
The reason being is that the Output will automatically overwrite the file no matter what.
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
-
Oct 8th, 2000, 04:28 AM
#11
Fanatic Member
Originally posted by Matthew Gates
The reason being is that the Output will automatically overwrite the file no matter what.
I thought that if the file looked like this:
a
b
g
h
i
And then I wrote 3 lines it will look like this:
1
2
3
h
i
-
Oct 8th, 2000, 05:32 AM
#12
Monday Morning Lunatic
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.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Oct 8th, 2000, 09:42 AM
#13
Thread Starter
Addicted Member
Thanks for all your help guys. I appreciate it alot.
-
Oct 10th, 2000, 12:03 AM
#14
Addicted Member
Hi,
Thnaks For The Info....
Regards
-
Oct 10th, 2000, 12:11 AM
#15
Addicted Member
Hi,
How can i used COLOR in the VB-World Forum? not in html form - somthing like your sample - with a few COLOR?
Regards
-
Oct 10th, 2000, 06:22 AM
#16
You mean code tags?
[code]your code[/code]
Easy, eh?
-
Oct 10th, 2000, 07:17 AM
#17
Addicted Member
Matthew, Thanks.
You Are My Hero!!!
Best Regards
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|