landon998
09-13-2000, 01:56 PM
Does anyone have any sample code to create a Random Access File? And it needs to be an 'Append' method so the previous data is not overwritten. Thanks!
Random Access Filelandon998 09-13-2000, 01:56 PM Does anyone have any sample code to create a Random Access File? And it needs to be an 'Append' method so the previous data is not overwritten. Thanks! Q... 09-14-2000, 10:53 PM Although this says it's for Excel it is the same for Visual Basic. Do not, however, open any files as #1. To obtain the lowest file number that is not being used, dimension an integer eg. intFileNum as integer Then set it to the retval of the FreeFile function. ie. intFileNum = FreeFile Then you should open you file as #intFileNum http://support.microsoft.com/support/kb/articles/Q151/2/62.asp Helmar 09-15-2000, 11:02 AM Assume the following Type in a module: Type MyData Field1 As String * 25 Field2 As Integer Field3 As String * 10 End Type Use the following code to append to the file: Dim NumberOfRecords As Long Dim aRecord As TestDat Dim FileNumber As Integer Const FileName As String = "C:aaaaTempTest.DAT" FileNumber = FreeFile Open FileName For Random As #FileNumber Len = Len(aRecord) NumberOfRecords = LOF(FileNumber) / Len(aRecord) MsgBox NumberOfRecords & " records." aRecord.Var1 = "11111111" aRecord.Var2 = 2 aRecord.Var3 = "33333333" Put #FileNumber, NumberOfRecords + 1, aRecord Close Helmar B. Herman, VP ProtoProducts |
EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum