Thank you Rudi,
Get table count in MS Word document
-
- NewLounger
- Posts: 1
- Joined: 25 Sep 2020, 00:46
-
- PlutoniumLounger
- Posts: 15498
- Joined: 24 Jan 2010, 23:23
- Location: brings.slot.perky
Re: Get table count in MS Word document
Hi Rudi. I won't argue.Rudi wrote: ↑19 Jan 2017, 05:35Set obj = Nothing is a standard statement used to clear object variables and basically cleans up or releases it from memory. It was good practice to use on older systems, but its a bit archaic on modern systems today and it does not really matter if you don't use it; although more pedantic coders might argue with that!
I wrestled with this when I started in Word97VBA. So many web pages said that I had to clear variables to <Nothing>, and the Word97VBA specs said I didn't have to.
Nowadays I think that the (seemingly pedantic) issue of (a) initializing variables and (b) clearing variables rests at a higher level, that of the programmer's brain.
An example: back in the Good Old Days each manufacturer's (IBM, Burroughs, Honeywell, ICL, ...) compiler (FORTRAN, COBOL, ALGOL, PL-I, ...) might or might not initialize variables. It was Good programming Practice to initialize variables in your program because when (not if!) the program was ported to a different platform, one would not have problems with UN-initialized variables.
That is, the rule about (say) setting totals to zero before a loop was a sensible precaution. Sure it was unnecessary in your IBM 1620 FORTRAN program, but when ported to a CDC 3300 or an ICL 1903A, well, there could be trouble.
To that extent I nowadays think that if I use a language says "Variables must be initialized", then it's good practice to start initializing variables in all languages I meet from that time forwards. Likewise if Set To Nothing is required in a language, then I should start setting to nothing in all languages from then on.
This might add a bit of time to writing code, but the time is nothing to that spent debugging down the road, or explaining to 10,000 unionized employees that their paychecks are late. Again. As well, the execution time is trivial with today's fast computers.
Exceptions, of course, can be made for specific low-level code such as calculating for GPS or similar low-level OS activities.
Cheers
Chris
An expensive day out: Wallet and Grimace
-
- Administrator
- Posts: 12577
- Joined: 16 Jan 2010, 15:49
- Location: London, Europe
Re: Get table count in MS Word document
Many years ago, I used to write programs that used the X-Windows library on Unix. Every call specified which variables it created, and whether it cleared them afterwards or you had to. If you got it wrong then you could either double-deallocate a piece of memory (which was usually catastrophic) or not deallocate it at all, resulting in memory leaks that eventually forced you to reboot the system because it ran out of virtual memory.
StuartR
-
- 4StarLounger
- Posts: 596
- Joined: 10 Jan 2016, 15:56
- Location: Madison, Wisconsin
Re: Get table count in MS Word document
@ChrisGreaves
The principal reason I use Option Explicit and declare all variables is so that my typos do not mess up my coding. I use interal uppercase in my variable names and when using them in code I type them in all lower case. When I go to the next line, if I have declared a variable, the editor will automatically correct to use the upper case. This is a redundant check to let me know I did not type something incorrectly.
I generally set each object to nothing at the end and set on error to goto -1 if I employed error checking.
I am a dabbler, but I've been at it a while. Other than machine code, my first programming language was also Fortran.
The principal reason I use Option Explicit and declare all variables is so that my typos do not mess up my coding. I use interal uppercase in my variable names and when using them in code I type them in all lower case. When I go to the next line, if I have declared a variable, the editor will automatically correct to use the upper case. This is a redundant check to let me know I did not type something incorrectly.
I generally set each object to nothing at the end and set on error to goto -1 if I employed error checking.
I am a dabbler, but I've been at it a while. Other than machine code, my first programming language was also Fortran.
Attorney Charles Kenyon
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word
Templates in Microsoft Word
Modifying the QAT
The Importance of Styles in Microsoft Word