Code Analyzer

  • Thread starter Thread starter pregis
  • Start date Start date
P

pregis

Hi,

Is there a way that I can scan for the total number of lines of code written
thus far? I read in Help about a Code Metrics report but can't seem to
locate it? Am I on the right track?

Thank you in advance!

Patrick
 
Hi pregis,

What does this give for information while it becomes now possible in Visual
Basic in version 2010 to spread code over more lines than now with one.

You mean that persons start making code like this.
\\
Dim
X
as
Integer
=
5
///
And they are more productive then people doing
\\\
Dim X as Integer = 5
///

Code metrics are always asked by persons who want to show that they know
nothing about development but want to make it more efficient (With as result
that it takes 2 times the time, but than you can see in future the history
about that).

Just my opinion

Cor
 
Wow MZ-Tools for .NET, it's been a long time since I've seen that app. It
was quite handy back in the day, but surely VS 2008 has everything you need
built right into it now? Including refactoring, code metrics, analysis etc.
 
Hi Patrick,
Is there a way that I can scan for the total number of lines of code
written
thus far? I read in Help about a Code Metrics report but can't seem to
locate it? Am I on the right track?

Just right click the solution or project node in the "Solution Explorer",
which by default is on the right hand side of the IDE. Then click
"Calculate Code Metrics". It's also in the "Analyze" menu along the top.

Nick.
 
Just right click the solution or project node in the "Solution
Explorer", which by default is on the right hand side of the IDE. Then
click "Calculate Code Metrics". It's also in the "Analyze" menu
along the top.

That's only available in some versions of VS: I certainly can't find it in
VS2008 Professional.

Andrew
 
pregis said:
Hi,

Is there a way that I can scan for the total number of lines of code written
thus far? I read in Help about a Code Metrics report but can't seem to
locate it? Am I on the right track?

Thank you in advance!

Patrick

Patrick, if you all you want is the total lines, you can get a visual
count by putting your cursor at the end of the file and look at the
IDE status bar right hand side to get the count <g>

Or you can turn on the line numbers on the IDE editor. I like to see
line numbers myself, so I can quickly grasp where things are at
relatively, "hmmm that function is around line 378,500 or so." <g>

Or do what lots of good programmers do - right their own tools
especially for something very simple like getting line counts. That
would be line 3-5 lines in VB. See the ReadAllLines() function in MSDN.

--
 
especially for something very simple like getting line counts. That
would be line 3-5 lines in VB. See the ReadAllLines() function in MSDN.

That would not be that easy if you want counting lines in whole project
or even solution :)
 
I was just asking sir :) I don't know alot about development, that is why I
ask you the questions that I don't understand. I was given a project
recently and it allowed me to use Visual Studio 2008 for the first time... It
has been a success, in part because of the contributions of others MVP's such
as yourself. I appreciate your response, however unhelpful and almost
insulting.

Thank you.

Patrick
 
Peter said:
That would not be that easy if you want counting lines in whole project
or even solution :)

True.

I can see a command line tool like:

CountLines [filesspec]... [filesspec] [@listfile] [ProjectFile]

For the project file option, do a XML read, get the source elements
and count each file, produce a report, etc. :-)

Of course, to me, that is pretty worthless - just getting line counts
unless I wanted to place a Software Engineering rule that no file can
be more than 500 lines and/or function can be more than 25 lines to
promote black box functional programming, lower QA issues, etc. Such
SE rules existed in the past, i.e. federal defense contracts. Can't
tell ya if its still followed today - OOPS did change many things. :-)

--
 
Patrick,

Here are two quick ways to get a count using DOS commands. If you
never used DOS, use the IDE and click

TOOLS | Visual Studio 200x Command Prompt

This will open a DOS window.

1) Using FIND command:

find /V /C "^M" filename

example:

find /V /C "^M" testargs2.vb

---------- TESTARGS2.VB: 230

FIND takes a wild card, so you can use it for all files in your
project folder for example:

D:\Local\projects\wcChat.NET> find /V /C "^M" *.vb

---------- CLSCHATUSER.VB: 44
---------- COLCHATUSER.VB: 6
---------- FRMCHATMAIN.DESIGNER.VB: 774
---------- FRMCHATMAIN.VB: 991
---------- FRMHELP.DESIGNER.VB: 269
---------- FRMHELP.VB: 9
---------- FRMLOGIN.DESIGNER.VB: 191
---------- FRMLOGIN.VB: 49
---------- MODCHAT.VB: 98
---------- SETTINGS.VB: 11
---------- WCSERVERAPI.VB: 2105

2) Using FOR command in a batch file.

The following batch file will count lineso but the count excludes
blank lines. Cut and paste/save the following into a file called
CountLines.CMD

-------------- CUT HERE -----------------
@echo off
:-----------------------------------------
: count lines in files
:-----------------------------------------

setlocal
if "%1" == "" goto :help

: get list of files
for %%i in (%*) do call :sub_countfile %%i
goto :eof

:-----------------------------------------
:sub_countfile
:-----------------------------------------

: start count the file lines
set a=0
for /f %%i in (%1) do set /A a += 1

: show result and exit call
echo ---------- %1: %a%
goto :eof

:-----------------------------------------
:help
:-----------------------------------------
echo usage: countlines filespec1 [filespec2] ... [filespecN]
goto :eof
-------------- CUT HERE -----------------

example:

countlines testargs2.vb

---------- testargs2.vb: 187

or with a file spec:

D:\Local\projects\wcChat.NET> countlines *.vb

---------- clsChatUser.vb: 38
---------- colChatUser.vb: 4
---------- frmChatMain.Designer.vb: 769
---------- frmChatMain.vb: 869
---------- frmHelp.Designer.vb: 265
---------- frmHelp.vb: 5
---------- frmLogin.Designer.vb: 187
---------- frmLogin.vb: 41
---------- modChat.vb: 71
---------- Settings.vb: 10
---------- wcServerAPI.vb: 1950

You can really do alot these with the extended COMSPEC (DOS) commands
today, especially in manipulating text files, lines and strings. Its
almost a "real" language. :-)
 
Back
Top