Input # write to array problem

I am writing several arrays to a comma-delimited text file, and that is working fine.  However, I realize one cannot use Input # to read that info back into those arrays.  Does anybody have any nifty tricks to read such a file so that I can re-populate the same arrays the file was written from?  Thanks.
--Vingamel

Open "JARNATH_SAVE" For Output As #1   ' Open file for output.
       
        NumberofPassengerTypes,
        For iY = 0 To 3599
            Write #1, MapTiles(3, iY),
        Next iY
LVL 1
VingamelAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Erick37Commented:
Try this:

Dim vA
Dim temp
Dim i As Integer
vA = Array("one", "two", "three", "four", "five")
Dim ff As Integer

ff = FreeFile
Open "c:\test.dat" For Output As #ff
For i = 0 To UBound(vA)
    Write #ff, vA(i);
Next
Close #ff

ff = FreeFile
Open "c:\test.dat" For Input As #ff
Do While Not EOF(ff)
    Input #ff, temp
    Debug.Print temp
Loop
Close #ff
VingamelAuthor Commented:
When trying to write the way you prescribe, I get a type mismatch error on
Write #ff, vA(iY);

I changed your code for my own project as follows...
Dim vA
Dim temp
Dim iY as Integer
Dim ff As Integer

For iY = 0 To 3599
    vA = MapTiles(3, 3599)
Next iY

ff = FreeFile
 
Open "JARNATH_SAVE" For Output As #ff   ' Open file for output.
       
   For iY = 0 To 3599
       Write #ff, vA(iY);
        Next iY
Close #ff
Éric MoreauSenior .Net ConsultantCommented:
To make an array with what you just read, use the SPLIT function.

vA = split(temp,",")
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

VingamelAuthor Commented:
vA = split(temp,",")?  How do my MapTiles(3,3599) array elements get into vA with that code?  Can you explain further?
VingamelAuthor Commented:
This does not work, emoreau...I am not certain how vA = Split(temp, ",") gets the elements of Maptiles(3, iY) into vA...  He'p me He'p me :o)

Dim vA
Dim temp
Dim ff As Integer
vA = Split(temp, ",")
For iY = 0 To 3599
    vA = MapTiles(3, iY)
Next iY


ff = FreeFile
   
Open "JARNATH_SAVE" For Output As #ff   ' Open file for output.
   For iY = 0 To 3599
     Write #ff, vA(iY);
   Next iY
VingamelAuthor Commented:
This does not work, emoreau...I am not certain how vA = Split(temp, ",") gets the elements of Maptiles(3, iY) into vA...  He'p me He'p me :o)

Dim vA
Dim temp
Dim ff As Integer
vA = Split(temp, ",")
For iY = 0 To 3599
    vA = MapTiles(3, iY)
Next iY


ff = FreeFile
   
Open "JARNATH_SAVE" For Output As #ff   ' Open file for output.
   For iY = 0 To 3599
     Write #ff, vA(iY);
   Next iY
VingamelAuthor Commented:
I am not rejecting any answer because it is wrong...just opening the question up for all to answer.  The answer provided does not work yet....
Thanks!
--Vingamel
Éric MoreauSenior .Net ConsultantCommented:
You said that your problem is to read?

Try something like this:
ff = FreeFile
Open "c:\test.dat" For Input As #ff
i = 0
Do While Not EOF(ff)
    Line Input #ff, temp
    MapTiles(3,i) = temp
    i = i + 1
Loop
Close #ff

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
VingamelAuthor Commented:
I am not rejecting any answer because it is wrong...just opening the question up for all to answer.  The answer provided does not work yet....
Thanks!
--Vingamel
kfrickCommented:
Try this:

Sub ReadMapFile()
Dim Index As Integer
Dim FileNum As Integer
Dim szTemp As String
Dim szChar As String * 1
    FileNum = FreeFile
    Index = 0   '(or -1, depending on your Option Base setting)
    Open "JARNATH_SAVE" For Input As #FileNum
    While Not EOF(FileNum)
        Input #FileNum, szChar 'read 1 character
        If szChar <> "," Then
            szTemp = szTemp + szChar
        Else
            Index = Index + 1
            MapTiles(3, Index) = szTemp
            szTemp = ""
        End If
    Wend
    Close #FileNum
End Sub


FYI:
If you change your output file routine to create a file in a list format rather that a Comma Delimited format, the read-back sub will be easier, because the Input# command will just read one record at a time. Then you won't have to test each character for a comma!

Change:
    Write #1, (stuff)
to:
    Print #1, (stuff)

then use:
Sub ReadMapFile()
Dim Index As Integer
Dim FileNum As Integer
Dim szTemp As String
    FileNum = FreeFile
    Open "JARNATH_SAVE" For Input As #FileNum
    For Index = 0 To 3599
        Input #FileNum, MapTiles(3, Index)
    Next
    Close #FileNum
End Sub

good luck!
-kf
VingamelAuthor Commented:
I am not rejecting any answer because it is wrong...just opening the question up for all to answer.  The answer provided does not work yet....
Thanks!
--Vingamel
VingamelAuthor Commented:
This worked!  Thank you, and to all others who helped.  Visit my site at www.jarnath.freeservers.com if you are interested in strategy games.  Here is what I did with emoreau's code, which populated maparray() with the correct information when it does the Input #:

Option Explicit
Dim maptiles(3, 3599)
Dim ff As Integer
Dim i As Integer
Dim temp
   

Private Sub Command1_Click()

For i = 0 To 3599
    maptiles(3, i) = 0
Next i
ff = FreeFile

Open "JARNATH_SAVE" For Output As #1   ' Open file for output.
               
        For i = 0 To 3599
            Write #1, maptiles(3, i),
        Next i
Close #ff

End Sub

Private Sub Command2_Click()
    Open "JARNATH_SAVE" For Input As #ff
i = 0
Do While Not EOF(ff)
    Line Input #ff, temp
    maptiles(3, i) = temp
    i = i + 1
Loop
Close #ff

End Sub
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.