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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding items held in dynamic array to file

Status
Not open for further replies.

Oxymoron

Technical User
Dec 17, 2000
168
GB
hey I have a dynamic array which holds records, which is fine for viewing records(previous and next) when data has been added - but when the program is closed and restarted all the data is (of course) lost from the array.
I want to therefor add the data added to a file as soon as it's submitted.
my:
put #FilNo, lastrec, RecordArray(lastrec)
does not work...what am i doing wrong?
here's my code if u want more information
all suggestions are VERY welcome and appreciated!
cheers
JoE
---------------module-----------
Option Explicit

Public Type tStorage
Type As String * 30
Date As Date
FromTo As String * 20
Quantity As Integer
JobNum As Integer
EmpNum As Integer
RecSent As Boolean
End Type

Public Record As tStorage
Public RecLen As Integer
Public CurrentRec As Integer
Public LastRec As Integer
Public FileNo As Integer
Public RecordArray() As tStorage

------------------form-------------
Public Sub cmdSubmit_Click()
LastRec = LastRec + 1
Dim i As Integer
i = LastRec
ReDim Preserve RecordArray(i)
RecordArray(i).Date = txtDate.Text
RecordArray(i).EmpNum = txtEmpNum.Text
RecordArray(i).FromTo = txtFromTo.Text
RecordArray(i).JobNum = txtJobNum.Text
RecordArray(i).Quantity = txtQuant.Text
RecordArray(i).Type = cmbType.Text
Call Adder
MsgBox "Record Added!", vbExclamation + vbOKOnly
Call Clear
End Sub

Public Sub Adder()
Put FileNo, LastRec, RecordArray(LastRec)
End Sub

Private Sub Form_Load()
Dim i As Integer
FileNo = FreeFile
RecLen = Len(Record)
Open App.Path & "\storage.dat" For Random As FileNo Len = RecLen
LastRec = LOF(FileNo) / RecLen
ReDim RecordArray(LastRec)
For i = 1 To LastRec
Get #FileNo, i, RecordArray(i)
Next
Close FileNo
End Sub

Private Sub View()
txtDate.Text = RecordArray(CurrentRec).Date
txtEmpNum.Text = RecordArray(CurrentRec).EmpNum
txtFromTo.Text = RecordArray(CurrentRec).FromTo
txtJobNum.Text = RecordArray(CurrentRec).JobNum
txtQuant.Text = RecordArray(CurrentRec).Quantity
cmbType.Text = RecordArray(CurrentRec).Type
End Sub
 
You are closing your file in the load(). Your file is closed when you try to update it in Adder. Tim

Remember the KISS principle:
Keep It Simple, Stupid! :cool:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top