ソースの規模(行数)を用いることがあります。
そういう時、
コメント行をどうするか?
は、考え方の違いにも依りますが・・・
省いた有効行だけのカウントも、ひとつの指標にはなります。
で、細目にコメントが入っている場合
マクロでカウント出来れば便利かなと
考えてみました。
コメントは、言語に依りますが、今回は PL/SQL をターゲットに
-- と /* */ の場合にしてみました。
どうでしょうか?
Option Explicit
Sub ファイル一覧作成()
Dim buf As String ' ファイル名
Dim cnt As Long ' 連番
Dim Path As String ' フォルダ名
Path = Cells(1, 2).Value & "\"
buf = Dir(Path & "*.sql")
cnt = 0
Range("A3:E3").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
Range("A2").Select
Do While buf <> ""
cnt = cnt + 1
Cells(cnt + 2, 1) = "Y" ' カウント取得マーク
Cells(cnt + 2, 2) = cnt ' 連番
Cells(cnt + 2, 3) = buf ' ファイル名
Cells(cnt + 2, 4) = FileDateTime(Path & buf) ' 更新日
buf = Dir()
Loop
If cnt = 0 Then
MsgBox "対象ファイルはありません!"
End If
End Sub
Sub 有効行数取得()
Dim buf As String
Dim cnt As Long
Dim cnt2 As Long ' 有効行数
Dim Path As String ' フォルダ名
Dim TARGET As String ' ソースファイル名
Dim inCFlg As Boolean ' インラインコメント
Path = Cells(1, 2).Value
cnt = 3
With CreateObject("ADODB.Stream")
.Charset = "UTF-8"
Do While Cells(cnt, 3).Value <> ""
If Cells(cnt, 1).Value <> "" Then
TARGET = Path & "\" & Cells(cnt, 3).Value
.Open
.LoadFromFile TARGET
cnt2 = 0
inCFlg = False
Do Until .EOS
buf = .ReadText(-2)
If Left(Trim(buf), 2) = "/*" Then
inCFlg = True
End If
If Right(Trim(buf), 2) = "*/" Then
inCFlg = False
End If
If Left(Trim(buf), 2) <> "--" And _
Trim(buf) <> "" And _
Left(Trim(buf),1) <> "/" And _
Left(Trim(buf),4) <> "SHOW" And _
Left(Trim(buf),4) <> "show" And _
inCFlg = False Then
cnt2 = cnt2 + 1
End If
Loop
.Close
Cells(cnt, 5).Value = cnt2
End If
cnt = cnt + 1
Loop
End With
MsgBox "有効行数カウント終了"
End Sub
最新の画像もっと見る
最近の「EXCEL VBA」カテゴリーもっと見る
最近の記事
カテゴリー
- VBScript(2)
- Weblog(314)
- お仕事ツール(0)
- Saloon(1099)
- Node.js他(Python)(16)
- HTA(32)
- 決め・分け論(64)
- 映画・ドラマ(37)
- EXCEL VBA(35)
- PL/SQL(10)
- Java(11)
- 詩(自作)(5)
- 詩(塚原将)(298)
- 短歌(200)
- 題詠100首鑑賞(96)
- 題詠100首(109)
- ALIAS SMITH and JONES エピソード(1)
- 題詠100首2010(11)
- 読書(74)
- プロスポーツ(プロ野球、格闘技)(27)
- 日常・育児とか(88)
- 仕事(IT関係)(61)
- とほほ(33)
- 夢(32)
- 勝手にバトン(7)
- 写真(36)
- スタートレック視聴日誌草稿(24)
- 旅行(25)
- 嫌いな言葉(6)
- 好きな言葉(4)
バックナンバー
人気記事