?
Solved

Writing and reading arrays to file

Posted on 2003-02-24
9
Medium Priority
?
150 Views
Last Modified: 2010-05-01
I am pretty new to visual basic. I have a program where i am making a two dimensional array, and i want to write it to a file and then later read it from a file to use in the program.  how do i write the array to a file (it is just a 2-dimensional array of strings) and then later read it back in.  also, how can i use a file box to choose what file i want to save it to, so more than one file can be used in the program?  thanks

.pb
0
Comment
Question by:philburger
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +2
9 Comments
 
LVL 14

Expert Comment

by:Esopo
ID: 8013058
You want a CommonDialog control for choosing the file.

Put a textbox, a button and a CommonDialog in your form.

Add this code to your button:

CommonDialog1.showopen
Text1.Text = CommonDialog1.Filename

You should get the picture.

***About the array:***

To keep it simple, I suggest you save to a text file, with something like this:

***************
open "file.txt" for output as #1
   for j=0 to ubound(Array1)
      print #1, Array1(j,1)
      print #1, Array1(j,2)
   next j
close #1
***************

This will put your two dimensional array (Array1 in this case) into a text file, to read from the file you could use something like this:

***************
open "file.txt" for input as #1
   for j=0 to ubound(Array1)
      line input #1, Array1(j,1)
      line input #1, Array1(j,2)
   next j
close #1
***************


... you get the point. If you have trouble with any of this or are not familiar with the code, you should check the documentation.

I'm not sure about the syntax, hope this works.

Best regards.
0
 
LVL 1

Expert Comment

by:jangeador
ID: 8013088
homework questions should be worth more points
0
 

Author Comment

by:philburger
ID: 8013104
thanks, this was not a homework question. i was really just wondeirng.  but what is ubound? i understand what it SHOULD do, but it did not.   weird.......
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 14

Accepted Solution

by:
Esopo earned 80 total points
ID: 8013275
Ubound is used to retreive the last position of the array, of course, if you know the end of it (wich you should) you could just use that number instead.

Regards.
0
 
LVL 1

Expert Comment

by:jangeador
ID: 8013908
For best programming practice use

LBound(Array1) To UBound(Array1)
0
 

Author Comment

by:philburger
ID: 8013930
thanks, i got it to work......i think
0
 

Expert Comment

by:CleanupPing
ID: 8901182
philburger:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
Experts: Post your closing recommendations!  Who deserves points here?
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 8972689
Moderator, my recommended disposition is:

    Accept Esopo's comment(s) as an answer.

DanRollins -- EE database cleanup volunteer
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month8 days, 1 hour left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question