# Off Topic > The Water Cooler >  >  Who uses line numbers in their code?

## JapanDave

Just curious as to if anyone uses them? I am doing a really big project right now and I need to create error logs and they are pretty much useless unless I get what line the error occured on. And in VBA the only way to get this with native tools is to number your lines.

----------


## xladept

Not for 35 years or more.  Maybe you could try "modular" programming.

Hey Dave,

This works:




```
Please Login or Register  to view this content.
```

----------


## JapanDave

Are you talking about code for editing modules?
I have been experimenting with this of late,



```
Please Login or Register  to view this content.
```


But ,there is nothing that allows you to know what line you are on, UNLESS you have them number.

Also, I think I left my brain at home, as I don't know what you are trying to show me with that code???

----------


## xladept

Well, Dave, I just put numbers on the lines and it looks like the VBA will still take line numbers.  But, for modular, I meant you could write short routines or functions and just call them in order, to whit:




```
Please Login or Register  to view this content.
```

----------


## Kyle123

I don't for vba, but if you use the mztools addin it's pretty trivial - one click to add them and one click to remove

----------


## JapanDave

> I don't for vba, but if you use the mztools addin it's pretty trivial - one click to add them and one click to remove



Hey Kyle,
It is not the line numbers, I made a short piece of code to do that. It is the error trapping that I am concerned with. I know MZ-Tools has something tells you what line the error was on. It is the fact that VBA lacks the tools to do thorough error trapping.

----------


## grimes0332

> And in VBA the only way to get this with native tools is to number your lines



Not sure if you mean the undocumented ERL() function which returns the last line number passed in the code...




```
Please Login or Register  to view this content.
```


Line numbers can be on a line by themselves, part of the executable line, do not have to the contiguous or even in order. The only restriction is they must be at the start of the line before any executable statement and be numeric (Both reasonably obvious). You can have 'sparse' line numbers where only the 'critical' lines are numbered. VBA just remembers the last line number passed. If no line numbers exist in the procedure, ERL returns 0.

