How to Read Flag Property of VB Common Dialog Custom Controls

This article was previously published under Q84068
This article has been archived. It is offered "as is" and will no longer be updated.
The Flags property of a Common Dialog control can be read by examiningindividual bit values of the Flag property and comparing them withthe predefined constant values in CONSTANT.TXT (or CONST2.TXT forVisual Basic version 1.0 for Windows). This applies to the followingVisual Basic for Windows Common Dialogs:
  • File Open Dialog
  • File Save Dialog
  • Color Dialog
  • Choose Font Dialog
  • Print Dialog
More information
The Flags property can be set at design time or run time.

To set the value of the Flags property, assign it a value. This ismost commonly done using a predefined constant (found in CONSTANT.TXTor CONST2.TXT). For example, to set the PRINTTOFILE flag on the PrintDialog box, use the following code:
   CMDialog1.Flags = PD_PRINTTOFILE				

To set more than one flag, OR the two flags (the pipe [|] characteracts the same as the OR statement):

The settings of the Flags property can also be changed at run time bythe user making various selections in the dialog box. When a selectionis made, or the status of a check box or option button is changed, theFlags property reflects this change. You can then read the value ofthe Flags property and determine if a specific flag has been set.

For example, in the above sample code, two flags are set in the Flagsproperty. The value of PD_PRINTTOFILE = &H00000020& and the value ofPD_SHOWHELP = &H00000800&.

The binary equivalent of the two is the following:
   PD_PRINTTOFILE = 00000000000000000000000000100000   PD_SHOWHELP    = 00000000000000000000100000000000				

Thus the value:
   Flags          = 00000000000000000000100000100000				

NOTE: Each flag setting has its own bit setting within the Flags property.

To determine if a specific flag is set, you only need to AND the flagwith the Flags property. If the result is 0, then the flag is not set;if the result is the same as the flag value, then the flag is set.

For example:
   Form1.Print (CMDialog1.Flags AND PD_PRINTTOFILE)				

The output is decimal 32. Thus, broken down:
   Flags          = 00000000000000000000100000100000				
   PD_PRINTTOFILE = 00000000000000000000000000100000   Result         = 00000000000000000000000000100000				

Thus, the flag for PRINTTOFILE is one of the flags that are set in theFlags property:
If  (CMDialog1.Flags AND PD_PRINTTOFILE) Then   ' Code for printing to file goes here.Else   ' Code for printing to printer goes here.End If				
1.00 2.00 3.00

Article ID: 84068 - Last Review: 10/26/2013 09:50:00 - Revision: 3.0

  • Microsoft Visual Basic 2.0 Professional Edition
  • kbnosurvey kbarchive KB84068