Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it possible to use a 'file list' dialog box? 4

Status
Not open for further replies.

briangm

Technical User
Mar 29, 2004
2
US
Hi all, I am writing a Macro for Extra version 6.5 and I want to bring up a dialog box for the user to select a file to open; is there an easy way to do this? It seems that this would be coded somewhere in Extra already.

Thanks in advance for any advice.

Brian Meyer
 
Dialog boxes are pretty low quality and hard to program in Extra. I've gone to VBA when I need access to file objects. I guess it is possible to use API calls, but this will likely get more complicated than would be helpful.

Check the FAQ if you're intersted in how to make VBA use Extra.

calculus

How do I use VB(A) to manipulate attachmate (6.5+)? faq99-4069
 
I use Windows open file dialog API, instead of the file open dialog Extra has available.

The following code should be saved as a Header File:
File Open Header.ebh
============================================================
Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As Long
lpstrCustomFilter As Long
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As Long
nMaxFile As Long
lpstrFileTitle As Long
nMaxFileTitle As Long
lpstrInitialDir As Long
lpstrTitle As Long
Flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As Long
lCustData As Long
lpfnHook As Long
lpTemplateName As Long

End Type

Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenFileName As OPENFILENAME) As Long
Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As String) As Long
Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long

Dim pOpenFileName As OPENFILENAME


Global Const OFN_READONLY = &H1
Global Const OFN_OVERWRITEPROMPT = &H2
Global Const OFN_HIDEREADONLY = &H4
Global Const OFN_NOCHANGEDIR = &H8
Global Const OFN_SHOWHELP = &H10
Global Const OFN_ENABLEHOOK = &H20
Global Const OFN_ENABLETEMPLATE = &H40
Global Const OFN_ENABLETEMPLATEHANDLE = &H80
Global Const OFN_NOVALIDATE = &H100
Global Const OFN_ALLOWMULTISELECT = &H200
Global Const OFN_EXTENSIONDIFFERENT = &H400
Global Const OFN_PATHMUSTEXIST = &H800
Global Const OFN_FILEMUSTEXIST = &H1000
Global Const OFN_CREATEPROMPT = &H2000
Global Const OFN_SHAREAWARE = &H4000
Global Const OFN_NOREADONLYRETURN = &H8000
Global Const OFN_NOTESTFILECREATE = &H10000
Global Const OFN_SHAREFALLTHROUGH = 2
Global Const OFN_SHARENOWARN = 1
Global Const OFN_SHAREWARN = 0

'-------------------------------------------------------
'
' Open File Dialog
'
'-------------------------------------------------------
'
Function GetFileName(Title$, FileType$) As String
Dim Message$, Filter$, FileName$, FileTitle$, DefExt$
Dim szCurDir$, APIResults&

' Define the filter string and allocate space in the "c" string
Filter$ = "Text File (*." & FileType & ")" & Chr(0) & "*." & FileType & Chr(0)
Filter$ = Filter$ & "All Files (*.*)" & Chr(0) & "*.*" & Chr(0)
Filter$ = Filter$ & Chr(0)

' Allocate string space for the returned strings.
FileName$ = Chr(0) & Space(255) & Chr(0)
FileTitle$ = Space(255) & Chr(0)

' Give the dialog a caption title.
Title$ = Title$ & Chr(0)

' If the user does not specify an extension, append MDB.
DefExt$ = "txt" & Chr(0)

' Set up the defualt directory
szCurDir$ = CurDir$ & Chr(0)

' Set up the data structure before you call the GetOpenFileName
pOpenFileName.lStructSize = Len(pOpenFileName)
pOpenFileName.hwndOwner = GetModuleHandle("Extra.exe")
pOpenFileName.lpstrFilter = lstrcpy(Filter$, Filter$)
pOpenFileName.nFilterIndex = 1
pOpenFileName.lpstrFile = lstrcpy(FileName$, FileName$)
pOpenFileName.nMaxFile = Len(FileName$)
pOpenFileName.lpstrFileTitle = lstrcpy(FileTitle$, FileTitle$)
pOpenFileName.nMaxFileTitle = Len(FileTitle$)
pOpenFileName.lpstrTitle = lstrcpy(Title$, Title$)
pOpenFileName.Flags = OFN_HIDEREADONLY + OFN_FILEMUSTEXIST
pOpenFileName.lpstrDefExt = lstrcpy(DefExt$, DefExt$)
pOpenFileName.hInstance = 0
pOpenFileName.lpstrCustomFilter = 0
pOpenFileName.nMaxCustFilter = 0
pOpenFileName.lpstrInitialDir = lstrcpy(szCurDir$, szCurDir$)
pOpenFileName.nFileOffset = 0
pOpenFileName.nFileExtension = 0
pOpenFileName.lCustData = 0
pOpenFileName.lpfnHook = 0
pOpenFileName.lpTemplateName = 0

' This will pass the desired data structure to the Windows API,
' which will in turn use it to display the Open Dialog form.

APIResults& = GetOpenFileName(pOpenFileName)

If APIResults& <> 0 Then
GetFileName = Trim(FileName$)
Else
'return null string if no file selected
GetFileName = ""
End If

End Function
============================================================



Then use include statement in Extra Macro file before functions to import header code:

'$Include: "File Open Header.ebh"


Then call to function in Extra Macro file:

Answer = GetFileName("Text for File Open Dialog", "txt")

Variable Answer will return Filename selected.
 
Thanks Jim! That's exactly what I was looking for.
 
Brian,

You're welcome, but props here go by Votes. [2thumbsup]

Jim
 
JimGE,

Is there anyway to force Windows to give focus to the file dialog produced by the code above?

Thanks,
wwr6196
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top