Discussion Locked

Commondialog in VB6

0 helpful
3 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

how do i use commondialog in VB6 for the openfiledialog() function?
I tried to program it as below, but didnt work.

Dim openFile As New Commondialog
commondialog.showopen()

but I do not get commondialog class from IDE and get a syntax error at the Dim openfile.... line

-TIA
Mparam

3 replies

by tony hopkinson

DIM var as New type
var.method

as in
Dim MyLabel as New Label
MyLabel.Caption := "My Label"

Normally with Dialogs you do

If Dialog.execute then
(or If Dialog.ShowModal = mrOK)

If Dialog.FileName <> "" Then
....

Further PS, be careful with Dim As New. VB uses deferred creation, so the new object is not created until you use it. If other parts of your code rely on it's existance before you you actually use it it you can get into quite a mess.
Better to do.

Dim MyLabel as Label
Set MyLabel = New Label
...

Set MyLabel = Nothing

by dragon emperor

Go to Project\Components
Check the box by the Microsoft Common Dialog Control

Use the following code where you want to use the common dialog.
On Error GoTo ErrHandler
With CommonDialog1
.CancelError = True

.ShowOpen

If .FileName <> "" Then
'Here is where you would use the file name.
End If

End With
ErrHandler:

There are many options you can use. Among the most common are setting the filters to use.

This discussion is closed to new replies.