Sample error log (The tabs don't show):

Date            Time            User            Machine         Line No Procedure Name  Module Name     Error   Error Description
------------------------------------------------------------------------------------------------------------------------------------------------------
20150314        15:43:42        Me              MINE            000000  PROPERTY:FILENA FRMSPLASH       000091  Object variable or With block variable not set
20150730        13:49:41        Me              MINE            011110  STATUSPOPUP     FRMX            000005  Invalid procedure call or argument
20150730        13:49:41        Me              MINE            011310  STATUSPOPUP     FRMX            000091  Object variable or With block variable not set


I'll answer your poll with a Yes. I don't always use them and don't use them on every line, but they are used extensively. Even if the code has been 'normalised' and broken down into short procedures there can be 2 or 3 critical lines in a procedure where you would like to know which one errored...

----------


## snb

Not a bad idea:




```
Please Login or Register  to view this content.
```

----------


## JapanDave

> Not sure if you mean the undocumented ERL() function which returns the last line number passed in the code...
> 
> 
> 
> 
> ```
> Please Login or Register  to view this content.
> ```
> 
> ...



It was in my first post, I know how to trap errors and the line number via "erl". I think there is a big misunderstanding here ,my point I was making was that the ONLY way to get line numbers was to have them in the code, hence my question "Who puts line numbers in their code?"

----------


## grimes0332

> It was in my first post...



You never mentioned specifically, only alluded to it. Bringing it out into the open might be helpful for others, though.

----------


## ranman256

Line numbers died out with the dinosaurs.

----------


## xladept

Another thing that's gone the way of the Dinosaurs is Flowcharting - but, if you have an hundred or more page program, as sometimes happened in the days of yore, you might want to consider Flowcharting. :EEK!: 

BTW: Procedure Names in code seem to also be atrophying.

----------


## Kyle123

> BTW: Procedure Names in code seem to also be atrophying.



In what way?

----------


## xladept

Hi Kyle,

I just posted this code correction - do you see a procedure name?  I guess recursion is obviated by the looping features.  Anyway, it's been on the back of my mind, so I just threw it out there :Smilie: 




```
Please Login or Register  to view this content.
```

----------


## grimes0332

> Line numbers died out with the dinosaurs



True, as far as they are needed as the target of a GoTo (also not extinct are GoSub, and Return) - but do you have any other way to easily identify where an error occurred in a procedure?

Don't dismiss something just because it's 'considered obsolete'. After all the Goto statement is still in regular use. Try using that anywhere except setting up an error handler and see the reaction.

----------


## xladept

Hi Grimes,

I still use GoSub.....Return :Smilie:   I posted code with about 7 (all to the same procedure) of them just yesterday :Smilie:

----------


## Kyle123

Sorry, you've lost me. A re you referring to the fact that the procedure name is completely useless in establishing what the sub actually does?

----------


## Richard Buttrey

Hi Dave.
"And in VBA the only way to get this with native tools is to number your lines."

Is that necessarily the case?
Why not use the O n Error and O n Error Goto 0 statements sprinkled through your code and pass some appropriate text comment each time to an independent error logging procedure.

I realise one should never say never but I was always encouraged to avoid line numbers for program control since it can lead to spaghetti code. I know you are not wanting to use line numbers for program flow in this case - or at least I think that's what you're saying but passing some comment to a procedure when an error occurs seems a more natural way to deal with this.

----------


## xladept

I don't mean anything like that - I'm just saying that most coding that I've seen lately is designed to let the process just "fall through" thus not necessitating Procedure Names.  It's good design. But, then :Confused: 


BTW: WTF is "spaghetti code" and where did the term originate - did some Pundit invent it for personal notoriety?

----------


## Kyle123

Spaghetti code is when you use line numbers for things like loops rather than a loop or writing just one procedure with things like if X goto 4

----------


## xladept

Thanks Kyle,  a couple of years ago, someone accused me of spaghetti code because of my fondness for GoSub....Return.  I've been wondering what they were talking about.  This must have all happened after my involvement with Programming. (IBM School 1965).

----------


## grimes0332

My last word...




> but I was always encouraged to avoid line numbers for program control since it can lead to spaghetti code



Agree totally.

The line numbers are not used to control program flow; just as an easy, efficient way to 'record the progress' of the code through the procedure, _where needed_. 

I see no one else has confessed to using line numbers in the poil - I stand proudly alone (Not an unusual ocurrance, mind).

----------


## TMS

I answered "no" and I never, ever, use line numbers.  If you do want/need to use GoTo, you can use a label ... but, as has been alluded to, use of GoTo is frowned upon (in polite circles  :Wink:  ).  Better to use structured programming (  :Smilie:  ).  And, when I first learned to code, and use structured programming AND flowchart, the guideline was that the flowchart for a module should fit on an A4 sheet of paper (and not be so tiny you couldn't read it).  The module should have a specific, limited function with a single entry point, a single exit point, one or more defined inputs and one or more defined outputs.

So, the structure would start with a Main, or Master, module which called sub-modules.  Each sub-module would call other sub-modules until, eventually, you called sub-modules that actually did something.  Module names should be descriptive, such as, InputData, AnalyseData, PrintData, etc.

Regards, TMS

----------


## TMS

Using Line Numbers is a PiTA.  You need to start with huge gaps in the sequence in order to allow the insertion of additional lines of code.  If you don't spread the numbers out, you end up having to re-number them ... and change all the GoTos

----------


## xladept

@ Trevor - wholeheartedly agree :Smilie:   But, I like a GoTo once in a while (to paraphrase Oscar Wilde) :Smilie:

----------


## Richard Buttrey

> BTW: WTF is "spaghetti code" and where did the term originate - did some Pundit invent it for personal notoriety?



Not entirely sure of the etymology although I seem to remember first becoming aware it back in the heady days of the ZX81 (with 1Kb RAM!)  back at the start of the 80s when line numbering was a BASIC requirement and the only way to direct process flow.

----------


## JapanDave

On error Goto is all well and good, but when you want to get detailed logs of what is happening and where, I feel it is pretty important to be able to pin point where and why something has happened. No code is flawless and the user can and will do what you don't expect. Especially when working with languages other than English. We have double byte characters and they cause enough headaches.

Other languages allow for native procedures to get line numbers etc.

Eg, the below is an example of what I am talking about.




```
Please Login or Register  to view this content.
```


They look the same in Excel and cause grief to no end. And yes, I try to convert to single byte wherever I can using this,




```
Please Login or Register  to view this content.
```

----------


## xladept

@ Richard - Thanks for the information :Smilie:

----------


## snb

What about debug.print module.name & macro/function.name in every macro/ function
At least you know - consulting the immediate window - in which macro/function something went wrong.




```
Please Login or Register  to view this content.
```

----------


## Izandol

Is easy to find error if you do not use error handler except when you expect error. For user testing is much faster than to read error log.

----------


## JapanDave

> What about debug.print module.name & macro/function.name in every macro/ function
> At least you know - consulting the immediate window - in which macro/function something went wrong.
> 
> 
> 
> 
> ```
> Please Login or Register  to view this content.
> ```



I agree that knowing those are important, but line specific is also very important I feel.

----------


## JapanDave

> Is easy to find error if you do not use error handler except when you expect error. For user testing is much faster than to read error log.



And you can expect all errors can you? You are better than me.

----------


## Izandol

Of course not - that is purpose of this method. Debugger shows error during testing and I fix it. Is easier because I have all variables available and user can tell exactly what he did.

----------


## Richard Buttrey

Re posts #32 & #33.

I think this essentially boils down to for whom is the logger required and what Dave means by 'errors' for his error log? 

Is Dave wanting to trap system coding errors and report these in a neat log for himself as the developer, or is he wanting the system to report user input/handling errors FOR the user so that they may review the log and take any appropriate action in a controlled way.

When developing and like Izandol I prefer to have the system fall over and stop with the yellow highlight so that I know exactly which line causes the problem. As a user though (and particularly if the user doesn't have any idea what macro code is) that's the last thing I want to see.

I sort of agree with you both. It just depends from where you're approaching the question.

----------


## Doc.AElstein

*@ JapanDave
Hi JapanDave*
  I still like to use Line Numbers sometimes. I still think it is a good way to reference a “Line”..*** I find it useful for, as you have suggested, into specifically referencing a point where, for example, an error occurred, or in general I find it helpful when explaining a code to someone..
http://www.excelforum.com/developmen...ml#post4198803
*  Given my limited experience compared to the others replying to this Thread, I expect my conclusion would then still have to be they are to be avoided!! – If I am using them they are probably bad!!*  :Smilie: 

* Just out of interest though…*
*_1 )* I would always put them in after at a point when I was fairly sure the code was finished, and number 10, 20, 30 etc to allow for the possible additions later between lines. And be liberal with a few empty numbered lines, again to allow for inserting lines later.  
*
_ 2) How to put them In   ?…
*_ …I use the technique of copying the whole code and pasting it into a spare Excel Spreadsheet column, then adding each row  to an adjacent column of numbers, then copying the final value back to the Code Window…
Row\Col
E
F
G

*24*
10 

10  

*25*
20 
Rem 2) Error handling
20  Rem 2) Error handling

