Public Function LoadFromBinFile() As Integer
Dim fsSource As FileStream
Dim brSource As BinaryReader
Dim i, j As Integer
Dim byteBuffer(2) As Byte
'ファイルを開く
Try
fsSource = New FileStream(strFileNameInput, FileMode.Open, FileAccess.Read)
brSource = New BinaryReader(fsSource)
Catch e As Exception
'失敗したとき
strLastErrorString = _
"This file cannot be opened: " + strFileNameInput + " (" + e.Message + ")"
Return -1
End Try
'配列のメモリ確保
ReDim intarySourceData(intCh, intPoints)
ReDim intaryDestData(intCh, intPoints)
'読み込み
Try
For i = 0 To intCh - 1 'チャネル方向にスキャン
For j = 0 To intPoints - 1 'サンプリング点方向にスキャン
byteBuffer = brSource.ReadBytes(2) '2バイト読み込み(配列に格納される)
intarySourceData(i, j) = _
byteBuffer(1) * 256 + byteBuffer(0) '2バイト分の内容を数値に復元
Next
Next
Catch e As Exception
'失敗したとき
strLastErrorString = _
"It is not possible to read from the file. (" + e.Message + ")"
Return -1
Finally
'とにかくファイルを閉じる
fsSource.Close()
brSource.Close()
End Try
'新規に読み込んだので、変換フラグをおろす
bDataConverted = False
Return 0
End Function
2005-05-15 03:13:10 (日)
プログラミング