I find myself pulling out hair over an update I am doing. I have a typed record/structure that is used to store information into individual vehicle files in Virtual Dyno. I use the randomaccessfile object to do this. It has always worked flawlessly until this update.
I have had to add to the record/structure stored to the card, so I did just like I have thousands of time before. I renamed the old structure and used a copy of it to add the new fields. The structures are below.
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
   
Yes they are largish, but they serve my purpose. The new update needs to be able to read the old format (oldvdrecord) to convert existing filles. The problem is that it doesn't do that. It writes/reads the new structure just fine, but it refuses to read the old structure. Here are the read routines.
	
	
	
	
	
	
	
		
			
			
			
			
			
		
	
	
	
		
	
	
		
	
vrec is the new structure (vdrecord) and oldvrec is the old structure (oldvdrecord). If the loadfile routine fails, it calls the loadoldfile sub and tries loading it as the old format before displaying an error. Now I know the old record works. It was lifted from running code. In fact, I can run the earlier version and it loads the old files flawlessly. So why can't I get this to work? 
I am getting a "(IllegalArgumentException) java.lang.IllegalArgumentException: invalid value for field" in the log entry in the loadoldfile routine.
Even doing a oldvrec.spress= ovfile.readint(0) returns 641 instead of 70 (spress is the first field in the structure and is an integer). I have looked at this until I am blind, and I don't see the problem. Keep in mind that the old version still compiles, runs, reads, and writes just fine using the old structure. This "should" be a simple deal.
I'll entertain any ideas at this point. A .vdf file is attached so you can play with the old format file.
Thanks,
--- Jem
Missing Link Software
			
			I have had to add to the record/structure stored to the card, so I did just like I have thousands of time before. I renamed the old structure and used a copy of it to add the new fields. The structures are below.
			
				B4X:
			
		
		
		Type vdrecord(metric As Boolean, spress, icenter, ecenter, idur, edur, weight As Short, ilift, elift As Double, head, _
   extype As Byte, vtech As Boolean, fueltyp, no2, ecm, posi, susptype, tire, itype, ltype, boost, trans As Byte, _
   dish, ccv, twidth, rock, hgv, idia, edia, ratio, bore, stroke, radius, p2d As Double, cyl, rod, ign, bal, _
   blower As Byte, blowcfm As Short, vcyl As Byte, rodlen As Double, carbtype As Byte, intcfm, excfm, intvol, _
   exvol As Double, ohc As Boolean, overlap As Short, spare1, spare2, spare3 As Double)
   
   Type oldvdrecord(spress As Int, icenter As Int, ecenter As Int, idur As Int, edur As Int, ilift As Int, _
   elift As Int, weight As Int, head As Byte, extype As Byte, vtech As Boolean, fueltyp As Byte, no2 As Byte, _
   ecm As Byte, posi As Byte, susptype As Byte, tire As Byte, itype As Byte, ltype As Byte, boost As Byte, _
   trans As Byte, dish As Double, ccv As Double, twidth As Double, rock As Double, hgv As Double, idia As Double, _
   edia As Double, ratio As Double, bore As Double, stroke As Double, radius As Double, p2d As Double, cyl As Byte, _
   rod As Byte, ign As Byte, bal As Byte, blower As Byte, blowcfm As Int, vcyl As Byte, rodlen As Double, carbtype As Byte)Yes they are largish, but they serve my purpose. The new update needs to be able to read the old format (oldvdrecord) to convert existing filles. The problem is that it doesn't do that. It writes/reads the new structure just fine, but it refuses to read the old structure. Here are the read routines.
			
				B4X:
			
		
		
		Sub loadfile
   Dim vfile As RandomAccessFile
   
   If filenam = "" Then
   Return
   End If
   
   If importing Then
   vfile.Initialize(File.DirRootExternal,"/download/"&filenam, False)
   Else
   vfile.Initialize(datadir,filenam, False)
   End If
   
   Try
   vrec= vfile.ReadObject(0)
   Catch
   vfile.Close
   loadoldfile
   
   Return
   End Try
   vfile.Close
   
   init_fields   
   
End Sub
Sub loadoldfile
   Dim ovfile As RandomAccessFile
   
   If importing Then
   ovfile.Initialize(File.DirRootExternal,"/download/"&filenam, False)
   Else
   ovfile.Initialize(datadir,filenam, False)
   End If
   
   Try
   oldvrec.Initialize
   'oldvrec.spress= ovfile.ReadInt(0)
   
   oldvrec= ovfile.ReadObject(0)
   oldvrec_to_vrec
   
   Catch
   Msgbox("This file appears to be corrupted!","Error")
   Log(LastException)
   ovfile.Close
   init_fields
   
   Return
   End Try
   ovfile.Close
   
   init_fields   
   
End SubI am getting a "(IllegalArgumentException) java.lang.IllegalArgumentException: invalid value for field" in the log entry in the loadoldfile routine.
Even doing a oldvrec.spress= ovfile.readint(0) returns 641 instead of 70 (spress is the first field in the structure and is an integer). I have looked at this until I am blind, and I don't see the problem. Keep in mind that the old version still compiles, runs, reads, and writes just fine using the old structure. This "should" be a simple deal.
I'll entertain any ideas at this point. A .vdf file is attached so you can play with the old format file.
Thanks,
--- Jem
Missing Link Software
 
				 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		 
 
		