I am running into one of the strangest issues I have seen in a long time. I have a user defined type that I utilize in VB6 and write out to a binary file.
The Type is...
The file is written in VB as such..
The Magic,SectionVcnt,SectionNum are simply integers, so the file created is 3 integers then as many of these user types as needed.
In excel I read this in as one would expect...
This has worked without issue for many years. However, after my last upgrade to the SectionDB user type, suddenly when I read in the sections, they are offset by 1 byte, for no reason that I can find, the header of the files is still those 3 integers. The first section read's in just fine, but the rest are offset. I can succesfully read them in only if I alter the code to...
which I really don't want to do. I know that when reading in Variant types you need a 2 byte descriptor, but I am not using any variants, I am completely at a loss for what could be happening here.
And this file reads in exactly right in VB6.
Any insight would be greatly appreciated.
Thanks
The Type is...
Code:
Type SECTIONDB ' Job Section List Database
SectionNum As Integer ' Section number
Multiplier As Long ' Multiplier
SpecName As String * 8 ' Spec name
ZoneName As String * 60 ' Zone name
Division As String * 20 ' Variable Zone Identifier
Subzone As String * 40 ' Subzone description
AssemblyName As String * 60 ' Assembly name
Notes As String * 100 ' User notes (remarks)
Flags As Integer ' Section flags
BaseHours As Double ' Base hours for section
AdjustHoursV(3) As Double ' Adjusted hours for section
FactorV(3) As Single ' User labor factor for section
JobHoursV(3) As Double ' Total job hours
ExceptCnt As Integer ' Exception count
ScaleFactor As Long ' Scale (1"=x')
RefSizeV(13) As Integer ' Reference sizes
VarDesc(13) As String * 16 ' Variable Size Descriptions
OrderNum As Integer ' Zone Order
RFU As String * 60 ' Reserved space for future use
End Type
The file is written in VB as such..
Code:
Dim I As Integer
Dim FD As Integer
Dim Magic As Integer
On Error Resume Next
DeleteFile Path
FD = FreeFile
Open Path For Binary Access Write As FD
If Err <> ERR_NONE And Err <> ERR_NOTFOUND Then GoTo StoreSectionDB_Error
On Error GoTo StoreSectionDB_Error
Magic = SECTIONDB_MAGIC
Put FD, 1, Magic
Put FD, , SectionVCnt
Put FD, , SectionNum
For I = 0 To SectionVCnt - 1
Put FD, , SectionV(I)
Next I
Close FD
The Magic,SectionVcnt,SectionNum are simply integers, so the file created is 3 integers then as many of these user types as needed.
In excel I read this in as one would expect...
Code:
FD = FreeFile()
Open PathName For Binary Access Read As FD
Get FD, 1, Magic
Get FD, , SectionVCnt
Get FD, , SectionNum
ReDim SectionV(SectionNum)
For i = 0 To SectionVCnt - 1
Get FD, , SectionRec
next i
This has worked without issue for many years. However, after my last upgrade to the SectionDB user type, suddenly when I read in the sections, they are offset by 1 byte, for no reason that I can find, the header of the files is still those 3 integers. The first section read's in just fine, but the rest are offset. I can succesfully read them in only if I alter the code to...
Code:
Get FD, Len(Magic) + Len(SectionVCnt) + Len(SectionNum) + Len(SectionRec) * i + 1, SectionRec
which I really don't want to do. I know that when reading in Variant types you need a 2 byte descriptor, but I am not using any variants, I am completely at a loss for what could be happening here.
And this file reads in exactly right in VB6.
Any insight would be greatly appreciated.
Thanks