dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2004
    Posts
    61

    Unhappy CommonDialog Color error - "32755"

    Dear all,

    i have try to use the CommonDialog Color to allow user to change color to suite themself.

    i have no problem to show the color dialog but i'm facing problem when the "cancel" button is click for the color dialog.

    it show me "run-time error '32755'

    Below is my coding.

    With CommonDialog1
    .CancelError = True
    .Flags = &H2
    .ShowColor '<== the error show here when i click debug
    txtname.BackColor = .Color

    End With


    how do i need to change my coding in order to solve this problem
    i have no ideas.

    thanks
    vbEnduser

  2. #2
    DataMiser is offline Super Moderator Power Poster
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,266

    Re: CommonDialog Color error - "32755"

    You need to add an error trap to your code.

    You set .cancelerror=true which means when they hit cancel an error code is returned and that is what you are getting. You need to trap that code and that is how you know they hit cancel.

    Code:
     On Error Goto ErrTrap
    With CommonDialog1
      .CancelError = True
      .Flags = &H2
      .ShowColor '<== the error show here when i click debug
      txtname.BackColor = .Color
    End With 
    Exit Sub
    ErrTrap:
    if err.number=32755 then 'cancel was selected
    else
      msgbox "Error " err.number &" " & err.description
    end if
    In the code above when the user hits cancel the code will skip to the errtrap then see that 32755 was the code and simply exit the routine cleanly. You may want to have a flag set there depending on what you would like to do when cancel is hit.
    It any other error occurs it will be displayed in a message box but will not cause the program to crash.

    It is a good idea to include error trapping in all your routines but always make sure to put an exit sub or exit function just above the error trap so the program doesn;t execute the errtrap unless an error actually occurs.

  3. #3
    Join Date
    Dec 2004
    Posts
    61

    Thumbs up Re: CommonDialog Color error - "32755"

    dear DataMiser,

    Thanks for the help.
    The application did not crash anymore.
    thanks you.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)