realbasic-nug
[Top] [All Lists]

Counting Lines of Code

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Counting Lines of Code
From: Seth Willits <seth at freaksw dot com>
Date: Fri, 30 Jul 2004 23:22:00 -0700
Delivered-to: realbasic-nug at lists dot realsoftware dot com
Another quick FYI, I wrote this little project to count the lines of code in a project by using the text from the "Export Source" action. It only counts non-blank lines of code and comments. So the lines like "Window1.BtnCount.Action:" and "Sub Action()" aren't count. It's also quite fast - "instant" with the largest projects I have here.

I wonder though who has the largest project... anyone care to dance? My largest currently tops under 6 grand at the moment, but I don't really write very large projects. I just write lots of medium-sized ones and never finish most of them. Now if you added up all the code of all the "current" projects I have, then I'd be a contender...


Window1.BtnCount.Action:
Sub Action()
  dim dlog as OpenDialog

  // Select File
  dlog = New OpenDialog
  dlog.Filter = "text"
  if dlog.ShowModal = nil then return
  File = dlog.Result

  // Run
  Thread1.Run
End Sub

Window1.Thread1.Run:
Sub Run()
  dim tin as TextInputStream
  dim lines as Integer
  dim line as String

  // Open File
  tin = File.OpenAsTextFile
  if tin = nil then
    beep
    return
  end if
  BtnCount.Enabled = false
  ChasingArrows1.Visible = true

  while tin.EOF = false
    line = tin.ReadLine
    if line <> "" and Left(line, 1) = " " then
      lines = lines + 1
    end if
  wend

  // Show lines
  StatLines.Text = "Lines of code: " + str(Lines)

  // Close file
  BtnCount.Enabled = true
  ChasingArrows1.Visible = false
  tin.Close
End Sub



Seth Willits
------------------------------------------------------------------------ ---
President and Head Developer of Freak Software - http://www.freaksw.com
REALbasic Guru at ResExcellence - http://www.resexcellence.com/realbasic

"When one door of happiness closes, another opens; but often we look so
long at the closed door that we do not see the one which has opened for us."
    -- Hellen Keller
------------------------------------------------------------------------ ---

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://www.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>