i am new, and i want to add a common dialog into my program so i can open files, where do i click to add one?
i have vb 6
thanks
Printable View
i am new, and i want to add a common dialog into my program so i can open files, where do i click to add one?
i have vb 6
thanks
Go to Components, and add "Microsoft Common Dialog Control". Choose the latest version you see.
i did that, now what do i do next?
Take the new component you now have, and put one on the form. Call it "cdlg" because it'll shorten the code :).
Then, add a CommandButton ("btnGo").
Here's the code:
The documentation explains most of it, but that's a start. The Filter property is a bit nasty, but it's basically:Code:Private Sub btnGo_Click()
On Error GoTo ErrorHandler
cdlg.Filter = "My Program Files (*.myp)|*.myp|All Files (*.*)|*.*|"
cdlg.DialogTitle = "Open file..."
cdlg.CancelError = True
cdlg.ShowOpen
MsgBox cdlg.filename
Exit Sub
ErrorHandler:
If Err.Number = cdlCancel Then
' The user hit cancel
Else
Debug.Print "Other Error " & Err.Number
End If
End Sub
The last pipe is very important.Code:Desc1|Type1|Desc2|Type2|Desc3|Type3|
Why is that? I never had a problem with not having a pipe char in the end.Quote:
The last pipe is very important.
Also you can have a filter accepting several filetypes, just separate them with ;Code:CommonDialog1.Filter = "Form (*.frm)|.frm|Module (*.bas)|*.bas|All supported files|*.bas;*frm|allfiles|*.*"
*kicks ankles*
Sorry...my c++ heritage is showing :(. It's important when you use the API version...sorry...sorr*@%*@$*$*$%@@@$*%
*slap*
I feel better now.
yeah, but you put nullchars intead of pipechars ;)
Oh? When using the function from C++ it always worked using pipes for me...
hmm? maybe i should try that, i've always used nullchars
Now I AM confused :(.
Yeah, me too, works only with nullchars :(
Do you use these declarations?
Code:Private Declare Function GetSaveFileName Lib "comdlg32.dll" Alias "GetSaveFileNameA" (pOpenfilename As OPENFILENAME) As Long
Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long
Yeah...Dunno what it is.
They're open and save dialogs.
Yes...I know that. What I don't know is what's going on with the nullchars and pipechars.Quote:
They're open and save dialogs.
*Confused*
Hmm, any ideas?
*idea*
Maybe in the later version they set it so that you could use pipechars in the API version, so that people from other languages could easily incorporate it into a string. Also, in C, since the string terminator is a nullchar, how would they get the other parts? That must be why it needs two at the end...it loops through and checks for a double null.