dcsimg
Results 1 to 20 of 20

Thread: [RESOLVED] Continuous Line Numbering

  1. #1

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    58

    Resolved [RESOLVED] Continuous Line Numbering

    Hi every one.

    The question might seem silly; but i really couldn't do it!

    I need to have line numbering in my vb6 project (in 2010!) for error handling matters.

    I have used Mz-Tools and some others to do so, they do it fine, the matter is that I have for example 20 forms and 50 functions in each one! The line numbering will reset itself at beginning of every single function/sub, so if the error is at line number 25, I don't know line 25 of which function.

    I have tried to find a way that the errorFinder gives me the function/sub name. But it needs writing a few lines to label each function and if I am forced to do so I will just forget about error handling!!! Its way too difficult with this load of codes!

    Anyway, if you know how to have continuous line numbering from start until the end of each form or you have any other solution for this problem, your help is appreciated in advance!

  2. #2
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: Continuous Line Numbering

    Quote Originally Posted by Luinox86 View Post
    I have tried to find a way that the errorFinder gives me the function/sub name. But it needs writing a few lines to label each function and if I am forced to do so I will just forget about error handling!!! Its way too difficult with this load of codes!
    That's why things like that are done during coding. Not wait till the end to append stuff like that to the entire project.

    As for a solution, an idea. Have MZ tools insert line numbers everywhere. Then create a new project to do something like this:

    1. List all (relevant) project files
    2. Load each file as plain text and do this with it:
    3. Go line by line, check if the line begins with a number followed by a white space character (tab or space)
    4. If it does, replace the number with your own number (create a counter which will increment continuously so each line has a different number)
    Last edited by baja_yu; Sep 22nd, 2010 at 10:05 PM.

  3. #3

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    58

    Re: Continuous Line Numbering

    Thanks.

    Actually i joined this project when it was done for around 70%, so I could not just change everything.

    Yes, this seems like a good solution, but I was looking for something with less effort. Because the other members of project do not tend to have too much manipulation and/or writing more projects to achieve this single goal.

    Why am i focusing on the line number solution is because I have written it up to a stable point. My function now gives the form name and the line number that the error happened in. But if there are for example eight lines numbered as 58, then we have to check them all. If just there is a way to have the line numbers not to reset on any function, that would be great. So the message box would say for example "Error happened at form number x, line number y." So that is way easy to find the line.

    ps: I want this function to work "ONLY" when executing using the .exe file, not in the VB environment.

    Thanks by the way.
    Looking forward to hear yours and others opinion.

  4. #4
    Frenzied Member
    Join Date
    Nov 2005
    Posts
    1,834

    Re: Continuous Line Numbering

    Adding error handling to a function/sub can be done with one click on a Toolbar button with MZ-Tools. It will take you about 5 minutes to add error handling to the entire project.

    Go to Tools -> MZ-Tools -> Options... -> Error Handler tab.

    Paste the following into the white box:

    Code:
        On Error GoTo {PROCEDURE_NAME}_Error
    
    	{PROCEDURE_BODY}
    
    Exit {PROCEDURE_TYPE}
    {PROCEDURE_NAME}_Error:
    
        MsgBox "Error " & Err.Number & " (" & Err.Description & ") on line " & Erl & " in procedure {PROCEDURE_NAME} of {MODULE_TYPE} {MODULE_NAME}", vbCritical, "Error"
    Then click somewhere inside a function/sub and click on the "Add Error Handler" Toolbar button. Do this for all functions/subs that require error handling. Maybe some functions/subs require different error handling, but that's up to you.



    Then finally go to Tools -> MZ-Tools -> Add Line Numbers.
    Last edited by Chris001; Sep 22nd, 2010 at 11:55 PM.

  5. #5

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    58

    Re: Continuous Line Numbering

    Thank you Chris001.

    It was pretty clear(and thanks for the picture; saved a lot of time ) and with little bit manipulation I just got what I needed; only one problem exists:

    Now I know how to use it, but how do i set it to all functions/subs the same Error-handler? is there any way to do so (we have hundreds of functions/subs).


    PS:
    By the way in the last question I asked how to add line numbers continuously to all the project codes without reseting it; I got my answer from MZ-Tools support team. To do so:

    "Go to the Options window, General tab, and check the "Use unique line numbers when adding line numbers to a whole project". Then, in the Project Explorer right-click a project and select the "Add Line Numbers" context menu. That will add continuous line numbers"

    Thanks to Carlos Quintero from MZTools Software.
    Last edited by Luinox86; Sep 23rd, 2010 at 02:58 AM.

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,415

    Re: Continuous Line Numbering

    Quote Originally Posted by Luinox86 View Post
    Now I know how to use it, but how do i set it to all functions/subs the same Error-handler? is there any way to do so (we have hundreds of functions/subs).
    Unfortunately you need to do that part manually, and it is arguably a good thing because it wont remove any existing error handlers (which you need to remove yourself, or merge in to your new one, or keep the old one, etc).

    You can make it a little easier tho by starting in the "General" -> "Declarations" section at the top of a code file, then press Ctrl-PgDown to move to the next sub/function, then press the error handler button, and repeat until you reach the end of the file.

  7. #7

  8. #8

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    58

    Re: Continuous Line Numbering

    Thanks si_the_geek & MartinLiss,

    Both answers are very helpful. I am clear how to use them and I hope we can solve the problem using the answers I got from this thread.

    By the way, I will tag this thread as 'solved' after testing them, but one question, is the vbForums.com like some others that for example the creator of the thread should give 'credit' to the person who could solve the problem or if I tag it as resolved is just to know that the problem is solved?!


    Thank everyone. I will post again if there is a problem.

  9. #9
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,148

    Re: Continuous Line Numbering

    When you have your answer, you can help us by marking the thread as resolved. If you have JavaScript enabled you can do that by selecting the Mark Thread Resolved item from the Thread Tools menu. Otherwise please insert "[Resolved]" at the start of the Subject and select the green checkmark from the Post Icons. Also if someone has been particularly helpful you have the ability to affect their forum "reputation" by rating their post. Only those ratings that you give after you have 20 posts will actually count, but in all cases the person you rate will see your rating and know that you appreciate their help. (No need to do it for me).

  10. #10

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    58

    Re: Continuous Line Numbering

    MartinLiss,

    Thank you for your info. I was reading your VB Project add in "Insert Procedure Names", It's a brilliant idea specially in my case that both projects I am currently working on have passed 2 years for one and 6 month for another one; so I am in the middle of both of them and lots of time i need to add stuff to the code.

    With your permission, I wanted to do some manipulation on your code, so instead of only adding the constant variable that carries the name of the procedure, we can add other stuff in the code too.

    Like what I am trying to do, I have the code for error handling but I want to add to *all* functions at once. So it requires me to add a few lines at the end of each function as well.

    I read your code its kind of clear to me what's happening, so CODE_PREFIX is the value that will be added and defined by user, and the procedure name follows that. I missed the lead after pressing the command button on the msgbox that is filling MarkerText, where does it go then? and which part of the code you are placing the text "after the first line of the precodure"?

    PS: If you don't feel comfortable to answer my questions about your add-in its totally understandable!


    Sincerely.

  11. #11
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,148

    Re: Continuous Line Numbering

    You are free to do anything you want with my code or any other code posted on this site.

    CODE_PREFIX is just a Const with the value "Const PROC_NAME = " and it is only used as part of the text in the InputBox that is used to get the user's input. (I don't know why I did it that way.) Whatever is entered in that InputBox winds up in MarkerText which is a Private Property of frmModules. If you are not familiar with Private Properties they are properties associated with a form just like Height and Width but in this case they are programmer-created. So just like I can say frmModules.Height = 3000 or Height = 3000 which has the same effect because frmModules is the default location, I can say MarketText = "Debug.Print" or as in my program have an InputBox that gets the value from the user. I could have done the same thing by making MarkerText a global variable but Properties are more powerful. So to make a long story short, MarkerText doesn't go anywhere; it's just a value available to the program.

  12. #12

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    58

    Re: Continuous Line Numbering

    MartinLiss,

    Thanks for the permission first.

    Yes, I got the idea of these variables and also properties. Now I found out that the 'insert text into each function' part is done inside connect.Dsr, inside cbeProcName_Click(am i correct?!). My questions:

    1. Which part are you defining that the desired text should be placed 'after the first line of each procedure'?

    2. In my logic, when it's possible to add something at the 'second line' of the code, it should be possible to add something at the end of the function, if it is so, in which function(cbeProcName_Click -> "For lngIndex = 1 To .VBComponents.Count" ? which line then?!) and by which variables I should define that?


    Thanks in advance.

  13. #13
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,148

    Re: Continuous Line Numbering

    Yes, you are correct and the actual insertion process starts at line 1490.

    1) I don't really understand the question, but if you are asking where to find what is inserted in the Sub or Procedure, then look for MarkerText in cbeProcName_Click and I'm sure you can figure out what's going on.

    2) The code starting at line 2170 inserts the new line of code with the actual insertion being done at line 2200 via the InsertLines method of VBComponents. It's just a loop that loops through all the lines in the procedure and it shouldn't be difficult to locate the second or last line and then insert before or after that line.

    BTW to really understand what's going on in this add-in and/or if you want to write add-ins of your own let me suggest the book (which may no longer be in print) that got me started called Developing Visual Basic Add-ins by Steven Roman published by O'Reilly, ISBN 1-56592-527-0.

  14. #14

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    58

    Re: Continuous Line Numbering

    MartinLiss,

    Thank you for your explanations. I am working on it, trying to get it work. Thanks anyway, I will post again if I have any question. I have already given the reputations i was supposed to

  15. #15

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    58

    Re: Continuous Line Numbering

    Dear MartinLiss,

    I was trying to get the function working for my case, apparently it's not that much clear to me.

    What I know is that, in Connect.Dsr:

    intStartPos = finds the beginning line of each function, which the value is 0 in any function/sub.

    I was trying to create another value in here to find the 'last line' of each function and just write before that, but I couldn't do so.

    Can you help me in this one also? You know I want some codes to appear at the beginning and also ending of each functions; like if we have (I want the bold lines to be written by the code:

    Function Test()
    This is first line

    ...
    ...
    ...

    This is last line
    End Function


    Ill appreciate it if you can tell me how do you write that part in the for loop to find IntEndPos (last line of the function).
    Thank you so much.

  16. #16

  17. #17

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    58

    Error 9 (Subscript out of range) in calling function?!

    Ok. Thank you Martin and everyone else. I am done with the error handling function. It now successfully adds I need at the beginning and also the ending of a function.

    Now I am facing a problem. There was a problem somewhere in the code that I couldn't know where is that. Using this error handler, I found out the line number of the error. I wondered that I am facing Error 9 (subscript out of range) in calling a function. Any idea is it possible or not?

    Actually, I can not test it very easily. I took the code to be running for 5 days and finally it faced the error and shown the line number. The code is like this:

    1 ...
    2 ...
    3 Call Myfunction(val(MyNumericStringVariable)) ***
    4 ...
    5 ...
    6 ...

    First, I thought its because of the code written inside the function. But in that case it does not say line number 3, is it? It says the line number that is within the MyFunction code.

    I just want to know is it possible to get Error 9 out of calling a function or not?


    Thanks.

  18. #18
    PowerPoster
    Join Date
    Dec 2004
    Posts
    24,852

    Re: Continuous Line Numbering

    what is the function declaration?
    private function myfunction(x as ....... ?
    or what is the entire function?

    what is the value of mynumericstringvariable when the error occurs?
    Last edited by westconn1; Oct 8th, 2010 at 04:23 AM.
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  19. #19
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,415

    Re: Continuous Line Numbering

    If you don't have error handling within the function itself, an error in it could well be reported on the line that calls it.

  20. #20

    Thread Starter
    Member
    Join Date
    May 2010
    Posts
    58

    Re: Continuous Line Numbering

    Hello all,

    Thank everyone for the great comments. The problem is solved and I am going to tag this thread.

    Surely after crediting users


    See you in other threads.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width