Results 1 to 8 of 8

Thread: Common Dialogue OK

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2001
    Posts
    54

    Common Dialogue OK

    I am writting some code using the microsoft common dialog control 6.0 and need to have an action take place when someone clicks on open or cancel. How do you write code for an action when you click cancel or open?


    Thanks

  2. #2
    Frenzied Member swatty's Avatar
    Join Date
    Aug 2002
    Location
    somewhere on earth
    Posts
    1,478
    FROM MSDN

    Visual Basic: CommonDialog Control

    CommonDialog Control


    The CommonDialog control provides a standard set of dialog boxes for operations such as opening and saving files, setting print options, and selecting colors and fonts. The control also has the ability to display help by running the Windows Help engine.

    Syntax

    CommonDialog

    Remarks

    The CommonDialog control provides an interface between Visual Basic and the routines in the Microsoft Windows dynamic-link library Commdlg.dll. To create a dialog box using this control, Commdlg.dll must be in your Microsoft Windows SYSTEM directory.

    You use the CommonDialog control in your application by adding it to a form and setting its properties. The dialog displayed by the control is determined by the methods of the control. Atrun time, a dialog box is displayed or the help engine is executed, when the appropriate method is invoked; atdesign time, the CommonDialog control is displayed as an icon on a form. This icon can't be sized.

    The CommonDialog control can display the following dialogs using the specified method.

    Method Dialog Displayed
    ShowOpen Show Open Dialog Box
    ShowSave Show Save As Dialog Box
    ShowColor Show Color Dialog Box
    ShowFont Show Font Dialog Box
    ShowPrinter Show Print or Print Options Dialog Box
    ShowHelp Invokes the Windows Help Engine


    The CommonDialog control automatically provides context sensitive help on the interface of the dialog boxes by clicking:

    The What's This help button in the title bar then clicking the item for which you want more information.


    The right mouse button over the item for which you want more information then selecting the What's This command in the displayed context menu.
    The operating system provides the text shown in the Windows 95 (or later) Help popup. You can also display a Help button on the dialog boxes with the CommonDialog control by setting the Flags property, however, you must provide the help topics in this situation.

    Note There is no way to specify where a dialog box is displayed.

    For More Information To see help topics for each dialog, click on See Also.
    Code:
    If Question = Incomplete Then
       AnswerNextOne
    Else
       ReplyIfKnown
    End If
    cu Swatty

  3. #3
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    VB Code:
    1. Set the CommandDialog1's CancelError property to True
    2. Private Sub Command1_Click()
    3. On Error GoTo Hell:
    4. CommandDialog1.ShowOpen 'Shows open dialog
    5. Msgbox CommandDialog1.FileName 'Shows the selected file.. This code will only executed when Open is clicked
    6. Exit Sub
    7. Hell:  
    8.   'This is where the control comes when user clicks Cancel Button
    9. If Err.Number = 32755 Then 'U check to see if the error is one generated by the Cancel Button
    10. ''Code..
    11. End If
    12. End Sub

  4. #4
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    Something like this:
    VB Code:
    1. Private Sub Form_Load()
    2. '=======================
    3. Dim strFileName As String
    4.  
    5. On Error GoTo ErrHanler
    6.  
    7.     CD.ShowOpen
    8.     If Not CD.CancelError Then
    9.         strFileName = CD.FileName
    10.     End If
    11.     Exit Sub
    12.  
    13. ErrHanler:
    14. '---------------
    15.     Debug.Print Err.Description
    16.     Err.Clear
    17.     Resume Next
    18.  
    19. End Sub
    Roy

  5. #5

    Thread Starter
    Member
    Join Date
    Nov 2001
    Posts
    54
    Thanks Swatty, great information!

    Is there a way to have a second action take place when you click on a common diaglogue button, for example if you click on open can you also trigger the form to change color.

  6. #6
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011
    Yah Sure !!!
    VB Code:
    1. Set the CommandDialog1's CancelError property to True
    2. Private Sub Command1_Click()
    3. On Error GoTo Hell:
    4. CommandDialog1.ShowOpen 'Shows open dialog
    5. Me.BackColor = vbBlue '.. This code will only executed when Open is clicked
    6.  
    7. Exit Sub
    8. Hell:  
    9.   'This is where the control comes when user clicks Cancel Button
    10. If Err.Number = 32755 Then 'U check to see if the error is one generated by the Cancel Button
    11. ''Code..
    12. End If
    13. End Sub

  7. #7

    Thread Starter
    Member
    Join Date
    Nov 2001
    Posts
    54
    Where can I find info on Err.Number = 32755?

  8. #8
    PowerPoster
    Join Date
    Aug 2002
    Location
    NY, NY
    Posts
    2,139
    In general, it is not a good practce to hardcode an error number (or anything at all if can be avoided). Instead use (as much as you can) generic Error Handling routine.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width