Hi, in my program, I'm reading a binary file to a structure. In the structure, I have one field called as 'ddcs' and it need to be declared as UInt16. However, there are exception prompt when I try to read the binary file with error message of 'File I/O of a structure with field 'ddcs' of type 'UInt16' is not valid'. And it will be working fine if I use Int16 as variable for 'ddcs' but the value is wrong as the binary file use unsigned 16bits for this value.
The correct value for the 'ddcs' field is 41213 but the value that I read is -24323 if I define the 'ddcs' field to Int16 and i know it is wrong.
Below is my code and please help.
The correct value for the 'ddcs' field is 41213 but the value that I read is -24323 if I define the 'ddcs' field to Int16 and i know it is wrong.
Below is my code and please help.
Code:
Private Structure Xhdccdf
<VBFixedString(6)> Public cdfver As String
<VBFixedString(48)> Public data1 As String
Public xcen As Int16
Public ycen As Int16
<VBFixedString(14)> Public swtyp As String
<VBFixedString(36)> Public data2 As String
<VBFixedString(12)> Public partfmly As String
<VBFixedString(16)> Public data3 As String
Public bths As Int16
Public crrs As Int16
Public bdcs As Int16
Public tdcs As Int16
Public ddcs As UInt16
Public trcs As Int16
Public xlocmin As Int16
Public xlocmax As Int16
Public ylocmin As Int16
Public ylocmax As Int16
<VBFixedString(158)> Public data4 As String
<VBFixedString(16)> Public wlot As String
<VBFixedString(12)> Public wnum As String
<VBFixedString(100)> Public data5 As String
End Structure
Private HdcCdf As Xhdccdf
Private Sub Read()
Try
FileOpen(10, m_strFilePath, OpenMode.Binary)
FileGet(10, HdcCdf)
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
FileClose(10)
End Try
End Sub