Results 1 to 3 of 3

Thread: [RESOLVED] Common dialog error

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2011
    Location
    Greece
    Posts
    164

    Resolved [RESOLVED] Common dialog error

    Hi all

    I get a error when I in the dlgcommon press cancel button


    On Error GoTo MnuNamnD_click_exit

    With dlgDemo
    .CancelError = True
    .InitDir = mstrLastDir
    .Flags = cdlOFNHideReadOnly
    .fileName = .FileTitle '""
    .Filter = "TextFiles *.txt|*.txt"
    .ShowOpen
    StrFileToOpen = .fileName
    namn = .FileTitle

    End With

    On Error GoTo MnuNamnD_click_error

    IntDemoFileNbr = FreeFile
    Open StrFileToOpen For Binary Access Read As #IntDemoFileNbr
    StrBuffer = Input(LOF(IntDemoFileNbr), IntDemoFileNbr)
    TxtTestFile.Text = StrBuffer

    Close #IntDemoFileNbr

    mstrLastDir = Left$(StrFileToOpen, InStrRev(StrFileToOpen, "\") - 1)
    Label14.Visible = False
    Label16.Visible = True
    Label16.Caption = "Fil :" & " " & namn
    Exit Sub

    MnuNamnD_click_error:
    MsgBox " Ett Fel inträffade"

    MnuNamnD_click_exit:


    TxtTestFile.Visible = False
    LstData.Visible = True
    AvbTxt.Visible = False
    SparaTxt.Visible = False

    and the error code is runtime code 32755

    because I pressed the cancel button.

    How to omitt this

    BonZo

  2. #2
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: Common dialog error

    Quote Originally Posted by Bonzo2008 View Post
    I get a error when I in the dlgcommon press cancel button

    . . .

    and the error code is runtime code 32755

    because I pressed the cancel button.

    How to omitt this
    That's exactly the behavior you'll get when the CommonDialog's CancelError property is set to True. Either set it to False or handle the cdlCancel error.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  3. #3
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,579

    Re: Common dialog error

    It is better to separate different tasks in different subs/functions, this make coding, debugging and reading easy

    try this
    Code:
    Private Sub Command1_Click()
    
        Dim strFileToOpen As String
        strFileToOpen = GetFileToOpen
        
        If strFileToOpen = vbNullString Then
            ' Cancel pressed
        Else
            ' Open the file
        End If
        
    End Sub
    
    Private Function GetFileToOpen() As String
        
        On Error GoTo errCancelPressed
        
        With dlgDemo
            .CancelError = True
            .InitDir = mstrLastDir
            .Flags = cdlOFNHideReadOnly
            .FileName = .FileTitle '""
            .Filter = "TextFiles *.txt|*.txt"
            .ShowOpen
            namn = .FileTitle
            GetFileToOpen = .FileName
        End With
        
        
        Exit Function
        
    errCancelPressed:
        GetFileToOpen = vbNullString
    End Function



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