Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
VB.NET Project Code Line Counter/Watcher
Author:
Craig
Website:
http://www.computerguy.ws
Submitted:
10/6/2012
Version:
VB 2010
Compatibility:
VB 2010
Category:
File Manipulation
Views:
6491
Simple little app that counts and watches the source files for the lines of code and ads them up and writes them to a temp text file. Teaches how to read files and write files in vb.net
Declarations:
You need a form with a timer and a bunch of labels :) You also need to modify the locations and names of the files you are watching. Uses FSO so it should work in ASP and ASP.NET as well.
Code:
Imports System.IO Public Class LineCounter Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Label20.BackColor = Color.LightGray Label1.BackColor = Color.LightGray Label4.BackColor = Color.LightGray Label6.BackColor = Color.LightGray Label8.BackColor = Color.LightGray Label10.BackColor = Color.LightGray Label12.BackColor = Color.LightGray Label14.BackColor = Color.LightGray Label16.BackColor = Color.LightGray Label18.BackColor = Color.LightGray CountLines() Timer1.Start() End Sub Private Sub CountLines() Dim fsoMyFile = CreateObject("Scripting.FileSystemObject") Dim tsTextStream Dim BPD Dim BP Dim DD Dim D Dim LD Dim L Dim URD Dim UR Dim UMD Dim UM Dim DA Dim DCA Dim FA Dim IA Dim PCA Dim VA fsoMyFile = CreateObject("Scripting.FileSystemObject") tsTextStream = fsoMyFile.OpenTextFile("C:\Users\Craig\Documents\Visual Studio 2012\Projects\Tech Notifier\Tech Notifier\Forms\BackPanel.Designer.vb", 1) Dim LinesOfCodeBPD = 0 Do While Not tsTextStream.AtEndOfStream tsTextStream.ReadLine() LinesOfCodeBPD = LinesOfCodeBPD + 1 Loop tsTextStream.Close() BPD = LinesOfCodeBPD - 1 Label19.Text = BPD tsTextStream = fsoMyFile.OpenTextFile("C:\Users\Craig\Documents\Visual Studio 2012\Projects\Tech Notifier\Tech Notifier\Forms\BackPanel.vb", 1) Dim LinesOfCodeBP = 0 Do While Not tsTextStream.AtEndOfStream tsTextStream.ReadLine() LinesOfCodeBP = LinesOfCodeBP + 1 Loop tsTextStream.Close() BP = LinesOfCodeBP - 1 Label2.Text = BP tsTextStream = fsoMyFile.OpenTextFile("C:\Users\Craig\Documents\Visual Studio 2012\Projects\Tech Notifier\Tech Notifier\Forms\Details.Designer.vb", 1) Dim LinesOfCodeDD = 0 Do While Not tsTextStream.AtEndOfStream tsTextStream.ReadLine() LinesOfCodeDD = LinesOfCodeDD + 1 Loop tsTextStream.Close() DD = LinesOfCodeDD - 1 Label3.Text = DD tsTextStream = fsoMyFile.OpenTextFile("C:\Users\Craig\Documents\Visual Studio 2012\Projects\Tech Notifier\Tech Notifier\Forms\Details.vb", 1) Dim LinesOfCodeD = 0 Do While Not tsTextStream.AtEndOfStream tsTextStream.ReadLine() LinesOfCodeD = LinesOfCodeD + 1 Loop tsTextStream.Close() D = LinesOfCodeD - 1 Label5.Text = D tsTextStream = fsoMyFile.OpenTextFile("C:\Users\Craig\Documents\Visual Studio 2012\Projects\Tech Notifier\Tech Notifier\Forms\Login.Designer.vb", 1) Dim LinesOfCodeLD = 0 Do While Not tsTextStream.AtEndOfStream tsTextStream.ReadLine() LinesOfCodeLD = LinesOfCodeLD + 1 Loop tsTextStream.Close() LD = LinesOfCodeLD - 1 Label7.Text = LD tsTextStream = fsoMyFile.OpenTextFile("C:\Users\Craig\Documents\Visual Studio 2012\Projects\Tech Notifier\Tech Notifier\Forms\Login.vb", 1) Dim LinesOfCodeL = 0 Do While Not tsTextStream.AtEndOfStream tsTextStream.ReadLine() LinesOfCodeL = LinesOfCodeL + 1 Loop tsTextStream.Close() L = LinesOfCodeL - 1 Label9.Text = L tsTextStream = fsoMyFile.OpenTextFile("C:\Users\Craig\Documents\Visual Studio 2012\Projects\Tech Notifier\Tech Notifier\Forms\UpdateRegFrm.Designer.vb", 1) Dim LinesOfCodeURD = 0 Do While Not tsTextStream.AtEndOfStream tsTextStream.ReadLine() LinesOfCodeURD = LinesOfCodeURD + 1 Loop tsTextStream.Close() URD = LinesOfCodeURD - 1 Label11.Text = URD tsTextStream = fsoMyFile.OpenTextFile("C:\Users\Craig\Documents\Visual Studio 2012\Projects\Tech Notifier\Tech Notifier\Forms\UpdateRegFrm.vb", 1) Dim LinesOfCodeUR = 0 Do While Not tsTextStream.AtEndOfStream tsTextStream.ReadLine() LinesOfCodeUR = LinesOfCodeUR + 1 Loop tsTextStream.Close() UR = LinesOfCodeUR - 1 Label13.Text = UR tsTextStream = fsoMyFile.OpenTextFile("C:\Users\Craig\Documents\Visual Studio 2012\Projects\Tech Notifier\Tech Notifier\Forms\UserManager.Designer.vb", 1) Dim LinesOfCodeUMD = 0 Do While Not tsTextStream.AtEndOfStream tsTextStream.ReadLine() LinesOfCodeUMD = LinesOfCodeUMD + 1 Loop tsTextStream.Close() UMD = LinesOfCodeUMD - 1 Label15.Text = UMD tsTextStream = fsoMyFile.OpenTextFile("C:\Users\Craig\Documents\Visual Studio 2012\Projects\Tech Notifier\Tech Notifier\Forms\UserManager.vb", 1) Dim LinesOfCodeUM = 0 Do While Not tsTextStream.AtEndOfStream tsTextStream.ReadLine() LinesOfCodeUM = LinesOfCodeUM + 1 Loop tsTextStream.Close() UM = LinesOfCodeUM - 1 Label17.Text = UM Try tsTextStream = fsoMyFile.OpenTextFile("C:\Users\Craig\Documents\wwwroot\TimeClock\default.asp", 1) Dim LinesOfCodeDA = 0 Do While Not tsTextStream.AtEndOfStream tsTextStream.ReadLine() LinesOfCodeDA = LinesOfCodeDA + 1 Loop tsTextStream.Close() DA = LinesOfCodeDA - 1 Label25.Text = DA tsTextStream = fsoMyFile.OpenTextFile("C:\Users\Craig\Documents\wwwroot\TimeClock\default.css", 1) Dim LinesOfCodeDCA = 0 Do While Not tsTextStream.AtEndOfStream tsTextStream.ReadLine() LinesOfCodeDCA = LinesOfCodeDCA + 1 Loop tsTextStream.Close() DCA = LinesOfCodeDCA - 1 Label27.Text = DCA tsTextStream = fsoMyFile.OpenTextFile("C:\Users\Craig\Documents\wwwroot\TimeClock\Functions.asp", 1) Dim LinesOfCodeFA = 0 Do While Not tsTextStream.AtEndOfStream tsTextStream.ReadLine() LinesOfCodeFA = LinesOfCodeFA + 1 Loop tsTextStream.Close() FA = LinesOfCodeFA - 1 Label29.Text = FA tsTextStream = fsoMyFile.OpenTextFile("C:\Users\Craig\Documents\wwwroot\TimeClock\Invoice.asp", 1) Dim LinesOfCodeIA = 0 Do While Not tsTextStream.AtEndOfStream tsTextStream.ReadLine() LinesOfCodeIA = LinesOfCodeIA + 1 Loop tsTextStream.Close() IA = LinesOfCodeIA - 1 Label31.Text = IA tsTextStream = fsoMyFile.OpenTextFile("C:\Users\Craig\Documents\wwwroot\TimeClock\Pdefault.css", 1) Dim LinesOfCodePCA = 0 Do While Not tsTextStream.AtEndOfStream tsTextStream.ReadLine() LinesOfCodePCA = LinesOfCodePCA + 1 Loop tsTextStream.Close() PCA = LinesOfCodePCA - 1 Label33.Text = PCA tsTextStream = fsoMyFile.OpenTextFile("C:\Users\Craig\Documents\wwwroot\TimeClock\Vars.asp", 1) Dim LinesOfCodeVA = 0 Do While Not tsTextStream.AtEndOfStream tsTextStream.ReadLine() LinesOfCodeVA = LinesOfCodeVA + 1 Loop tsTextStream.Close() VA = LinesOfCodeVA - 1 Label35.Text = VA Catch ex As Exception MsgBox(ex.Message.ToString) End Try Dim LinesTotal = BPD + BP + DD + D + LD + L + URD + UR + UMD + UM + DA + DCA + FA + IA + PCA + VA Label22.Text = LinesTotal Dim LinesUTotal = BP + D + L + UR + UM + DA + DCA + FA + IA + PCA + VA Label23.Text = LinesUTotal Dim objStreamWriter As StreamWriter objStreamWriter = New StreamWriter("C:\Temp\LinesOfCode.txt") objStreamWriter.WriteLine("Total Lines - " & LinesTotal) objStreamWriter.WriteLine("Total User Lines - " & LinesUTotal) objStreamWriter.Close() End Sub Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick CountLines() End Sub End Class
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement