人力検索はてな
モバイル版を表示しています。PC版はこちら
i-mobile

急いでいます。どなたかお助け下さい>< ACCESS2003 VBAに関する質問です。

ソースは下記のとおりです。
Sub RemoveDoubleComma()
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
Dim i, data
Dim k
i = 14
k = 10
Dim filePath
filePath = "\\SERVER\メンテNO" & i & ".txt"
DoCmd.TransferText acExportDelim, "TメンテNO" & k & " エクスポート定義", "TメンテNO" & k, filePath

Sleep 300
Dim fileContents
With fso.OpenTextFile(filePath)
fileContents = .ReadAll()
.Close
End With

Sleep 300
Do While InStr(fileContents, ",,") > 0
fileContents = Replace(fileContents, ",,", ",")
Loop
fileContents = Replace(fileContents, vbNewLine & ",", vbNewLine)
fileContents = Replace(fileContents, "," & vbNewLine, vbNewLine)

With fso.CreateTextFile(filePath, True)
.Write fileContents
.Close
End With
End Sub

テキストファイルの中身は下記のとおりです。
"46824","2","201","20110320","99999999","52","202","20110320","99999999","52","203","20110320","99999999","52","204","20110320","99999999","52" ←OK
"46824","3" ←NG削除
「"46824","3"」←カンマ含み全部で11文字の行の場合は行を削除したいのです。
上のソースに追加して下さい><

宜しくお願いします。

●質問者: hogehoho
●カテゴリ:コンピュータ インターネット
✍キーワード:LOOP ng SET sub txt
○ 状態 :終了
└ 回答数 : 1/1件

▽最新の回答へ

1 ● Mook
●100ポイント ベストアンサー

先ほどのは誤記以外は問題なかったのでしょうか?


また、今回の要望も厳密に11文字と一致するという条件だけでよいのですか?

この辺り軽微な話なので、ご自身で調整できるのであれば良いですが。

.Write fileContents

Dim line
For Each line In Split( fileContents, vbNewLine )
 If Len( line ) <> 11 Then .WriteLine fileContents
Next

に置き換えてどうでしょうか。

◎質問者からの返答

カンマ外れて良い感じなのですが。

データが繰り返し表示されるようになったのと、11文字でも出力されています><

"46824","3","201","20000101","20110319","51","202","20000101","20110319","51","203","20000101","20110319","51","204","20000101","20110319","51"

"46824","3","205","20000101","20110319","51","206","20000101","20110319","34"

"46824","3","756","20000101","20110319","54"

"46824","3"

"46824","3","201","20000101","20110319","51","202","20000101","20110319","51","203","20000101","20110319","51","204","20000101","20110319","51"

"46824","3","205","20000101","20110319","51","206","20000101","20110319","34"

"46824","3","756","20000101","20110319","54"

"46824","3"

"46824","3","201","20000101","20110319","51","202","20000101","20110319","51","203","20000101","20110319","51","204","20000101","20110319","51"

"46824","3","205","20000101","20110319","51","206","20000101","20110319","34"

"46824","3","756","20000101","20110319","54"

"46824","3"

関連質問


●質問をもっと探す●



0.人力検索はてなトップ
8.このページを友達に紹介
9.このページの先頭へ
対応機種一覧
お問い合わせ
ヘルプ/お知らせ
ログイン
無料ユーザー登録
はてなトップ