Browsing for a file
You will perform many modifications that require input from a file on the Windows file system. Instead of requiring the user to remember the full path and name of the file, we will show you how to use an out-of-the-box codeunit to let them select the file using a dialog box.
How to do it...
Create a new codeunit from Object Designer.
Add the following global variables:
Name
Type
Subtype
Length
CommonDialogMgt
Codeunit
Common Dialog Management
SelectedFile
Text
255
Add the following code to the
OnRun
trigger:SelectedFile := CommonDialogMgt.OpenFile('NAV File Browser', SelectedFile,1,'Filter',0); MESSAGE('You selected %1', SelectedFile);
Save and close the codeunit.
How it works...
NAV provides a codeunit, number 412, named Common Dialog Management. It uses an OCX that references to the Microsoft Common Dialog Control. This codeunit provides a function that allows you to open a simple dialog box in either Open or Save mode. This function, OpenFile
, takes five parameters...