DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

finding if ActiveX showOpen, 'cancel' is clicked

Hi
I am using the ActiveX control COMDLG32 to open a file.
If MSCommonDlgAX.X.ShowOpen = False Then
MsgBox "cancel"
Else
MsgBox "Open"
End If

In both cases the message "cancel" is displayed. I tried 'CancelError' as well. It does the same thing. Does anyone know a way to make this work.

Thanks
0 Kudos
Message 1 of 5
(4,889 Views)
Anne,

From what I can tell about Microsoft's Common Dialog ActiveX control ShowOpen method, it doesn't seem to have a return value. See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cmdlg98/html/vbmthshowopen.asp. Since it doesn't return anything, your comparison isn't valid. You might look for some examples online that show using the CommonDialog control or perhaps another control that provides a return value describing the outcome of what happened with the dialog.

Hope that helps!

Regards,
Shannon R
Applications Engineer
National Instruments
0 Kudos
Message 2 of 5
(4,889 Views)
Hi Shannon

Thanks for the reply. According to to MS website 'CancelError' is supposed to contain the return value. But in diadem it does not work.

http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/dnarvb4/html/msdn_comdlg.asp

I used the vb 'FileNameGet' method instead of the activex control.

Thanks
Anne
0 Kudos
Message 3 of 5
(4,889 Views)
Hi Anne,

I can't see anything in that Microsoft document that says that CancelError is supposed to contain the return value. This property functions as described here and it is used to cause an error to occur when the CancelError property is set to True. You use error-handling to catch the error when the user clicks Cancel.

In VBScript (and SUD dialogs in DIAdem) you can use the error-handling method described in the DIAdem help topic "On Error statement" to catch the error that occurs when the user clicks Cancel.

Here's how I used this method:

' CancelError is True, but we will catch errors.
On Error Resume Next
M
SCommonDlgAX.X.CancelError = True

' Set filters.
MSCommonDlgAX.X.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt|Batch Files (*.bat)|*.bat"
' Specify default filter.
MSCommonDlgAX.X.FilterIndex = 2

' Display the Open dialog box.
MSCommonDlgAX.X.ShowOpen

' An error will have occurred if the user clicked Cancel.
If (Err.Number <> 0) Then
Msgbox "User clicked cancel"
Else
Msgbox MSCommonDlgAX.X.FileName
End If

On Error Goto 0

Hope this helps you get started,
David Mc.
NI Application Engineer
0 Kudos
Message 4 of 5
(4,889 Views)
Thanks David
I misunderstood how to use cancelError
Anne
0 Kudos
Message 5 of 5
(4,889 Views)