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!

Random Access Files

Status
Not open for further replies.

Stott40

Programmer
Nov 5, 2000
4
US
I am recieving an error 52 when i try to run my aplication. it is a simple application that prompts the user with an Input Box when it is fired up for the first time, meaning intCurrentRecNum = 0 I click Ok to get it going, that is when I recieve the error. After selecting Debug it takes me to the Put statement in the SaveRecordBuffer general procedure, I know this is a lengthy message but You must see the code and please tell where I am screwing up!Private Sub SaveRecordBuffer()
Dim i As Integer

With TBuffer
' .datDate = CDate(lblDate)

For i = 1 To 3
.lngProdShift(i) = Val(txtProdTons(i))
.lngRawMatsShift(i) = Val(txtOilCons(i))
If .lngProdShift(i) = 0 Then
lblRatio(i).Caption = "-"
Else
lblRatio(i).Caption = .lngRawMatsShift(i) / .lngProdShift(i)
End If

Next

End With
Put intFileNum, intCurrentRecNo, TBuffer
End Sub
 
You can't get or put a recordnumber of 0. Why is is program going though the Sub SaveRecordBuffer() on startup anyway?. You problem is somewhere else, not in this sub.

David Paulson


 
Ok , here is what I use for checking to see if the settings have been set at the start of a program, this is a less complex sample, but easy to understand, in a module I declare my user type rec, with a member called runtime as integer. Then dim recorddata as rec. Or whatever you would use. Heres the code


Code:
Private Sub Command1_Click()
Dim recordnum
recordnum = 1
Open "jkl.txt" For Random Access Read Write As #1
Get #1, recordnum, recorddata
On Error GoTo errortest
If recorddata.runtime = 0 Then
    MsgBox "Settings Dialog Box here"
    recorddata.runtime = 1
    Put #1, recordnum, recorddata
    Close #1
    Exit Sub
Else
    MsgBox "Settings are already set"
    Close #1
    Exit Sub
End If
errortest:
recorddata.runtime = 0
Put #1, recordnum, recorddata
Close #1
MsgBox "Record number 1 has been created"
End Sub


I put the error test line in there because I wasn't sure if it would create the file, and create and empty recorddata entry, which it did on my machine, I dont' know how you have yours set up so I left it in there. Anyways when you run the program for the first time it will bring a MsgBox up saying "Settings Dialog here", then when you close it and run it again you will see "Settings already set". Notice that I used record number 1, there is no record number 0. Remember that , that will give you lots of errors

Hope this helps you out

DarkMercenary
darkmercenary44@earthlink.net

In the real world
As in dreams
Nothing is quite
What it seems
:Book of Counted Sorrows
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top