PDA

Click to See Complete Forum and Search --> : Random File Access DB


jtparkhu
May 5th, 2002, 05:10 AM
I am still new to Visual Basic but I am trying to learn how to work with random file access to use for my database in my sports simulator. I'm just trying to do the basics right now and I'm having trouble. I have a module that includes my user define structure and then my form with 3 text boxes where the data comes from. I receive a "Bad record length" error when i hit the Create command. Below is my code:

modDatabase:
Public fHnd As Integer
Public numRecs As Long

Public LeagueDB As LeagueData
Structure LeagueData
Public LFullName As String
Public LAbrevName As String
Public LStartingYear As String
Public LDivisions() As String
Public LConferences() As String
End Structure

frmNewLeague:
Private LeagueName As String
Private Sub cmdCreate_Click()
ReDim LeagueDB.LDivisions(3)
LeagueName = txtLeagueName.Text
numRecs = Len(LeagueDB)
fHnd = FreeFile
FileOpen(fHnd, "C:\TUHS\" & LeagueName & ".lge", OpenMode.Random, , , numRecs)
numRecs = LOF(fHnd) \ numRecs
numRecs = numRecs + 1

LeagueDB.LAbrevName = txtLeagueName.Text
LeagueDB.LStartingYear = txtStartingYear.Text
LeagueDB.LDivisions(0) = txtDivision1.Text

FilePut(fHnd, LeagueDB, numRecs)

End Sub

If anyone can help me with this, it would be great, because I just can't figure it out. Thanks a lot in advance!

James