473,382 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Reading information from .dat files

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:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdCreate_Click()
  2.     Open "c:\users\brian\Documents\School\CPT 323\friends.dat" For Output As #1
  3.     Write #1, 1, "phone number", "first name", "last name"
  4.     Write #1, 2, "111-111-1111", "Michael", "Massey"
  5.     Write #1, 3, "222-222-2222", "Brian", "Tjarks"
  6.     Write #1, 4, "333-333-3333", "George", "Fuller"
  7.     Close 1    
  8. End Sub
  9.  
  10. Private Sub cmdRead_Click()
  11.     Dim phoneNumber As String
  12.     Dim firstName As String
  13.     Dim lastName As String    
  14.     Open "friends.dat" For Input As #1    
  15.     Do Until EOF(1)
  16.         Input #1, phoneNumber, firstName, lastName
  17.         lstFriends.AddItem "phoneNumber " & _
  18.         "firstName " & "lastName"
  19.     Loop    
  20.     Close 1       
  21. End Sub
  22.  
Mar 5 '10 #1

✓ answered by ADezii

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:
Expand|Select|Wrap|Line Numbers
  1. Open "c:\users\brian\Documents\School\CPT 323\friends.dat" For Output As #1
  2.  
  3. Write #1, 1, "phone number", "first name", "last name"
  4. Write #1, 2, "111-111-1111", "Michael", "Massey"
  5. Write #1, 3, "222-222-2222", "Brian", "Tjarks"
  6. Write #1, 4, "333-333-3333", "George", "Fuller"
  7.  
  8. Close #1
Expand|Select|Wrap|Line Numbers
  1. Dim SequenceNumber As Long
  2. Dim phoneNumber As String
  3. Dim firstName As String
  4. Dim lastName As String
  5.  
  6. With Me![lstFriends]
  7.   .RowSourceType = "Value List"
  8.   .ColumnCount = 4
  9.   .ColumnWidths = ".25 in;;;"
  10. End With
  11.  
  12. Me![lstFriends].RowSourceType = "Value List"
  13. Me![lstFriends].ColumnCount = 4
  14.  
  15. Open "c:\users\brian\Documents\School\CPT 323\friends.dat" For Input As #1
  16.  
  17. Do While Not EOF(1)
  18.  Input #1, SequenceNumber, phoneNumber, firstName, lastName
  19.    lstFriends.AddItem SequenceNumber & ";" & phoneNumber & ";" & firstName & ";" & lastName
  20. Loop
  21.  
  22. Close #1

5 5555
missinglinq
3,532 Expert 2GB
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)>
Mar 5 '10 #2
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 :)
Mar 5 '10 #3
ADezii
8,834 Expert 8TB
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:
Expand|Select|Wrap|Line Numbers
  1. Open "c:\users\brian\Documents\School\CPT 323\friends.dat" For Output As #1
  2.  
  3. Write #1, 1, "phone number", "first name", "last name"
  4. Write #1, 2, "111-111-1111", "Michael", "Massey"
  5. Write #1, 3, "222-222-2222", "Brian", "Tjarks"
  6. Write #1, 4, "333-333-3333", "George", "Fuller"
  7.  
  8. Close #1
Expand|Select|Wrap|Line Numbers
  1. Dim SequenceNumber As Long
  2. Dim phoneNumber As String
  3. Dim firstName As String
  4. Dim lastName As String
  5.  
  6. With Me![lstFriends]
  7.   .RowSourceType = "Value List"
  8.   .ColumnCount = 4
  9.   .ColumnWidths = ".25 in;;;"
  10. End With
  11.  
  12. Me![lstFriends].RowSourceType = "Value List"
  13. Me![lstFriends].ColumnCount = 4
  14.  
  15. Open "c:\users\brian\Documents\School\CPT 323\friends.dat" For Input As #1
  16.  
  17. Do While Not EOF(1)
  18.  Input #1, SequenceNumber, phoneNumber, firstName, lastName
  19.    lstFriends.AddItem SequenceNumber & ";" & phoneNumber & ";" & firstName & ";" & lastName
  20. Loop
  21.  
  22. Close #1
Mar 5 '10 #4
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!
Mar 6 '10 #5
ADezii
8,834 Expert 8TB
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).
Mar 6 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

7
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...
2
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...
14
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...
1
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,...
23
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...
7
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...
7
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...
2
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
8
namcintosh
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...
21
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() {...
1
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...
0
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...
0
isladogs
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...
0
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...
0
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,...
0
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...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.