Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 08-29-2015, 03:50 PM
cjmccormack cjmccormack is offline
Registered User
 
Join Date: Aug 2015
Posts: 3
Question File Open Dialog - how to determine if user hits 'Cancel'

Hello,

I'm writing a script for running several show commands pre- and post- switch refresh.

The script does the following:
- Parses the last line of a session to get both the prompt and the hostname, the hostname derived from the prompt
- Using the hostname and date parameters, sets the crt.Session.LogFileName to a custom string that auto-populates the filename in the FileOpenDialog
- Opens a crt.Dialog.FileOpenDialog so the user can select the path and change the filename if needed.

After this is done, logging is enabled, the commands are run, logging is disabled again then the script terminates.

My current issue is I'm not sure how to handle the case where the user selects 'Cancel' in the FileOpenDialog box. I would like the script to terminate at that point, but because I have a filename auto-populated, the return value would only be an empty string if the user actually removed the entire filename. It is far more convenient to have the filename auto-populated so removing that is pretty much out of the question.

Are there any methods of the Dialog class that aren't well documented that I could use? Is there an easy way to handle this I may have just missed?

Many thanks!
Reply With Quote
  #2  
Old 08-31-2015, 08:05 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi cjmccormack,

If I understand correctly what you are trying to accomplish, you would just check for empty string and then take the appropriate action:

Code:
    If filepath = "" Then MsgBox "You cancelled"
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 08-31-2015, 08:42 AM
cjmccormack cjmccormack is offline
Registered User
 
Join Date: Aug 2015
Posts: 3
If the filename text field has text already in it that I wanted pre-populated, I can't look for a response with an empty string to determine they hit cancel, unless the user deletes the pre-populated string, correct? It seems the FileOpenDialog simply returns a unicode string, and even if the user hits Cancel, if there is some text in that string a value will be returned.
Reply With Quote
  #4  
Old 08-31-2015, 10:39 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi cjmccormack,

In my tests, while leaving the default string in place, choosing Cancel does result in an empty string.

Quote:
It seems the FileOpenDialog simply returns a unicode string, and even if the user hits Cancel, if there is some text in that string a value will be returned.
What test did you run that produced the above results?

A great trick I learned from our script guru is to enclose the results in angle braces so you can tell if there really is some non-printing value being returned that would otherwise not be obvious.

I used the following test (in this case, you would not even invoke the "if" side unless the variable is empty, but I thought I might provide this debugging tip anyway):

Code:
filePath = crt.Dialog.FileOpenDialog("Please select a text file", "Open", "c:\temp\New.txt")

if filepath = "" then 
    msgbox "you cancelled" & vbcrlf & vbcrlf & "<" & filepath & ">"
else
    msgbox "your path is: " & filepath
end if
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #5  
Old 08-31-2015, 02:27 PM
cjmccormack cjmccormack is offline
Registered User
 
Join Date: Aug 2015
Posts: 3
You are correct, thank you so much! I'm not sure what I did wrong, but following your guidance I did indeed receive the empty string when the Cancel option was chosen.

Thanks!
Reply With Quote
  #6  
Old 08-31-2015, 02:29 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi cjmccormack,

Great, thanks for posting the follow-up!
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
Reply

Tags
cancel , dialog , fileopendialog , open , scripting

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 02:32 AM.