Web Development

General discussion


Commondialog in VB6

By mayasarma ·
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

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


This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -

by Tony Hopkinson In reply to Commondialog in VB6

DIM var as New type

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

Collapse -

by Dragon Emperor In reply to Commondialog in VB6

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


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

End With

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

Collapse -

use this

by teera_koedchan In reply to Commondialog in VB6

Call openFile.ShowOpen

Related Discussions

Related Forums