投稿日 | : 2004/04/14(Wed) 21:17 |
投稿者 | : つばさくん |
URL | : |
タイトル | : 2行目を削除できるようになりました。 |
花ちゃんありがとうございました。
CSVファイル指定行とまでは行かなかったのですが
2行目を選択的に削除できるようになりました。
質問なのですが
指定行とするためには、指定した行までのbyte数をきっちり
おさえれば、良いのでしょうか?
ちなみに、こんなプログラムです。
Private Sub Command1_Click()
Dim DelTxt1 As String
Dim DelTxt2 As String
Dim Fso As New FileSystemObject
Dim FsoTS As TextStream
Dim DelByt1 As Long
Dim DelByt2 As Long
Dim FilePath As String
Dim bytArray1() As Byte
Dim bytArray2() As Byte
Dim bytArray3() As Byte
Dim intFileNo As Integer
Dim lngFileLenB As Long
'対象とするデータへのパスを設定する
FilePath = App.Path & "\test.csv"
’データの配列を取得する
Set FsoTS = Fso.OpenTextFile(FilePath)
DelTxt1 = FsoTS.ReadLine & vbCrLf '先頭行データ配列
DelTxt2 = FsoTS.ReadLine & vbCrLf '2行目データ配列
FsoTS.Close
Set FsoTS = Nothing
’テキストに表示する
Text3.Text = DelTxt2 '2行目をテキストに表示
’データのバイト数を取得する
DelByt1 = LenB(StrConv(DelTxt1, vbFromUnicode)) '先頭行のバイト数
DelByt2 = LenB(StrConv(DelTxt2, vbFromUnicode)) '2行目のバイト数
lngFileLenB = FileLen(FilePath) 'ファイル全体のバイト数
’配列要素数を設定する
ReDim bytArray2(DelByt1 - 1) '先頭行の配列要素数を設定
ReDim bytArray3(DelByt2 - 1) '2行目の配列要素数を設定
ReDim bytArray1(lngFileLenB - DelByt2 - 1) '3行目以降の配列要素数を設定
’?????
intFileNo = FreeFile
Open FilePath For Binary As #intFileNo
Get #intFileNo, , bytArray2 'よくわからない
Get #intFileNo, , bytArray3
Get #intFileNo, , bytArray1
Close #intFileNo
’テキストボックスへ表示する
Text1.Text = StrConv(bytArray1, vbUnicode) '2行目から最終行までをテキストに表示
Text2.Text = StrConv(bytArray2, vbUnicode) '先頭行をテキストに表示
’データを削除する
Kill FilePath '更新前ファイルを削除
’ファイルに書き込む
intFileNo = FreeFile
Open FilePath For Binary Access Write As #intFileNo '新規に同じ名前で書込
Put #intFileNo, , bytArray2 'まずはじめに先頭行を書き込む
Put #intFileNo, , bytArray1 '続いて3行目以降のデータ行を書込
Close #intFileNo
End Sub