Option ExplicitPrivate Type TDATA aName(0 To 13) As Byte nAge As Integer nByt As Byte End TypePrivate Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) Private Sub Command1_Click() Dim FileNum As Integer Dim FileName As String Dim aData() As Byte Dim p As Long Dim aTData() As TDATA Dim nCount As Long Dim s As String
FileNum = FreeFile
Open FileName For Binary As FileNum ReDim aData(0 To LOF(FileNum) - 1) As Byte Get FileNum, 1, aData Close FileNum
Option ExplicitPrivate Type TDATA aName(0 To 13) As Byte nAge As Integer nByt As Byte End Type Private Sub Command1_Click() Dim FileNum As Integer Dim FileName As String Dim IntLen As Integer Dim int_Temp As Integer FileNum = FreeFile
Open FileName For Binary As FileNum IntLen = LOF(FileNum) \ Len(TDATA) Dim StuInfo(IntLen - 1) As TDATA For int_Temp = 0 To IntLen - 1 Get FileNum, int_Temp * Len(TDATA) + 1, StuInfo(int_Temp) Next Close FileNum
Dim i As Integer Dim j As Integer Dim str_Temp As String For i = 0 To IntLen - 1 str_Temp = "" For j = 0 To 13 str_Temp = str_Temp & Chr(StuInfo(i).aName(j) + 32) Next MsgBox "Name" & i + 1 & "Is" & str_Temp Next
End Sub
年龄 双字节数 2 ,您定义为integer为什么? 要是年龄不是整型的,可以定义为什么?我定义为 nage(0 to 1) as byte对不对?读出来好象是错的?不知道该怎么读取了?请指教
因为integer就是2字节啊。。 年龄不可能不会整数, 所以不讨论。 nage(0 to 1)as byte 也对, 但是不知道你怎么读错了。
Private Type TDATA aName(0 To 13) As Byte nAge(0 To 1) As Byte nByt As Byte End TypePrivate Type TDATA aName(0 To 13) As Byte nAge As Integer nByt As Byte End Type上面两种定义的长度一样,可以说基本一样。可能是读取方法错误。
aName(0 To 13) As Byte
nAge As Integer
nByt As Byte
End TypePrivate Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Sub Command1_Click()
Dim FileNum As Integer
Dim FileName As String
Dim aData() As Byte
Dim p As Long
Dim aTData() As TDATA
Dim nCount As Long
Dim s As String
FileNum = FreeFile
Open FileName For Binary As FileNum
ReDim aData(0 To LOF(FileNum) - 1) As Byte
Get FileNum, 1, aData
Close FileNum
nCount = Fix(((UBound(aData) + 1)) / 17)
ReDim aTData(0 To nCount) As TDATA
CopyMemory aTData(0), aData(0), (UBound(aTData) + 1) * 17
s = aTData(1).aName
MsgBox s
Erase aData
Erase aTData
End Sub
aName(0 To 13) As Byte
nAge As Integer
nByt As Byte
End Type
Private Sub Command1_Click()
Dim FileNum As Integer
Dim FileName As String
Dim IntLen As Integer
Dim int_Temp As Integer
FileNum = FreeFile
Open FileName For Binary As FileNum
IntLen = LOF(FileNum) \ Len(TDATA)
Dim StuInfo(IntLen - 1) As TDATA
For int_Temp = 0 To IntLen - 1
Get FileNum, int_Temp * Len(TDATA) + 1, StuInfo(int_Temp)
Next
Close FileNum
Dim i As Integer
Dim j As Integer
Dim str_Temp As String
For i = 0 To IntLen - 1
str_Temp = ""
For j = 0 To 13
str_Temp = str_Temp & Chr(StuInfo(i).aName(j) + 32)
Next
MsgBox "Name" & i + 1 & "Is" & str_Temp
Next
End Sub
要是年龄不是整型的,可以定义为什么?我定义为 nage(0 to 1) as byte对不对?读出来好象是错的?不知道该怎么读取了?请指教
年龄不可能不会整数, 所以不讨论。
nage(0 to 1)as byte 也对, 但是不知道你怎么读错了。
aName(0 To 13) As Byte
nAge(0 To 1) As Byte
nByt As Byte
End TypePrivate Type TDATA
aName(0 To 13) As Byte
nAge As Integer
nByt As Byte
End Type上面两种定义的长度一样,可以说基本一样。可能是读取方法错误。