Executing or opening an invalid file path

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
nskd
Newbie
Posts: 12
Joined: Wed May 29, 2019 2:02 pm

Executing or opening an invalid file path

Post by nskd » Fri Jun 28, 2019 8:35 am

Hi,

Need help in my simple dialog. Let's say if the user does not enter any file or file path and simply hit the "Open" button. How can the program prompt the user that a valid path is needed instead of this Macro Scheduler error prompt?

Dialog>Dialog1
object Dialog1: TForm
Left = 404
Top = 111
HelpContext = 5000
BorderIcons = [biSystemMenu]
Caption = 'Select a file'
ClientHeight = 134
ClientWidth = 375
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -14
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
Position = poScreenCenter
ShowHint = True
OnTaskBar = False
PixelsPerInch = 120
TextHeight = 16
object Label1: TLabel
Left = 20
Top = 20
Width = 96
Height = 16
Margins.Left = 4
Margins.Top = 4
Margins.Right = 4
Margins.Bottom = 4
Caption = 'Enter a filename'
end
object Edit1: TEdit
Left = 17
Top = 50
Width = 305
Height = 24
Margins.Left = 4
Margins.Top = 4
Margins.Right = 4
Margins.Bottom = 4
TabOrder = 0
end
object FileOpen_Button1: tMSButton
Left = 331
Top = 50
Width = 26
Height = 26
Margins.Left = 4
Margins.Top = 4
Margins.Right = 4
Margins.Bottom = 4
Glyph.Data = {
F6000000424DF600000000000000760000002800000010000000100000000100
0400000000008000000000000000000000001000000010000000000000000000
80000080000000808000800000008000800080800000C0C0C000808080000000
FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00777777777777
77777777777777777777000000000007777700333333333077770B0333333333
07770FB03333333330770BFB0333333333070FBFB000000000000BFBFBFBFB07
77770FBFBFBFBF0777770BFB0000000777777000777777770007777777777777
7007777777770777070777777777700077777777777777777777}
TabOrder = 1
DoBrowse = False
BrowseStyle = fbOpen
end
object Button1: tMSButton
Left = 17
Top = 88
Width = 92
Height = 31
Margins.Left = 4
Margins.Top = 4
Margins.Right = 4
Margins.Bottom = 4
Caption = 'Open'
ModalResult = 10
TabOrder = 2
DoBrowse = False
BrowseStyle = fbOpen
end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,FileOpen_Button1,OnClick,DoBrowse
AddDialogHandler>Dialog1,Button1,OnClick,Open_Sub
Show>Dialog1,r

SRT>DoBrowse
SetDialogProperty>Dialog1,FileOpen_Button1,DoBrowse,True
GetDialogProperty>Dialog1,FileOpen_Button1,Filename,file
SetDialogProperty>Dialog1,Edit1,Text,file
END>DoBrowse

SRT>Open_Sub
ExecuteFile>%file%
END>Open_Sub
Exit>0
Attachments
file not present.png
file not present.png (19.71 KiB) Viewed 290 times

User avatar
Grovkillen
Automation Wizard
Posts: 360
Joined: Fri Aug 10, 2012 2:38 pm
Location: Hudiksvall, Sweden
Contact:

Re: Executing or opening an invalid file path

Post by Grovkillen » Fri Jun 28, 2019 9:27 am

Disable the button until the variable is filled out and confirmed valid?
Let>ME=%Script%

Running: MS14.5.4

nskd
Newbie
Posts: 12
Joined: Wed May 29, 2019 2:02 pm

Re: Executing or opening an invalid file path

Post by nskd » Fri Jun 28, 2019 9:56 am

Hi Grov,

Thanks for your suggestion. This suggestion looks workable. Do you mean that I have to go to Button property and change something?

Can you guide me a little?

User avatar
Grovkillen
Automation Wizard
Posts: 360
Joined: Fri Aug 10, 2012 2:38 pm
Location: Hudiksvall, Sweden
Contact:

Re: Executing or opening an invalid file path

Post by Grovkillen » Fri Jun 28, 2019 12:01 pm

Yes you can set the dialog property using the command setDialogProperty.
Let>ME=%Script%

Running: MS14.5.4

nskd
Newbie
Posts: 12
Joined: Wed May 29, 2019 2:02 pm

Re: Executing or opening an invalid file path

Post by nskd » Fri Jun 28, 2019 2:54 pm

Can you edit on my script and let me see how to get it done?

User avatar
Marcus Tettmar
Site Admin
Posts: 7080
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Executing or opening an invalid file path

Post by Marcus Tettmar » Mon Jul 01, 2019 12:10 pm

I would just check that the file exists before doing anything:

Code: Select all

SRT>Open_Sub
  IfFileExists>file
    ExecuteFile>file
  Else
    MessageBox>Please enter a valid file first!
  Endif
END>Open_Sub
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply