GSAK (Geocaching Swiss Army Knife) | ||
Contents
- Index
Option <Explicit=Yes|No> Explicit declaration of macro variables. If you are familiar with visual basic (or basic?) then you know exactly what the Option Explicit command is about. Like basic, GSAK currently defines variable types "on the fly". The problem with this approach is that it can lead to subtle program errors just because of a typing error in a variable name. The other problem I have recently found out is that "on the fly" variable generation can slow down your macro considerably, especially if you have a large number of variables and even more so if you have a large number of lines in your macro code. For small macros it probably doesn't matter, but for large macros I would very much recommend you always use Option Explicit=Yes, and declare all your variables at the start of your macro (or execute a subroutine that does this) Note: Variables used in the Form function and in form <data> statements do not have to be declared unless the variable is used before the Form() function is called. Here is an example of how this option can protect you from a typing error, even in a small macro:
Now you might be scratching your head wondering why the message box only shows the message as "part1". If you can't see the problem it is because we have used $mesage (with only one "s") on the second line. This means a new variable with the name of $mesage gets created, and the value for the existing $message remains the same. Now by using Option Explicit=yes and Declare we protect ourselves from this type of program error:
Related: Declare Alpha List Category List |
Copyright 2004-2019 CWE Computer Services Privacy Policy Contact |