*26*
30 
'2a) An Error handler is made availble and VBA instructed to use it on passing the next line.
30  '2a) An Error handler is made availble and VBA instructed to use it on passing the next line.



Row\Col
G

*24*
=E24 & " " &F24

*25*
=E25 & " " &F25

*26*
=E26 & " " &F26




 I guess the above is as outdated as my ideas about using Line Numbers…. 



> ..... the line numbers, I* made a short piece of code* to do that. ......



*…  Could you share / explain* that code?
 
_ 3) I am not sure if VBA is clear on its concept of counting a code "Line" or Lines….****
http://www.mrexcel.com/forum/lounge-...ml#post4387604
For example is this “Line” _....  



```
Please Login or Register  to view this content.
```


_......  one Line or two “Lines” . VBA will not allow me to give the second “Line” a number like this



```
Please Login or Register  to view this content.
```


_.....................................................


Here an example of when I would find having Line numbers useful:--- how I would demo… the difference between Error HandlING Statements….._
On Error Goto 0
And
On Error Goto -1
These two can be thought of as sending the Error to some imaginary points…. Or Lines with numbers  0  and -  1

_.....  Using then line numbers to assist….
_ Here first the code with Line Numbers:



```
Please Login or Register  to view this content.
```


_ Here the explanations:

