Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

save arrays

Status
Not open for further replies.

philipad

Technical User
Feb 12, 2006
23
CY
hi

I have this programs that saves two arrays, tabletop(100) and tableleft(100). How can I save these arrays to be used by another program?


Dim tableLeft(100) As Integer
Dim tabletop(100) As Integer

Private Sub Command1_Click()
i = Val(Text3.Text)
tableLeft(i) = Val(Text1.Text)
tabletop(i) = Val(Text2.Text)
End Sub

Private Sub Command2_Click()
k = Val(Text4.Text)
Label1.Caption = tableLeft(k)
Label2.Caption = tabletop(k)

End Sub

Private Sub Image1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Text1.Text = X
Text2.Text = Y
End Sub
 
If you're talking about the within same app then just use a public variable rather than a local.

e.g.
'add to a main module
Public tableLeft(100) as integer

Then you have access to them throughout you code

Hope that helps.
 

How old are you? [smile]
Code:
Option Explicit

Type TableRecord
    tableLeft(100) As Integer
    tabletop(100) As Integer
End Type

Public Sub WriteData()
    Dim MyRecords As TableRecord
    Dim iFilenum    As Integer
    
    MyRecords.tableLeft(50) = 10
    MyRecords.tabletop(25) = 20
    
    iFilenum = FreeFile
    
    Open "x:\TableFile" For Binary Access Write As #iFilenum
    Put #iFilenum, 1, MyRecords
    Close #iFilenum
End Sub

Public Sub ReadData()
    Dim MyRecords As TableRecord
    Dim iFilenum    As Integer

    iFilenum = FreeFile
    
    Open "x:\TableFile" For Binary Access Read As #iFilenum
    Get #iFilenum, 1, MyRecords
    Close #iFilenum
End Sub

There are many other ways to do what you want.
You could use a two dimensional array instead of the User Defined TYPE:

Const tableLeft%=0
Const tableTop%=1
Dim MyRecords(1, 100) As Integer
MyRecords(tableLeft, 50) = 10
MyRecords(tableTop, 25) = 20
.
.
.
Put #iFilenum, 1, MyRecords

You could use Random File Access.

You could even use ADODB and create a local recordset (no Db) and save the values to two fields in 100 records and then save the records to XML (adPersistXML)

It depends on how much data you are storing and how fast to access it, as which methods are best and how to optimize it, and if you need to search/replace records easily. But for your need here, this is pretty cheap.
 
Do I have to create the file x:\TableFile or it is created by the code you wrote?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top