View Single Post
Old 02-28-2014, 01:46 PM
Ka0sFact)r Ka0sFact)r is offline
Registered User
Join Date: Feb 2014
Posts: 2
check for valid file

I am working on a script that I almost have completed. However I am trying to add a fail-safe that will prevent a runtime error. My script for SecureCRT is written in vb. At the start of the script the user is to select a .csv file that will be read into an array for the script to use. I want to have the script check to make sure that the user entered a file, did not select cancel, and the file is a .csv file and not some other file type. If it is not a valid csv file I want to give the option to retry or abort the script.

Here is all I have that is working so far:

filepath = crt.Dialog.FileOpenDialog("Please select the *.csv file to open")
If FileSysObj.GetExtensionName(filepath) = "csv" <> False Then
crt.Dialog.MessageBox _
"The selected file is not a valid csv file!" & vbCrLf & _
"Please choose a valid csv file!" & vbCrLf & _
End If

However if the don't select a valid file the script tries to proceed and just crashes.
Reply With Quote