_a) Run the code preferably in Debug ( F8 ) Mode. You will see that the Error HandlER “made available” in line 40 and “switched on” by line 90 will only work once.  This is because VBA is in what is called an “exceptional” state. In this case VBA is being instructed that an Error HandlER is ”in control". Further attempts to “instruct” VBA what to do in the case of an error are ignored. And so further errors are responded to normally.  

_b) Include line 180 ( On Error Goto -1 ) and run again. You will see that the Error HandlER from line 40 works over and over again. Note that in this further ( infinite ) looping, we return from the Error handling code section “ErrHandlERSection1” ( Code Lines 150 to 200 ) to line 60. We do not therefore go through line 40. However the original error handler is still “made available” and ready for use, that is to say, will be switched on by the next error.  The Error HandlING Statement, On Error Goto -1, has “switched off”  this Error HandlER from Line 60, and cleared the “exceptional VBA State”. But it does not “remove” the “availability” of , or instruction to VBA to use, that original Error HandlER

_c) Include also now Line 190 ( On Error Goto 0 ) and run again. Now the Error handler will only work once. This is because  the additional On Error Goto 0 has “removed” or “Stopped being available” any Error handler in place

_d) If you further change line 200 to read
200  GoTo 40
And run the code again , then the Error HandlER will work over and over again as line 40 will continually “re - switch it on”

_................................

* I personally find that all a lot easier to explain when I have line numbers.


Alan*

P.s. Please Let me ….. :Roll Eyes (Sarcastic): 

..........................................................................
References:
http://www.excelforum.com/excel-new-...ml#post4017218
http://excelmatters.com/2015/03/17/on-error-wtf/
https://app.box.com/s/8zkhjcmbxrqnlnexqpktuy41clgqm4zo
http://www.mrexcel.com/forum/excel-q...ml#post4357653

----------


## Doc.AElstein

@ grimes0332
Hi grimes0332,
Thanks for the  Erl() function..  ....Another useful undocumented ( in VBA ) thing.

Alan
P.s. In my code from Post #35,  Erl() gives me the line number just before the Line where the error occurred. 
_... So does snb’s, if he has a Line number before



```
Please Login or Register  to view this content.
```


P.P.s…. Try a line number > 65535  !!  
P.P.P.s.. * Does Erl()  have an optional argument … I mean what is the significance and use ( if any ) of the ()*?
*EDIT* Ah, OK I missed that Erl() gives by design the last line before the error line,.

----------


## xladept

Well, if you guys are going to make mistakes :Cool:

----------


## SpectateSwamp

I put the line numbers that are in the code on the flowchart elements. 

pict01.jpg

pict02.jpg

This flowchart does the line wrap / hi-lite for my custom search / cms app.

here is the source code... It's a few years old but this part hasn't changed

Please please show me how you would code up this routine.....

http://www.telusplanet.net/public/stonedan/source.txt

----------


## Doc.AElstein

> I put the line numbers that are in the code on the flowchart elements. 
> 
> This flowchart does the line wrap / hi-lite for my custom search / cms app.
> 
> here is the source code... It's a few years old but this part hasn't changed
> 
> Please please show me how you would code up this routine.....
> 
> http://www.telusplanet.net/public/stonedan/source.txt



 :EEK!: 
I am not sure what you want excactly.

I put some code lines on. 

It is not perfect

Alan

( I did not do it manually !!! )

----------


## Olly

If I anticipate an error in "normal" usage, I use (for example)



```
Please Login or Register  to view this content.
```


If I'm still developing / debugging, I'd rather catch the unhandled errors using the built in debugger.

Line numbers?! No thanks!

----------


## JapanDave

@Olly, that all well and good when it is you debuging the code. But, what happens when you send that file off to the users and all you have to go on is this '"ERROR", Err.Number, Err.Source, Err.Description'. You have no idea where it happened in a lot of cases. Eg, a 'Runtime error' , could happen in any number of places.

----------


## xladept

I hope that once I've sold a routine that the bugs are caused by improper handling and that I have protected for "bad" data :EEK!:

----------


