Worst Practices (5) - Redim. Please Redim. Could you please Redim.
Found today (coming from a different source than the other worst practices examples found so far):
Redim Preserve VAL01(0), VAL01(1), VAL01(2), VAL01(3), VAL01(4)
I would hope that just REDIMing once to a length of 5 would be sufficient - but you never know... . Also the preserve option is very "important", as this REDIM is used to set some initial values - there is nothing in this array beforehand (and it would be erased by the first redim anyway).
A fixed array of 5 elements (DIM VAL01(4)) would be even better. And using some *meaningful* variable name...
Here is the complete function (changed only to fit to the screen) - just to see some other tricks/hacks/nonsense like using the same array for displaying options and setting a new one:
Function GetDefaultValues01 '// Function to determine all default values needed for the e-mail convertion process ... Redim Preserve VAL01(0), VAL01(1), VAL01(2), VAL01(3), VAL01(4) '// Defining substitution display text ... VAL01(0) = "More Infos" VAL01(1) = "Contact to" VAL01(2) = {E-Mail address with an (AT) instead of the "@".} VAL01(3) = "Firstname, space, lastname of the user" VAL01(4) = WS.Prompt ( 6, _ "Please select what might be displayed instead of the current found e-mail address.",_ "Please select what you want to be displayed instead the currently found e-mail addresses ..."_ , VAL01(0), VAL01 ) If VAL01(4) = "" Then Messagebox "Cancel by user request.", 48, "Process canceled" End End If End Function










Comments
for I = 1 to ubound(list)
redim preserve Maxlist ( i )
' Some calculation done with List ( i )
maxlist ( i-1 ) = Newvalue
' Some more calculations
next
And I found this THREE times in a project I took over from somewhere else.
After redoing these actions (yes view actions) the users reported they were in violent disagreement with the new software, now they were no longer able to get a coffee after clicking the action, which they used to be able to do !
Rudi
Posted by Rudi Knegt At 22:46:15 On 02.03.2006 | - Website - |
Dietmar
Posted by Dietmar Höhmann At 16:03:01 On 05.03.2006 | - Website - |