' Name: NewFileOpen
' Description:
'   Example replacement for FileOpen macro.  Uses COMMDLG to Allow 
'	selection of personalized file type extensions.
'   To use it, copy the macro to your FileOpen macro and customize
'	it suit your needs.
'   Requires CommLib macro to be installed globally.
'
' Copyright 1993 Artemis Associates, San Jose, CA

Sub MAIN
	fname$ = ""		' No Initial Filename
	dir$ = "c:\"	' Initial Directory

	' Filter of File Type to look for
	filt$ = "Contracts (*.cnt)|*.cnt"
	filt$ = filt$ + "|Letters (*.let)|*.let"
	filt$ = filt$ + "|Invoices (*.inv)|*.inv"
	filt$ = filt$ + "|All Files (*.*)|*.*"
	title$ = "New File Open - COMMDLG"

	' Flags for dialog box characteristics
	OFN_READONLY = 1
	OFN_PATHMUSTEXIST = 2048
	OFN_FILEMUSTEXIST = 4096
	flags = OFN_PATHMUSTEXIST + OFN_FILEMUSTEXIST

	' Use Function 0 for FileOpen
	fname$ = CommLib.GetFileDlg$(0, dir$, fname$, filt$, title$, flags)

	If fname$ = "" Then Goto Bye
	On Error Goto ErrOpen

	' Check if ReadOnly box is checked, if so, open as ReadOnly
	If(flags And OFN_READONLY) = 0 Then
		FileOpen .Name = fname$
	Else
		FileOpen .Name = fname$, .ReadOnly = 1
	End If
	Goto Bye

ErrOpen:
	msg$ = "Error Opening File, " + fname$
	r = MsgBox(msg$, "New File Open", 16)
Bye:
End Sub