## SpectateSwamp

I use pseudo line numbers..

Line_number = "line 1000"
input data
line_number = "line 1010"
Check data.

With everything handled by a common error section.
Those errors that aren't trapped get put to a log file for sorting later.

When one locally traps every error that can possibly occur... Code becomes hard to understand..

Structured Coders can't jam-it / trial and error test like us noodlers. 

When you have problems with code do a quick FlowChart.

----------


## Doc.AElstein

Hi SpectateSwamp
Did you catch post #39
http://www.excelforum.com/showthread...06#post4450133
Alan

----------


## snb

Your post cannot be seen because of a modulo error in this forum's software.

----------


## Doc.AElstein

> Your post cannot be seen because of a modulo error in this forum's software.



Hi snb
who are you talking to ?
Alan

P.s.
if you aretalikng about this;
http://www.excelforum.com/suggestion...-not-exis.html

-..The point was that I did not actually post.

----------


## SpectateSwamp

> Hi SpectateSwamp
> Did you catch post #39
> http://www.excelforum.com/showthread...06#post4450133
> Alan





For those that are against line numbers... Do your thing.. But leave us alone. Or we will do code reviews on your pathetic offerings.

----------


## Doc.AElstein

> For those that are against line numbers... Do your thing.. But leave us alone. Or we will do code reviews on your pathetic offerings.



Lol.. Don’t be too aggressive though.

_.. In the meantime I have found line numbers most use in helping to explain Code I pass on in this forum... as well as for the Erl() stuff mentioned all in this Thread.
http://www.excelforum.com/the-water-...ml#post4293426

But sometimes , like today, I get really naffed off with my own offerings with code lines when I want to modify or just take parts from a code..

_..so  _ I already have a code which puts in the code lines at a flash...... so I did a quick Antidote today and did a code to wipe them out and put the code back as it originally was:
http://www.excelforum.com/showthread...t=#post4488539

_  Now there is a positive contribution to our acceptance_.. if you can wipe the code lines out at a flash, then it is not too bad to have them given Line numbers in, may be
 :Smilie: 

Alan

P.s. The latest of my codes for “putting them in” is here_..
http://www.excelforum.com/showthread...t=#post4488352
_....not perfect yet, but not too bad.

Edit:  26th Sept 2016  I updated my codes a bit:
http://www.excelforum.com/showthread...09#post4489109

----------


## sanram

I am not sure that what are you trying to achieve. But if it's about line number only then it can be done by this.



```
Please Login or Register  to view this content.
```


But actually I am not sure about your question.

----------


## sanram

Also this one works for me :



```
Please Login or Register  to view this content.
```

----------


## Doc.AElstein

Hi sanran




> ...
> But actually I am not sure about your question.



In this Thread we are discussing generally the use of *Line Numbers* in code.

*Line Numbers*

Your second code uses *Line Numbers.* 



```
Please Login or Register  to view this content.
```


We have been discussing the use of these. We are interested in any opinions. The Thread is asking if people use* line numbers*. I for example use them freqeuntly,
http://www.excelforum.com/showthread...t=#post4488539

See also in the Thread we are now in ( see in side 2 of the Thread we are now in:
http://www.excelforum.com/the-water-...ml#post4293426     )
In this code I am using* Line numbers* and two labels,  ErrHandlERSection1: and CreateError:



```
Please Login or Register  to view this content.
```


_.........................
_._____________________________________________________________________

*Labels*





> I am not sure that what are you trying to achieve. But if it's about line number only then it can be done by this.
> 
> 
> 
> ```
> Please Login or Register  to view this content.
> ```
> 
> 
> ....



I think you are incorrect. 

Your first Code is using *Labels.*
https://www.youtube.com/watch?v=cE1NOfyz04Y

Your first code only has* Labels*. it has no Line Numbers



```
Please Login or Register  to view this content.
```



This is how my code would look like with* labels* instead of line numbers




```
Please Login or Register  to view this content.
```


or




```
Please Login or Register  to view this content.
```


_..................................


Do you see the difference?

I can use either *150:** or** ErrHandlERSection1:* as a label. They are both labels. I* cannot* use them both on the same line.

But I* can* use a* Line Number* and a* Label* on the same line
150 ErrHandlERSection1:

*
Alan*

----------


## sanram

Okay. I got it now.

----------


## Doc.AElstein

> Okay. I got it now.



Glad to help with your understanding....   :Roll Eyes (Sarcastic): 
Alan

----------


## Doc.AElstein

Duplicate Post

----------


## Doc.AElstein

*While I am here*_..... that last bit of label Line stuff made me think:::  my codes did not catch GoTo Line Numbers and the such .. and nor did a lot others i googled...

Actuallyy, I Googled quite a bit on looking for code alternatives to mine for putting in and taking off  line Numbers. There are a few but i could not get them too work. Possibly I will be enlightened in the future. In the meantime I thought no harm in “perfecting” mine a bit further..

So, A couple of problems I noticed. 

*_1 )* if you have a code line like_...
_______  GoTo *234* 
_.. where *234* is an existing Line number in a code where you want to add line numbers to the complete code, then you would need to adjust those numbers manually after running a code to add Line numbers.   :Frown:    -----   But not any more with my latest code.  :Smilie: 

