How to check wether user pressed oK or Cancel for save dialog

moronmaster
09-04-2003, 04:24 AM
Hi,
I am using the common dialog control in VB 6.0 and i'd like to figure out how to detect wether the user clicked ok or the cancel button.

MSDN claims that you have to detect this using error traps. But i'd like to avoid this. Is ther a simpler (and more readable) way of doing this?

like :

nRet_Val = commondialog1.ShowSave
If nRet_Val - False then
Exit Sub
Else
'go save your file
End if

Thanks in advance to whoever can offer some help in this.

susanl
09-04-2003, 04:32 AM
I am not sure if this will help you, but VB does have constants for user selections. I have used them with MsgBox though not with the common dialog box. There is vbYes, vbNo, vbCancel, I think vbOK as well. I may be wrong but I do believe there are these constant values that can be used.

gundavarapu
09-04-2003, 04:37 AM
write the code

commondialog1.cancelerror=true
commondialog1.showsave


this will generate exception if the user selects cancel

Hope this helps!

wildfire1982
09-04-2003, 04:39 AM
and

if err.number=cdlcancel then
'cancel was pressed
end if

will detect it.

moronmaster
09-04-2003, 04:50 AM
Hmm... i tried what you guys suggested, but it throws an exception (cancel was selected) Meaning i still have to trap for the error to check wether the cancel key was pressed.

I guess i have no choice but to learn to use traps.

My code snippet here (which doesn't work):

'Get the desired filename for saving into
dlg_save.CancelError = True
dlg_save.ShowSave

If Err.Number = cdlCancel Then
'cancel was pressed
debug_msg ("Info: User canceled file save")
Exit Sub
End If

wildfire1982
09-04-2003, 04:53 AM
you need to set on error resume next aswell.

moronmaster
09-04-2003, 05:03 AM
EDIT: Oh...waitaminute. Yep i gto it working.
Thanks a lot guys

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum