I am trying to create a form that writes a .dat file, and then another form that reads the file and outputs the fields into a list box. The creation seems to have gone fine, but reading the file seems to not work so much. Can anyone tell me what I'm doing wrong? Here's what I have so far: -
Private Sub cmdCreate_Click()
-
Open "c:\users\brian\Documents\School\CPT 323\friends.dat" For Output As #1
-
Write #1, 1, "phone number", "first name", "last name"
-
Write #1, 2, "111-111-1111", "Michael", "Massey"
-
Write #1, 3, "222-222-2222", "Brian", "Tjarks"
-
Write #1, 4, "333-333-3333", "George", "Fuller"
-
Close 1
-
End Sub
-
-
Private Sub cmdRead_Click()
-
Dim phoneNumber As String
-
Dim firstName As String
-
Dim lastName As String
-
Open "friends.dat" For Input As #1
-
Do Until EOF(1)
-
Input #1, phoneNumber, firstName, lastName
-
lstFriends.AddItem "phoneNumber " & _
-
"firstName " & "lastName"
-
Loop
-
Close 1
-
End Sub
-
You've made several mistakes, so hopefully this will be a learning experience for you. I'll simply Post the code and should you have any questions, feel free to ask: - Open "c:\users\brian\Documents\School\CPT 323\friends.dat" For Output As #1
-
-
Write #1, 1, "phone number", "first name", "last name"
-
Write #1, 2, "111-111-1111", "Michael", "Massey"
-
Write #1, 3, "222-222-2222", "Brian", "Tjarks"
-
Write #1, 4, "333-333-3333", "George", "Fuller"
-
-
Close #1
- Dim SequenceNumber As Long
-
Dim phoneNumber As String
-
Dim firstName As String
-
Dim lastName As String
-
-
With Me![lstFriends]
-
.RowSourceType = "Value List"
-
.ColumnCount = 4
-
.ColumnWidths = ".25 in;;;"
-
End With
-
-
Me![lstFriends].RowSourceType = "Value List"
-
Me![lstFriends].ColumnCount = 4
-
-
Open "c:\users\brian\Documents\School\CPT 323\friends.dat" For Input As #1
-
-
Do While Not EOF(1)
-
Input #1, SequenceNumber, phoneNumber, firstName, lastName
-
lstFriends.AddItem SequenceNumber & ";" & phoneNumber & ";" & firstName & ";" & lastName
-
Loop
-
-
Close #1
5 5555
Why in the world would you want to create an external data file instead of simply using a table to hold your data?
Linq ;0)>
I'm still learning to program, and the book I'm using is teaching about .dat files now. You're right that it doesn't seem like the best way, but I don't want to discount it without knowing what I'm discounting :)
You've made several mistakes, so hopefully this will be a learning experience for you. I'll simply Post the code and should you have any questions, feel free to ask: - Open "c:\users\brian\Documents\School\CPT 323\friends.dat" For Output As #1
-
-
Write #1, 1, "phone number", "first name", "last name"
-
Write #1, 2, "111-111-1111", "Michael", "Massey"
-
Write #1, 3, "222-222-2222", "Brian", "Tjarks"
-
Write #1, 4, "333-333-3333", "George", "Fuller"
-
-
Close #1
- Dim SequenceNumber As Long
-
Dim phoneNumber As String
-
Dim firstName As String
-
Dim lastName As String
-
-
With Me![lstFriends]
-
.RowSourceType = "Value List"
-
.ColumnCount = 4
-
.ColumnWidths = ".25 in;;;"
-
End With
-
-
Me![lstFriends].RowSourceType = "Value List"
-
Me![lstFriends].ColumnCount = 4
-
-
Open "c:\users\brian\Documents\School\CPT 323\friends.dat" For Input As #1
-
-
Do While Not EOF(1)
-
Input #1, SequenceNumber, phoneNumber, firstName, lastName
-
lstFriends.AddItem SequenceNumber & ";" & phoneNumber & ";" & firstName & ";" & lastName
-
Loop
-
-
Close #1
Thank you so much! The book we are using is very vague...and as you can see, I'm still not very good at this. I didn't even realize that the number in the write was a field, I assumed it was a place holder. Concerning your With block, can I set those things within the form design or do I have to write the code? I had set those things when building the form, and it seems to work, I'm just curious as to why you coded it instead.
Thanks again for your help!
The With..End With Block sets certain Properties of the List Box in Code, but you can also do this in the Properties Window for the List Box (manually).
Sign in to post your reply or Sign up for a free account.
Similar topics
by: John |
last post by:
I have over 5000 thumbnail pictures of size 5kb each. I would like to
able to load all 5000 pictures and view 50 per page using
mysql_data_seek(). I would like to know what are the advantages and...
|
by: dunnm |
last post by:
This is probably a more appropriate location to post this question. I
should have know that since I've found most of the other PHP/PDF
information contained in this group.
Here's my issue...I...
|
by: Peter Galfi |
last post by:
Hi!
I am looking for a library in Python that would read PDF files and I could extract information from the PDF with it. I have searched with google, but only found libraries that can be used to...
|
by: Joel Goldstick |
last post by:
I wanted to write a simple page to let me choose a directory and then list
the files in it. The end goal was to make an easy way to copy all the
file names in a directory. I tested with Opera7,...
|
by: Graham F French |
last post by:
Hello,
I can read text files into my application, but I cannot read in msg files as
they seem to be in a proprietry format.
Is there anyway of converting it on the fly or is there an...
|
by: John Dann |
last post by:
I'm trying to read some binary data from a file created by another
program. I know the binary file format but can't change or control the
format. The binary data is organised such that it should...
|
by: Dmitry Akselrod |
last post by:
Hello everyone,
I am attempting to extract some header information from typical Microsoft
Outlook MSG files in VB.NET. I am not after a complete message or
attachments that may be enclosed. I...
|
by: Wes Peters |
last post by:
Does anyone know of an article that deals with the subject of reading a
structured text file using VBA code in Access?
Thanks,
Wes
|
by: namcintosh |
last post by:
I really need some help.
I am trying to read some information from a file in C++. Here is the program that I wrote. (Beware, I am very new to this, so don't freak out if the program seems a...
|
by: Naya |
last post by:
Hello, everyone!!!
Well, I have a situation here. I am trying to read this data from a
file, but the wrong values keep spitting out at me. Here's what I
mean:
Program:
int main()
{...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
| |