*_2 )* On my code to remove Line numbers, then you can get a problem with any Labels. ( Like _....
*Label_X:* 
_......etc ) 

This is because if my code that puts the label in, pasts out like this ( like what it does ) _...

20 ___*LabulX:*

_...then  the VB Editor “_eats_” the extra spaces and changes it to  this:

*20 LabulX:*

My code for taking off Code lines was then was getting a bit “out of wack” , which resulted in some labels getting a bit truncated, like

*bulX*

( Bollox !  :Frown:  ) _....
_....But never mind I fixed that as well  :Smilie: 

_.......

*Here is a good example* 
Say I start with this code, which is messy, but works:




```
Please Login or Register  to view this content.
```


I copy that to the Clipboard ( Highlight Code and Hit *Ctrl+C* )
I run my code
Sub InsertLineNo_A8()
That puts the modified code with Line Numbers in the Clipboard
I paste it out ( *Ctrl+V* ) and get this:




```
Please Login or Register  to view this content.
```


I copy that to the Clipboard
I run my code
Sub CodLnsWeg_A8()
That puts the modified code without Line Numbers in the Clipboard
I paste it out and get this:




```
Please Login or Register  to view this content.
```


I copy that to the Clipboard
I run my code
Sub InsertLineNo_A8()
That puts the modified code with Line Numbers in the Clipboard
I paste it out and get this:




```
Please Login or Register  to view this content.
```


I copy that to the Clipboard
I run my ....... etc... etc.....

_................................................

The codes are in their ‘Explicit Pedantry Form to help further the understanding of mankind.. 
If I get around to sanitising them and maybe catch anything else non perfekt in them then I will maybe do a post in *Tips and Tutorials Sub Forum*. For now someone might find them useful..

*Alan*
_.....................

Code:
Sub InsertLineNo_A8()
( All one code: I had to split it due to Post size limits. Each code section should be copied directly under the previous in the same Code Module )
http://www.excelforum.com/showthread...t=#post4489052
http://www.excelforum.com/showthread...t=#post4489054


and likewise for
Sub CodLnsWeg_A8()
http://www.excelforum.com/showthread...t=#post4489061
http://www.excelforum.com/showthread...t=#post4489065

----------


## snb

@DocE

Put this code in de codemodule of sheet1.
Run the macro: M_snb




```
Please Login or Register  to view this content.
```

----------


## Doc.AElstein

Hi snb, Thanks for that.
_....

I have all the following codes in my Worksheets Code Module with Code name "Tabelle1"

Then,

This




```
Please Login or Register  to view this content.
```


-.. after running this




```
Please Login or Register  to view this content.
```


_.. gives this




```
Please Login or Register  to view this content.
```


_.............................................._______________________________-

And this




```
Please Login or Register  to view this content.
```


_...after running this




```
Please Login or Register  to view this content.
```


_... gives this




```
Please Login or Register  to view this content.
```


_.........................
__________
 and this: 




```
Please Login or Register  to view this content.
```


_.. after running this:




```
Please Login or Register  to view this content.
```


_.. gives this:

_....... a mess !

