|
-
May 11th, 2013, 05:11 AM
#1
Thread Starter
Addicted Member
[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
-
May 11th, 2013, 06:16 AM
#2
Re: Common dialog error
 Originally Posted by Bonzo2008
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)
-
May 11th, 2013, 06:31 AM
#3
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|