Suggestion on open file diaolog

Suggestion on open file diaolog

Anonymous
Not applicable
299 Views
6 Replies
Message 1 of 7

Suggestion on open file diaolog

Anonymous
Not applicable
My situation is this...
I am trying to insert a block from a file (browse and pick)
I have found some sample code that opened a user form and then opened the
dialog box
But my problem is passing the file name back to my sub for the block
insert...

Any suggestions as to where to find some ideas?

Randy
0 Likes
300 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
My situation is this...
I am trying to insert a block from a file (browse and pick)
I have found some sample code that opened a user form and then opened the
dialog box
But my problem is passing the file name back to my sub for the block
insert...

Any suggestions as to where to find some ideas?

Randy
0 Likes
Message 3 of 7

Anonymous
Not applicable
randy, what type of dialogbox did you open, is it a selfwritten one or the
windows commondialog or...

if it is the commondialog then you can return the ".FileName", it it's self
written, it would be more easy if we see your code.

- alfred -


In article ,
RBILLINGS@PREFERREDMFG.COM says...
> My situation is this...
> I am trying to insert a block from a file (browse and pick)
> I have found some sample code that opened a user form and then opened the
> dialog box
> But my problem is passing the file name back to my sub for the block
> insert...
>
> Any suggestions as to where to find some ideas?
>
> Randy
>
>
>
>
>
0 Likes
Message 4 of 7

Anonymous
Not applicable
The folling code is from userform1 (I kinda want to by pass this form and go
straight to the open file box)

Option Explicit

Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias
"GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long


Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type

Public Function ShowOpen(Filter As String, _
InitialDir As String, _
DialogTitle As String) As String

Dim OFName As OPENFILENAME

'Set the structure size
OFName.lStructSize = Len(OFName)
'Set the owner window
OFName.hwndOwner = 0
'Set the filter
OFName.lpstrFilter = Filter
'Set the maximum number of chars
OFName.nMaxFile = 255
'Create a buffer
OFName.lpstrFile = Space(254)
'Create a buffer
OFName.lpstrFileTitle = Space$(254)
'Set the maximum number of chars
OFName.nMaxFileTitle = 255
'Set the initial directory
OFName.lpstrInitialDir = InitialDir
'Set the dialog title
OFName.lpstrTitle = DialogTitle
'no extra flags
OFName.flags = 0
'Show the 'Open File' dialog
If GetOpenFileName(OFName) Then
ShowOpen = Trim(OFName.lpstrFile)

Else
ShowOpen = ""
End If
End Function



Private Sub cmdShowOpen_Click()
Dim Filter As String
Dim InitialDir As String
Dim DialogTitle As String

Filter = "Drawing Files (*.dwg)" + Chr$(0) + "*.dwg" + Chr$(0) + "All
Files (*.*)" + Chr$(0) + "*.*" + Chr$(0)
InitialDir = "H:\0blocks\HARDWARE"
DialogTitle = "Open a DWG file"

Label1.Caption = ShowOpen(Filter, InitialDir, DialogTitle)
End Sub


**
The following is from module1 where ***** should be the file name
Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(p1, ******, 1#, 1#, 1#,
angle)
0 Likes
Message 5 of 7

Anonymous
Not applicable
randy,

it's not really beautiful, but should work:
Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(p1,
userform1.Label1.Caption, 1#, 1#, 1#,

- alfred -

In article <3DFBF781A292C3D41B5EB4872169CD08@in.WebX.maYIadrTaRb>,
RBILLINGS@PREFERREDMFG.COM says...
> The folling code is from userform1 (I kinda want to by pass this form and go
> straight to the open file box)
>
> Option Explicit
>
> Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias
> "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
>
>
> Private Type OPENFILENAME
> lStructSize As Long
> hwndOwner As Long
> hInstance As Long
> lpstrFilter As String
> lpstrCustomFilter As String
> nMaxCustFilter As Long
> nFilterIndex As Long
> lpstrFile As String
> nMaxFile As Long
> lpstrFileTitle As String
> nMaxFileTitle As Long
> lpstrInitialDir As String
> lpstrTitle As String
> flags As Long
> nFileOffset As Integer
> nFileExtension As Integer
> lpstrDefExt As String
> lCustData As Long
> lpfnHook As Long
> lpTemplateName As String
> End Type
>
> Public Function ShowOpen(Filter As String, _
> InitialDir As String, _
> DialogTitle As String) As String
>
> Dim OFName As OPENFILENAME
>
> 'Set the structure size
> OFName.lStructSize = Len(OFName)
> 'Set the owner window
> OFName.hwndOwner = 0
> 'Set the filter
> OFName.lpstrFilter = Filter
> 'Set the maximum number of chars
> OFName.nMaxFile = 255
> 'Create a buffer
> OFName.lpstrFile = Space(254)
> 'Create a buffer
> OFName.lpstrFileTitle = Space$(254)
> 'Set the maximum number of chars
> OFName.nMaxFileTitle = 255
> 'Set the initial directory
> OFName.lpstrInitialDir = InitialDir
> 'Set the dialog title
> OFName.lpstrTitle = DialogTitle
> 'no extra flags
> OFName.flags = 0
> 'Show the 'Open File' dialog
> If GetOpenFileName(OFName) Then
> ShowOpen = Trim(OFName.lpstrFile)
>
> Else
> ShowOpen = ""
> End If
> End Function
>
>
>
> Private Sub cmdShowOpen_Click()
> Dim Filter As String
> Dim InitialDir As String
> Dim DialogTitle As String
>
> Filter = "Drawing Files (*.dwg)" + Chr$(0) + "*.dwg" + Chr$(0) + "All
> Files (*.*)" + Chr$(0) + "*.*" + Chr$(0)
> InitialDir = "H:\0blocks\HARDWARE"
> DialogTitle = "Open a DWG file"
>
> Label1.Caption = ShowOpen(Filter, InitialDir, DialogTitle)
> End Sub
>
>
> **
> The following is from module1 where ***** should be the file name
> Set blockRefObj = ThisDrawing.ModelSpace.InsertBlock(p1, ******, 1#, 1#, 1#,
> angle)
>
>
>
>
>
0 Likes
Message 6 of 7

Anonymous
Not applicable
problem is the variable from the show open does not pass back to the sub
0 Likes
Message 7 of 7

Anonymous
Not applicable
didn't got it at my first look, sorry.

if calling api-functions you do have to set empty-values just for reserving
space for the api-function to fill in data.

so check at least all strings to be initalized like
OFName.lpstrFile = Space$(254)

i hope now it's ok and we have found all, - alfred -

In article , RBILLINGS@PREFERREDMFG.COM says...
> problem is the variable from the show open does not pass back to the sub
>
>
>
>
0 Likes