L
Laurent
I've just completed my first big add-in project. The program manages
"customizable sets" of extensive Word display options. It basically
reproduces most of Word option dialog items, but save choices in separate
configuration sets that can be apply at a click of a button. The add-in
works well, is ready for multilingual use and quite fast.
My problem is bloated code, not speed, or function. It has more than 2000
lines. Maintenance is not easy.
The biggest problem I have is a long serie of variables that are part of
each parameter set, but often different data type . The number of variables
was quite small at the beginning of the project but it kept growing as I
added more and more features. (I also have to admit that I learned VB
only two weeks ago and I probably made gross design mistakes in some parts
of the coding )
For each variable, there are 10 customizable sets and 10 "factory" sets,
for a total of 20 possible and applicable sets of display parameters.
It goes a bit like this:
Public strName(10, 1) As String
Public bBlue(10, 1) As Boolean
...
... (long list)
...
Public bParagraphs(10, 1) As Boolean
Public iType(10, 1) As Integer
Public sZoomValue(10,1) as single
etc.
for about 25 different variables for each set of parameters.
Because they differed in type, I designed an option form with a mix of
checkbox, textbox, spin and combobox that display and change any set.
All operations in the add-in must repeat all the list of variables:
1. Declare variables
2. Assign hard-coded factory defaults to variable
3. Management routine to change factory default (maintenance)
4. Read custom settings from registry
5. Save custom settings to registry
6. Reset custom settings to factory default
7. Push any set content to the form
8. Put form content back to a given set
9. Apply a set of parameters (main function)
Moreover, each variable's corresponding component on the form has a name
much similar to the variable name and can have:
10. Assigned caption from external source (for multilingual purpose)
11. Assigned controlTip from external source
12. Code to change enable,visible,locked,or backstyle according to
state and condition of other parameters (exemple: the draft mode
and AreaStyl do not work in Page Type).
25 variables X 12 basic operations = already 600 lines of mostly repeating
code ! :-(
Now, using a three dimension array instead of a two dimensions one seems
the logical path to follow to reduce code lines. Instead of having:
25 variables x (10 sets x 2 mode)
one could have (25 variables x 10 sets x 2 mode)
(or even (25 variables x 20 sets) but it would be more confusing)
It would allow much more compact code, like using FOR... NEXT loop instead
of a long list of 25 pretty much similar operations.
But NOT ALWAYS: for example, boolean parameters are treated differently
from integer parameters in most operation. So I would preferably create
25x10x2 array for each data type
I am not sure however it will change anything in speed of execution or
memory requirement. Actually, VBA help file says it will INCREASE memory
requirements, as array takes more memory than single variables !
The problem with a 3D array is also how to tell which parameters is in
which array location.
For example, I have at present such lines as:
chkboxDraft = bDraft(iSetNo,iMode)
and
cboType.ListIndex = iType(isetNo,IMode)
If I had one or more 3D arrays it would be
chkboxDraft = bBooleanParametersArray(7, iSetNo, iMode)
cboType.ListIndex = iIntegerParametersArreay(3, iSetNo, iMode)
But here, HOW can I remember that the value 7 refers to the Draft setting
and the value 3 in the other array refers to Type setting ? Refers to an
handout paper print ? Wont it be even more confusing than actual indiviual
variables ? Less lines of code but much more bugs possible ?
It's here I am wondering and decided to submit this design problem to this
group.
How would you design the whole gizmo if number of lines code is an issue
Or, is number of lines codes an issue after all ?
Thanks for sharing you general perspective on this.
"customizable sets" of extensive Word display options. It basically
reproduces most of Word option dialog items, but save choices in separate
configuration sets that can be apply at a click of a button. The add-in
works well, is ready for multilingual use and quite fast.
My problem is bloated code, not speed, or function. It has more than 2000
lines. Maintenance is not easy.
The biggest problem I have is a long serie of variables that are part of
each parameter set, but often different data type . The number of variables
was quite small at the beginning of the project but it kept growing as I
added more and more features. (I also have to admit that I learned VB
only two weeks ago and I probably made gross design mistakes in some parts
of the coding )
For each variable, there are 10 customizable sets and 10 "factory" sets,
for a total of 20 possible and applicable sets of display parameters.
It goes a bit like this:
Public strName(10, 1) As String
Public bBlue(10, 1) As Boolean
...
... (long list)
...
Public bParagraphs(10, 1) As Boolean
Public iType(10, 1) As Integer
Public sZoomValue(10,1) as single
etc.
for about 25 different variables for each set of parameters.
Because they differed in type, I designed an option form with a mix of
checkbox, textbox, spin and combobox that display and change any set.
All operations in the add-in must repeat all the list of variables:
1. Declare variables
2. Assign hard-coded factory defaults to variable
3. Management routine to change factory default (maintenance)
4. Read custom settings from registry
5. Save custom settings to registry
6. Reset custom settings to factory default
7. Push any set content to the form
8. Put form content back to a given set
9. Apply a set of parameters (main function)
Moreover, each variable's corresponding component on the form has a name
much similar to the variable name and can have:
10. Assigned caption from external source (for multilingual purpose)
11. Assigned controlTip from external source
12. Code to change enable,visible,locked,or backstyle according to
state and condition of other parameters (exemple: the draft mode
and AreaStyl do not work in Page Type).
25 variables X 12 basic operations = already 600 lines of mostly repeating
code ! :-(
Now, using a three dimension array instead of a two dimensions one seems
the logical path to follow to reduce code lines. Instead of having:
25 variables x (10 sets x 2 mode)
one could have (25 variables x 10 sets x 2 mode)
(or even (25 variables x 20 sets) but it would be more confusing)
It would allow much more compact code, like using FOR... NEXT loop instead
of a long list of 25 pretty much similar operations.
But NOT ALWAYS: for example, boolean parameters are treated differently
from integer parameters in most operation. So I would preferably create
25x10x2 array for each data type
I am not sure however it will change anything in speed of execution or
memory requirement. Actually, VBA help file says it will INCREASE memory
requirements, as array takes more memory than single variables !
The problem with a 3D array is also how to tell which parameters is in
which array location.
For example, I have at present such lines as:
chkboxDraft = bDraft(iSetNo,iMode)
and
cboType.ListIndex = iType(isetNo,IMode)
If I had one or more 3D arrays it would be
chkboxDraft = bBooleanParametersArray(7, iSetNo, iMode)
cboType.ListIndex = iIntegerParametersArreay(3, iSetNo, iMode)
But here, HOW can I remember that the value 7 refers to the Draft setting
and the value 3 in the other array refers to Type setting ? Refers to an
handout paper print ? Wont it be even more confusing than actual indiviual
variables ? Less lines of code but much more bugs possible ?
It's here I am wondering and decided to submit this design problem to this
group.
How would you design the whole gizmo if number of lines code is an issue
Or, is number of lines codes an issue after all ?
Thanks for sharing you general perspective on this.