私のコードは 64 ビット マシンで動作しますが、32 ビット マシンで実行すると、次のエラーが発生します (コードが正常に動作する場合もあります)。
InvalidCastException が処理されませんでした
次の数行は私のコードを提供します:
バイナリ ファイルに書き込むには:
Dim writeStream = New FileStream(path, FileMode.Open)
Dim BinReader As BinaryReader
next_byte = Len(CStr(time)) + Len("EndOfHeader") + 16 + 2
first_time = True
BinWriter = New BinaryWriter(writeStream)
For i = 0 To Form1.signals.Length - 1
If IsNothing(Form1.signals(i)) = False Then
'once for each test
BinWriter.Write(Int(Form1.signals(i).picodata.GetLength(0) - 1)) 'n for each signal in test
BinWriter.Write(Form1.signals(i).picodata(1, 0) - Form1.signals(i).picodata(0, 0)) 'timestep
BinWriter.Write(next_byte) 'position of start of test
BinWriter.Write(CStr(time))
Exit For
End If
Next
BinWriter.Write("EndOfHeader")
For i = 0 To Form1.signals.Length - 1
If IsNothing(Form1.signals(i)) = False Then
BinWriter.Write(i)
For j = 1 To Form1.signals(i).picodata.GetLength(0) - 1
BinWriter.Write(Form1.signals(i).picodata(j, 1))
Next
End If
Next
BinWriter.Close()
読み込むには:
Dim readstream As FileStream
Dim end_test As Integer
Dim Index As Integer
Dim BinReader As BinaryReader
Dim end_head as Boolean=false
Dim count as integer=0
selected_test=0
ReadStream = New FileStream(readFileName, FileMode.Open)
BinReader = New BinaryReader(ReadStream)
'read header
While end_head = False
Try
pos_old = ReadStream.Position
try_string = BinReader.ReadString
If try_string = "EndOfHeader" Then
Exit While
Else
ReadStream.Position = pos_old
End If
Catch ex As Exception
ReadStream.Position = pos_old
End Try
'this approach allows for flexibility
number_arr(count) = BinReader.ReadInt32
TimeStep_arr(count) = BinReader.ReadDouble
position_arr(count) = BinReader.ReadInt32
time_arr(count) = CDate(BinReader.ReadString)
count += 1
End While
'read in data
While readstream.Position <> read_stream.length
ReDim PicoData(number_arr(selected_test), 1)
Index = BinReader.ReadInt32
n = number_arr(selected_test)
For i = 1 To n
PicoData(i, 1) = BinReader.ReadDouble
PicoData(i, 0) = TimeStep_arr(selected_test) * i
Next
ReDim TimeShort(Int(n / 20))
ReDim FiltVoltsShort(Int(n / 20))
ReDim FiltVelShort(Int(n / 20))
ReDim RawVoltsShort(Int(n / 20))
'generate new reading here
Call FourierFilter(PicoData, 0)
signals(Index) = New reading(Index, TimeShort, RawVoltsShort, FiltVelShort, FiltVoltsShort, Points_Store(ii, 2), Points_Store(ii, 1), DataChart, VelocityChart, SelectedTimeBox, SelectedVelocityBox, True, PicoData)
End While
BinReader.Close()
readstream.Close()
日付が正しく読み込まれないことがあります。キャラクター+希望の日付を取得します。私のコードの一部は切り取られていますが (プログラムがかなり巨大なので)、私が送信した内容が何らかの意味を成すことを願っています。ありがとう