WORKAROUND
Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
To work around this problem, have your dynamic dialog box redrawing Sub
procedures call the following Visual Basic for Applications routine (or
something similar) whenever you need to rewrite an option button or check
box label:
' Make sure to call this procedure after assigning the new labels to the
' controls. This Sub Procedure has two arguments: Ctrl is the control
' and NumToBlank is the number of spaces necessary to cover up the
' longest possible caption for the control.
Sub ClearLabels(Ctrl as Object, NumToBlank as Integer)
' Follow the current label with a lot of spaces.
Ctrl.Caption = Ctrl.Caption & _
String(NumToBlank - Len(Ctrl.Caption), " ")
End Sub
To call this procedure within a Visual Basic for Applications module and
have it apply to an option button named "Option1" (without the quotation
marks) on the Active Dialog, and to pad the label with 30 spaces, include a
call in the procedure that writes the labels as follows:
ClearLabels ActiveDialog.OptionButtons("Option1"), 30
Keep in mind that with proportional fonts, it may take more than 10 spaces
to obscure 10 wider characters (such as the "#" character). Also keep in
mind that the ClearLabels procedure must be called after making the
assignment of the new label caption.
If you prefer to have one procedure fix all of the option buttons at once
by looping through them, you can create a procedure such as the following:
' Make sure to call this after assigning the new labels to the controls.
Sub Clear_Labels()
' Dimension a variable to hold the objects.
Dim Control As Object
' Sets up a loop to run through every option button in the active
' dialog. Change ".OptionButtons" to ".CheckBoxes" if working with
' check boxes.
For Each Control In ActiveDialog.OptionButtons
' Set the caption equal to itself with 35 spaces after it.
' You may need to edit this line to increase or decrease the
' number of characters in the final label. Keep in mind that
' with proportional fonts, it may take more than 10 spaces to
' cover up 10 other characters.
Control.Caption = Control.Caption & _
String(35 - Len(Control.Caption), " ")
' Loop through the code.
Next Control
End Sub