Can anyone help me with the following issue?
I’ve made several templates which executes an «autonew» macro with a
dialog box containing a «DropListBox». To use the dialog boxes, I have
to define the «DropListBox» matrix at the start of every «autonew»
macro. This makes no sense because the information in the
«DropListBox» is the same for every template and it complicates the
maintenance of the macros. Therefore I would like to keep all the
standard information in a «global macro» and do a «call» to this
macro. Is this possible?
As an example on how I have done it, look at the following example
with the definition of the «DropListBox» matrix and two different
dialog boxes:
This is the start of every «autonew» macro:
Dim Lokasjon$(4)
Lokasjon$(0) = "Test" :
Lokasjon$(1) = "Test1" :
Lokasjon$(2) = "Test2" :
Lokasjon$(3) = "Test3" :
Lokasjon$(4) = "Test4" :
This is dialog example 1:
Begin Dialog UserDialog 389, 299, "Standard brev"
GroupBox 10, 6, 368, 123, "Mottakerinfo"
Text 20, 24, 61, 13, "&Firma:"
TextBox 108, 21, 250, 18, .tilfirma
Text 20, 45, 63, 13, "&Adresse:"
TextBox 108, 42, 250, 18, .Adresse
Text 20, 66, 72, 13, "&Postadr.:"
TextBox 108, 63, 250, 18, .postadr
Text 20, 87, 63, 13, "&Deres ref.:"
TextBox 108, 84, 150, 18, .deres
Text 20, 108, 64, 13, "&Overskrift:"
TextBox 108, 105, 250, 18, .overskrift
GroupBox 10, 134, 366, 132, "Avsenderinfo"
Text 18, 152, 64, 13, "&Lokasjon:"
DropListBox 106, 152, 250, 104, Lokasjon$(), .lokasjon
Text 18, 203, 55, 13, "A&vsender:"
TextBox 106, 200, 150, 18, .avsender
Text 18, 224, 36, 13, "&Tittel:"
TextBox 106, 221, 150, 18, .Tittel
Text 18, 245, 44, 13, "E&mail:"
TextBox 106, 242, 250, 18, .email
OKButton 151, 272, 88, 21
End Dialog
Dim test1 As UserDialog
Dialog test1
This is dialog example 2:
Begin Dialog UserDialog 389, 297, "Standard telefax"
GroupBox 10, 6, 368, 123, "Mottakerinfo"
Text 20, 24, 44, 13, "&Firma:"
TextBox 108, 21, 250, 18, .tilfirma
Text 20, 45, 73, 13, "&Deres ref.:"
TextBox 108, 42, 150, 18, .deres
Text 20, 66, 57, 13, "T&elefax:"
TextBox 108, 63, 150, 18, .tilfax
Text 20, 87, 32, 13, "&Sak:"
TextBox 108, 84, 250, 18, .overskrift
Text 20, 108, 70, 13, "&Ant. sider:"
TextBox 108, 105, 50, 18, .Sider
GroupBox 10, 134, 366, 132, "Avsenderinfo"
Text 18, 152, 68, 13, "&Lokasjon:"
DropListBox 106, 152, 250, 104, Lokasjon$(), .lokasjon
Text 18, 203, 71, 13, "A&vsender:"
TextBox 106, 200, 150, 18, .avsender
Text 18, 224, 40, 13, "&Tittel:"
TextBox 106, 221, 150, 18, .Tittel
Text 18, 245, 44, 13, "E&mail:"
TextBox 106, 242, 250, 18, .email
OKButton 152, 270, 88, 21
End Dialog
Dim test2 As UserDialog
Dialog test2
Thanks and kind regards,
/Jan
---
Jan Westgaard
Jan.We...@tapir.ntnu.no
: Dim test1 As UserDialog
: Dialog test1
: Dim test2 As UserDialog
: Dialog test2
: Thanks and kind regards,
: /Jan
: ---
: Jan Westgaard
: Jan.We...@tapir.ntnu.no
You're definitely on the right track in seeking to remove redundant code
from your macro system. You could initialize your Lokasjon$() string
array in one place by putting into a global template a function to size
the array and a subroutine to load it. The function and the subroutine
could then be called by any of your other macros.
The Lokasjon$() function and subroutine could reside in one macro in
normal.dot, but since you're obviously developing a complex macro system,
you might prefer to create a general purpose macro library template that
could do this job and others which you'll think of later. You could then
put this template in the User Templates directory and let Word
automatically load it as a global template.
Or, if your needs are more complex, you could create custom macro library
templates for different groups of users. The macro library template for
each group could then be put in a network directory only available to
members of that group. An AutoExec macro (or a macro specified on the
command line) could use Environ$() to get the name of the users group from
an environment variable or could use some other identification scheme,
then load the appropriate macro library template. In this way, your
network can enforce security, simplify your Word macros and avoid
duplicate code.
The example below assumes that there is such a loaded global template
with a macro named Lokasjon. A macro that uses the Lokasjon$() calls the
Lokasjon macro twice. The first time it calls the initArray function to
get the size of the array. The second time it calls the loadArray
subroutine to fill the array. The Lokasjon macro has a Sub Main, as
usual, but there is no code in it since its functions and subroutines are
intended to be called directly.
'Lokasjon macro in a loaded global template
Sub MAIN
End Sub
Function initArray
initArray = 5
End Function
Sub fillArray(anArray$())
anArray$(0) = "Test"
anArray$(1) = "Test1"
anArray$(2) = "Test2"
anArray$(3) = "Test3"
anArray$(4) = "Test4"
End Sub
'another macro which calls Lokasjon
Sub main
arraySize = Lokasjon.initArray
Dim Lokasjon$(arraySize)
Lokasjon.fillArray(Lokasjon$())
' testing code to display Lokasjon$() contents
For n = 0 To arraySize - 1
a$ = a$ + Lokasjon$(n) + Chr$(13)
Next n
MsgBox Str$(arraySize) + Chr$(13) + a$
End Sub
Richard Anderson
r...@netcom.com
--