|
-
Nov 15th, 2000, 10:18 PM
#1
Thread Starter
New Member
I am making a program that stores patient info.
when the app is shut down, i need to save the info of three list boxes in a text file.
when the app is loaded i need that info loaded back into their respective list boxes.
please help
i have no clue as how to do it oles? databases
-
Nov 15th, 2000, 10:47 PM
#2
Hyperactive Member
one way to accomplish your task is to use sequential files
i'm not really good at it but i can give u a rough start
say u wanted the words "my text file is very little" stored in a text file ... you would then go about it like:
dim thestring as string
open "c:\test1.txt" for output as #1
print thestring
close #1
what that will do is make a text file called test1.txt and store that thestring in it
now to retrieve that from that text file you would do:
dim thestoredstring as string
open "c:\test1.txt" for input as #1
line input thestoredstring
print thestoredstring
close#1
that will retrieve what you stored in the previous example to the new string called thestoredstring
now in order for you to do that with listboxes
you have to make loops to get every iten in the listboxes and save them
and you would also have to do a loop to retrieve them and add them to the listboxes
the loop would be a while loop checking for the end of file(eof) so it can stop
-
Nov 15th, 2000, 10:51 PM
#3
A database would probably be your best option. But because I am not familiar with Database programming, I just use text files to store information.
Here's a piece which may get you started on text files:
Code:
Private Sub Form_Unload()
Open "C:\listfile1.txt" For Output As #1
For X = 0 To ListBox1.Count - 1
Print #1, ListBox1.List(X)
Next X
Close #1
Open "C:\listfile2.txt" For Output As #1
For X = 0 To ListBox2.Count - 1
Print #1, ListBox2.List(X)
Next X
Close #1
Open "C:\listfile3.txt" For Output As #1
For X = 0 To ListBox3.Count - 1
Print #1, ListBox3.List(X)
Next X
Close #1
End Sub
' And for the Opening
Private Sub Form_Load()
Dim strString As String
On Error GoTo FixIt
Open "C:\listfile1.txt" For Input As #1
Do While Not EOF(1)
Input #1, strString
ListBox1.AddItem strString
Loop
Close #1
Open "C:\listfile2.txt" For Input As #1
Do While Not EOF(1)
Input #1, strString
ListBox2.AddItem strString
Loop
Close #1
Open "C:\listfile2.txt" For Input As #1
Do While Not EOF(1)
Input #1, strString
ListBox2.AddItem strString
Loop
Close #1
Exit Sub
FixIt:
Open "C:\listfile1.txt" For Output As #1
Close #1
Open "C:\listfile2.txt" For Output As #1
Close #1
Open "C:\listfile3.txt" For Output As #1
Close #1
End Sub
Of course there is a more efficient way than that. I was just lazy so I did the old cut 'n' paste, or in this case copy 'n' paste.
-
Jan 10th, 2001, 02:32 AM
#4
Junior Member
You could also do this using a .ini file with a lot fewer lines of code. read up on them.
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
|