_ But for adding lines it is a nice alternative.  :Smilie:  
_ It keeps a constant indent ( for all but labels ) when the number of digits change, like

90__'''
100_'''

_ I note that the second code must go directly after the first.



_  otherwise,  as usual.... I have not got a clue how it works   :Frown: 

_ Eventually I will suss it may be
 :Smilie: 

Alan

----------


## snb

It was only meant for adding line numbers (not adding lines....). But apparently you found out yourself.  :Wink:  

So if you 'misuse' the code: mess in, mess out.




```
Please Login or Register  to view this content.
```

----------


## Doc.AElstein

> It was only meant for adding line numbers...
> _.......
> Sub M_snb_numberout()
> _.......
> _......
> _............



Thanks snb.
 It’s a very nice compact code for adding Line numbers.   :Smilie:   Works great
http://www.excelforum.com/showthread...t=#post4489718
http://www.excelforum.com/showthread...=3#post4489721

I’d use it more if I understood it  :Smilie: 

Thanks for the Number out code_................
Sub M_snb_numberout()
_.............well.
I had to fight a little bit with that..........

_1 ) It errors if a line has no code and just a line number.
_ I did a quick correction for that:
http://www.excelforum.com/showthread...t=#post4489734

then

_2 ) I noticed it leaves a small offset at the early lines. 
http://www.excelforum.com/showthread...t=#post4489734
Possibly that does not always occur depending on tab settings? .  I see you are using a Tab in your code, but I do not quite understand what you are doing there.


Anyway, I played around a bit, ( and messed it up a bit  :Smilie:  )  -...--   and came up with a messy version that knocks out those extra indents.
http://www.excelforum.com/showthread...t=#post4489792


Alan
 :Smilie:

----------


## snb

a new post to show the others.

----------


## Doc.AElstein

Hi snb
FWIW.  I keep my latest version of a code to put in or take off code lines in the Code module *CodeLines* in this File which I keep up to date. 
https://app.box.com/s/zhz7awdag4nl1zs6564s9zzcwp50e4w9
I am at A8 I think now
Sub InsertLineNo_A8() ‘ To Put in
Sub CodLnsWeg_A8() ‘ To take out

The codes are messy with all my usual unnecessary stuff and ‘Comments etc. 
But I find them useful.
They also now deal with GoTo ‘s, so if you have existing GoTo ‘s  with numbers then it catches them and corrects for that. They are almost certainly not perfect. As time goes by I notice Bugs or things not quite working so I update the code and put the next version in that File. ( A9 would be the next etc )

The way the codes work is that you highlight a code, copy it to the clipboard, then run the Put in or take out Code Lines Code. The modified code is then in the Clipboard so if you paste back out over your selection then you should get the modified version of your code. ( or paste it out somewhere else ). The code that puts Code lines in also adds a temporary Worksheet in the current Active Workbook with the code in which you can chose to delete or not through the normal Default Display warning that pops up when the code attempts to delete it. ) 

Here I just posted the current codes  again :
*Version A8*

Sub InsertLineNo_*A8*() ‘ To Put in

( All one code I just had to split it in three parts due to post size restrictions )

http://www.excelforum.com/showthread...t=#post4525293
http://www.excelforum.com/showthread...t=#post4525301
http://www.excelforum.com/showthread...t=#post4525305


_......

Sub CodLnsWeg_*A8*()

( All one code I just had to split it in two parts due to post size restrictions )

http://www.excelforum.com/showthread...t=#post4525308
http://www.excelforum.com/showthread...t=#post4525316


Alan

BTW.* Post # 17*
http://www.excelforum.com/showthread...t=#post4291625
mention  some M Z tool 
I guess that Tool is probably a much better alternative to mine.

I think it costs though. That tends to put me off, not that I mind paying necessarily for stuff, but I find then you get in a trap of having to keep updating things

----------


## SpectateSwamp

I assign a line number to a string throughout the program. 

My massive Search Engine / Multimedia Player has 10,000 plus lines
and many many goto's 

When an error occurs I check the value of the string and GoTo the error handler.

How easy it is to find source if the lines are in sequence.

Serendipity kicks in every now and again. That just doesn't happen with structured code. Nope

----------

