Previous | Index | Next 

[HOWTO] Change the value of a given property of all controls of specified type or name

VB Migration Partner allows you to “massively” assign the design-time value of a given property to multiple controls, on a given form or all forms in the VB6 project. You can select the affected controls by their type or their name, in both cases using a regular expression. The pragma that does this magic is ChangeProperty, which takes the following four arguments: the property name, the new property value, a regex that identifies the control type (all controls if omitted), and a regex that identifies affected controls by their name (any name if omitted). Here are a few examples:

   '## Rem all command buttons in current form  whose name begins with "cmd" must be 400 twips high
   '## ChangeProperty Height, 400, "VB\.CommandButton", "cmd.+"    '## Rem reset the Text property of all TextBox controls in all forms    '## project:ChangeProperty Text, "", "VB\.TextBox”

The name of controls that belong to a control array include the index between parenthesis:

   '## Rem reset the Text property for all the elements of the "txtFields" control array
   '## ChangeProperty Text, "", "VB\.TextBox", "txtFields\(\d+\)"

You can also perform math operations on the current property value, by prefixing the newvalue argument with the +, -, *, /, \ symbols:

   '## Rem expand the width of all command  buttons in current form by 200 twips
   '## ChangeProperty Width, +200, "VB\.CommandButton"

   '## Rem ensure that all textboxes on current form are multilined and double their height
   '## ChangeProperty Height, *2, "VB\.TextBox"

The second argument can be preceded by the “=” symbol, which allows you to set a negative value for a numeric property or to assign a string property that begins with a math symbol:

   '## Rem set the ListIndex property to -1 for all ListBox controls
   '## ChangeProperty ListIndex, =-1, "VB\.ListBox”

   '## Rem set the Caption property to "+1" for controls named "lblIncr" or "cmdIncr"
   '## project:ChangeProperty Caption, "=+1", , "(lblIncr|cmdIncr)"


Previous | Index | Next