Re:SALOON & VBA

PL/SQLソースの有効行カウントツール(Excel VBA)

生産性を測る基準値として、
ソースの規模(行数)を用いることがあります。

そういう時、
コメント行をどうするか?
は、考え方の違いにも依りますが・・・
省いた有効行だけのカウントも、ひとつの指標にはなります。

で、細目にコメントが入っている場合
マクロでカウント出来れば便利かなと
考えてみました。

コメントは、言語に依りますが、今回は 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
名前:
コメント:

※文字化け等の原因になりますので顔文字の投稿はお控えください。

コメント利用規約に同意の上コメント投稿を行ってください。

 

※ブログ作成者から承認されるまでコメントは反映されません。

  • Xでシェアする
  • Facebookでシェアする
  • はてなブックマークに追加する
  • LINEでシェアする

最新の画像もっと見る

最近の「EXCEL VBA」カテゴリーもっと見る

最近の記事
バックナンバー
人気記事