neotreksoftware.com
for free use with GFA Basic 32
fileselectors gb32 example 2
Now that you have the basic application shell you
one of the first things you might want to do is
add a windows file open or file save dialog.
fileselectors in gb32 look like this:

Click here to begin downloading gb32_fileselection_dialogs.zip with 4 fileselect examples
To do this, modify one of the menus to in formwindow
to Open File. Then add the code in one of the four
fileselect listings. Some programming terms and
definitions will follow the 4 coding examples.
This is the fileselectors pasteable to editor code listing:
listing 1: The Gfa basic FileSelect command.
The fileselect command is the easiest way to invoke the
Windows common dialog box. It is one line, but it does
have some limitations.
'FileSelect is short code for all Files only,
'
Global title$, filt$, file$, a%
title$ = "Open common dialog" //title$ must be preceeded by
//the # (hash,number,sharp) mark in Fileselect
file$ = "noname.txt"
filt$ = "all,*.*" //must be comma delimited csv string
FileSelect # title$, "c:\*.*", file$, filt$
listing 2: Fileselect using the Gfa basic FormEditor.
The method here uses the form editor on the right hand
side of a split window of the IDE (integrated development environment) GFA Basic 32.
To use this code you will need to put a CommDlg Object
icon shown on the bottom of the form editor on to the
default form frm1. Rename frm1 to form1. Then you can
run the example code. You can now change the properties
variables directly in the code at the event subrutine
Sub Command1_Click().
'Shows File Open Dialog, Editor Ocx Object
'Place a Common Dialog control on the form.
'Place a button, Command1, on the form.
'In the click event add the following code:
'Place a button, Command2 with Caption 'Exit
'by OCX or better
'the API GetOpenfilename, GetSaveFilename or
'or
'The C header and CommonDlg would be most
'compatable the other Windows languages with windows shell
'but lengthly and complex to the eye...
'
LoadForm form1
lbl1.Caption = "File Open Common Dialog"
Do
Sleep
Until Me Is Nothing
Sub Command1_Click()
Command2.Caption = "Exit Prog"
CdOfn.FileName = "test.file"
CdOfn.FileTitle = CurDir()
CdOfn.DefExt = ".txt"
CdOfn.Filter = "Text *.txt|*.txt|All *.*|*.*"
CdOfn.Title = "Open Document"
CdOfn.Flags = cdoHideReadOnly + cdoFileMustExist
CdOfn.ShowOpen
End Sub
Sub Command2_Click
End 'Quit
EndSub
listing 3: Fileselect Common Dialog using the a hardcoded
OCX in the code listing without the use of the
form editor.
A Gfa basic OCX is a windows object (control) that
describes the parameters or properties of GFA basic
forms, windows or control objects.
'Open DLG and Fileselect should be substituted
'by this runtime OCX
'
Ocx CommDlg cdOfn
cdOfn.FileName = "test.file"
cdOfn.FileTitle = CurDir()
cdOfn.DefExt = ".txt"
cdOfn.Filter = "Text *.txt|*.txt|All *.*|*.*"
cdOfn.Title = "Open Document"
cdOfn.Flags = cdoHideReadOnly + cdoFileMustExist
cdOfn.ShowOpen
Message cdOfn.FileName
listing 4: Fileselect using the backward compatable
Gfa 16 bit command DLG OPEN.
This should not be used unless you have just converted
a listing from 16 bit gfa basic and have not had the
time to change it to one of the above.
' The 16 bit Dlg Open syntax
' Calls the Data file Selection
' Dlg Open Wnd, Flags, Title, Dir, defext, Filt$(), Ret$
' window,flags,title,directory,filter,filename
'This command is syntax out of compatabiliy
'to the 16 bit GFA-BASIC for Windows syntax
'It should no longer be used.
'Example: A Shura
@InitDlgOpen
@DlgOpen
Procedure InitDlgOpen
Global ofn_file$, ofn_flags As Double, ofn_hwnd As Double
Global ofn_nameext$, ofn_path$, ofn_pth$, ofn_title$
Global filt$(20)
//filt$(0) = "Bitmap ",filt$(1) = "*.bmp"
filt$(0) = "ALL *.*", filt$(1) = "*.*"
filt$(2) = ""
Return
Procedure DlgOpen
//16 bit
ofn_hwnd = 0 //handle, no window desktop owner
ofn_title$ = "Select file"
ofn_path$ = "C:\"
ofn_flags = 0 //OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST etc.
ofn_file$ = "" //return filename selected
ofn_nameext$ = filt$(1) //start name shown at top edit
Dlg Open Win_0, 0, ofn_title$, ofn_pth$, ofn_nameext$, filt$(), ofn_file$
Print ofn_file$
Return
Definitions:
Object: A programming object. Usually placed in memory.
OCX : A type of windows Active X control. Describes
forms, windows and control objects in many IDE's.
IDE : A programming language Integrated Development
Environment. (Not to be confused with an older
type of hard drive standard).
PME : Properties, Metheods and Events in the PME
object programming model.
Properties :Object variables in the GB32 Form Editor or
listings.
Metheods :Commands and functions etc, in an event
handling subrutine Sub.. EndSub
Events :Windows events triggered by a user action.
ie: On_Click or On_MenuEvent(Idx%) and so on.
www.neotreksoftware.com