I love to have a macro button that types my Corporate Name or my Email address. If you inspect the Under.dot template at the distribution site (link at foot of this post) you'll see that I've created a Toolbar "Under" and on it a new menu item "Text"; on that menu item are several buttons. I post the code for "cmd_TypeEmail" and "cmd_TypeName" below.


<pre>Public Sub ()
' Procedure : cmd_TypeEmail
' Description: Insert my electronic mail address into the current document.
' By: Chris Greaves Inc.
' Inputs: None
' Returns: None
' Assumes: Nothing
' Side Effects: None.
' Tested: By a call from the user.
Selection.TypeText strEmail
End Sub
Public Sub cmd_TypeName()
' Procedure : cmd_TypeName
' Description: Insert my corporate name into the current document.
' By: Chris Greaves Inc.
' Inputs: None
' Returns: None
' Assumes: Nothing
' Side Effects: None.
' Tested: By a call from the user.
Selection.TypeText strBusiness
End Sub
</pre>


Note that these macros (SUBroutines without parameters) appear to use string variables "strEmail" and "strBusiness". I am a cover-function freak, and I have chosen to write two FUNCTIONS "strEmail" and "strBusiness". Their code appears immediately below:

<pre>Public Function strEmail() As String
' Procedure : strEmail
' Description: Return my electronic mail address from the environment.
' By: Chris Greaves Inc.
' Inputs: None
' Returns: None
' Assumes: Nothing
' Side Effects: None.
' Tested: By a call from the user.
strEmail = strGp(strcApplication, strcModule, strcEmail, strcDefaultEmail)
End Function
Public Function strBusiness() As String
' Procedure : strBusiness
' Description: Return my corporate business name from the environment.
' By: Chris Greaves Inc.
' Inputs: None
' Returns: None
' Assumes: Nothing
' Side Effects: None.
' Tested: By a call from the user.
strBusiness = strGp(strcApplication, strcModule, strcBusiness, strcDefaultBusiness)
End Function
</pre>


These two functions are little more than cover-functions for calls to strGP, and I happen to like this method of coding, although some will disagree. I like that the "cmd_TypeEmail" and "cmd_TypeName" macros look simple, and to all intents and purposes they just type a text string.

I like that I can use my INI file routine strGp to obtain string values from the environment.

I like that strGP accesses an INI and will store and assign default values should the INI file not be fully developed. This means that a user can delete the INI file and the application will re-generate it as required automatically.

If ever I decide to use something other than an INI file to store values, I have to change only strGP and strPP; I don't have to change any other functions. I could, as an example, read the entire INI file into memory and make the strGP function look up a string array.

strGP and strPP are sometimes called Interface Functions, because they provide a well-defined interface between my application and the environment.

Keen eyes will notice a change in the arguments to strGP. I've decided to bite the proverbial and make the strGP accept both a file and a section name. I'll post the new code under the earlier thread.