Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » Registry & File Input / Output

Post new topic   Reply to topic
Still Need Help Saving/Loading an Array
View previous topic :: View next topic  
Author Message
Tony Walker
Newbie


Joined: 18 Mar 2005
Posts: 17

PostPosted: Mar 21st, 2005 02:35 PM    Post subject: Still Need Help Saving/Loading an Array Reply with quote

I need the complete code for Visual BASIC that does the following.

Here's what I have.

Dim MyName (1 to 3) As String


MyName(1) = "A"
MyName(2) = "B"
MyName(3) = "C"

Now I need the code for Command1 so it saves the array to a file called "C:\Test.tst".
Then I need the code for Command2 to open the file and from there I can assign the values to a ListBox like this...

For i = 1 to 3
List1.AddItem (MyName(i))
Next i
Back to top
View user's profile Send private message Send e-mail
RoofRabbit
Regular


Joined: 06 Jul 2005
Posts: 95
Location: Lenoir, NC USA

PostPosted: Jul 6th, 2005 11:10 PM    Post subject: Reply with quote

This would save and load the array, you can do as you wish with the array after it's loaded. Of course, you'll have to set the filename value in SomeFileName to something.
Code:

Dim MyName(2) As String 'indexes from 0 to 2 by default

Sub SaveTextArray()
    Dim ch As Integer
    Dim i As Integer
    ch = FreeFile
    Open SomeFileName For Input As ch
    For i = 0 To 2
        Print #ch, MyName(i)
    Next i
    Close #ch
End Sub

Sub LoadTextArray()
    Dim ch As Integer
    Dim i As Integer
    ch = FreeFile
    Open SomeFileName For Input As ch
    For i = 0 To 2
        Line Input #ch, MyName(i)
    Next i
    Close #ch
End Sub

_________________
Website - [link]
Back to top
View user's profile Send private message Visit poster's website ICQ Number
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » Registry & File Input / Output All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic