• Welcome to Valhalla Legends Archive.
 

Something to count how many lines in a project

Started by Topaz, April 10, 2005, 01:01 AM

Previous topic - Next topic

Topaz

There's one for C++ / Java, now tell me where to get one for vb6 projects!

The-FooL

Find a 3rd party tool that plugs into the IDE.  There are freeware ones where line counting is one of the most basic features.

Yegg

Here's a thought. Make a program that reads the code (the lines) of your program as a text document, it will then add all of the lines (one by one) to a list in your program (ListBox, ListView). Simply do Len(ListName), or however you would check how many items are in the list, and then you will know how many lines there are.


Grok

In Project References, add "Microsoft Visual Basic 6.0 Extensibility".  Also look for the VB Help topic "Programming in the Extensibility Model" for programming examples.  This library gives you access to the programmable interfaces of the VB IDE.

Ban

Quote from: Yegg on April 10, 2005, 06:19 PM
Here's a thought. Make a program that reads the code (the lines) of your program as a text document, it will then add all of the lines (one by one) to a list in your program (ListBox, ListView). Simply do Len(ListName), or however you would check how many items are in the list, and then you will know how many lines there are.

You forgot that blank lines should NOT be counted towards that final result.

Adron

Quote from: Ban on April 11, 2005, 09:49 AM
Quote from: Yegg on April 10, 2005, 06:19 PM
Here's a thought. Make a program that reads the code (the lines) of your program as a text document, it will then add all of the lines (one by one) to a list in your program (ListBox, ListView). Simply do Len(ListName), or however you would check how many items are in the list, and then you will know how many lines there are.

You forgot that blank lines should NOT be counted towards that final result.

Actually, instead of having to make a new listbox, you could do some code reuse here. Let's assume you already have a chat bot, with a listbox for the users in the channel. Most bots display the number of users in the channel as a caption or somewhere.

Now, what you need to do is create an application that processes data from the file, and feeds it to the bot's listbox. You'll have to start with two winsocks, one that listens for a connection and another to accept it. You'll want to listen on port 6112. Now, what you do is you listen for a connection. Then you load the bot, have it connect to 127.0.0.1. That's the magic number to have it connect to your new line counting application.

When the connection comes, you print the regular old "username:" and "password:" stuff to the winsock, and then user name / channel name, just make something up. At this time, the bot will think it is connected to a battle.net. Little does it know that its code is being reused!

Now, many bots might not allow really long usernames. They may also have a problem with the same username appearing more than once, or usernames containing spaces. For this reason we will have to translate the lines read from the file into something else to pass to the bot for counting. We will have to "generate" usernames.

As we need each username to be unique, but it doesn't matter what it is, the easiest way is to have a string variable that you just increase each letter one by one in. Here's some sample code to do that:


Function GetNextName As String
   Static n As String ' This is the name
   Dim i As Integer ' This is used for moving through the string
   i = 1
   Do
      ' Check if name must be longer!
      If i > Len(n) Then n = n & "A": Exit Do
      ' Check if this is we can use the next letter
      If Mid(n, i, 1) < "Z" Then Mid(n, i, 1) = Chr(Asc(Mid(n, i, 1)) + 1): Exit Do
      ' Reset this letter and move on
      Mid(n, i, 1) = "A"
      i = i + 1
   Loop
   GetNextName = n
End Function


Now, using this very powerful function we can actually create a unique name for each line!

Through this method, you will be able to give each line its own name, and pass that to the bot for counting. However, not all lines deserve a name. We may not want to count empty lines as lines for this purpose. In order not to give a name to lines that are empty, we must check for each line whether it's a good line before we let it have a name. This can be done through the following function:


Function IsGoodLine(ByVal line As String) As Boolean
    ' Empty lines are bad lines!
    If line = "" Then IsGoodLine = False: Exit Function
    ' OK So it's not empty, well then what character is there?
    Select Case Left(line, 1)
    Case " ", vbTab
        ' A space doesn't make a line good! Check the rest!
        IsGoodLine = IsGoodLine(Mid(line, 2))
    Case Else
        ' Oooh neat, there's something else on the line! This line is a good line!
        IsGoodLine = True
    End Select
End Function


OK, now you have the important functions. I leave the rest of the coding up to you. It should all be very simple coding, given that you have the central parts of the line counting bot reuse application already in this post.

Please share the remainder of the code after you have written it, so that others may learn how to count the lines of their source codes as well!

The-FooL

Quote from: Adron on April 11, 2005, 01:14 PM
Now, what you need to do is create an application that processes data from the file, and feeds it to the bot's listbox. You'll have to start with two winsocks, one that listens for a connection and another to accept it. You'll want to listen on port 6112. Now, what you do is you listen for a connection. Then you load the bot, have it connect to 127.0.0.1. That's the magic number to have it connect to your new line counting application.
Lmfao Adron

Ban

Quote from: The-FooL on April 11, 2005, 03:54 PM
Quote from: Adron on April 11, 2005, 01:14 PM
Now, what you need to do is create an application that processes data from the file, and feeds it to the bot's listbox. You'll have to start with two winsocks, one that listens for a connection and another to accept it. You'll want to listen on port 6112. Now, what you do is you listen for a connection. Then you load the bot, have it connect to 127.0.0.1. That's the magic number to have it connect to your new line counting application.
Lmfao Adron

It's almost as though Adron didn't realize that its more difficult to do that than simply read the lines ;)

UserLoser.

Quote from: Spht on April 11, 2005, 05:42 AM
I think UserLoser wrote one.

I didn't create a VB line counter project, I used some older tool I found somewhere on the web to do that.  However, I did create a replacement for link.exe which allowed me to passover my own options such as better optimizations, section data sizes, section names, function exports, compile as a dll, windows, console, etc.

R.a.B.B.i.T

http://www.mztools.com/
MZTools is great, and adds a lot of handy stuff in addition to just line counting (it can check for unused variables, for instance).