|
-
Aug 30th, 2000, 11:04 PM
#1
Thread Starter
Frenzied Member
How do i load a file with the common dialog controls (never learned how)
-
Aug 30th, 2000, 11:11 PM
#2
Conquistador
Try that:
Code:
Private Sub Command1_Click()
On Error GoTo handling:
Dim cd1 As CommonDialog
Set cd1 = CommonDialog1
cd1.DialogTitle = "Open a File" 'Title of the CD
cd1.Filter = "Applications|*.exe|Text Files|*.txt" 'The filters for the files
cd1.FilterIndex = 1 'Choose the index of the filters
cd1.CancelError = True 'Make it so that it will not process if nothing selected
cd1.ShowOpen
'Put your file process stuff here
'
'
'
'
handling: 'a file was not selected
End Sub
-
Aug 30th, 2000, 11:13 PM
#3
Thread Starter
Frenzied Member
thanks, only 7 mnutes to respond!!!!!!!! thanks da_silvey
-
Aug 30th, 2000, 11:24 PM
#4
Thread Starter
Frenzied Member
-
Aug 30th, 2000, 11:38 PM
#5
Conquistador
add a common dialog box then add this code to command button 1
-
Aug 30th, 2000, 11:40 PM
#6
Conquistador
or do you need help with something else?
-
Aug 30th, 2000, 11:42 PM
#7
Thread Starter
Frenzied Member
yeah how do I make it load a pic, there is nothing that specifies the filename or what was chosen
-
Aug 30th, 2000, 11:51 PM
#8
Conquistador
sorry about that, firstly, you probably want your users to load the pic, not the prograM??
if you want the program to pick the pic without any user intervention, you do not need a common dialog, but if you want the user to be able to choose the picture you can use it.
the filterindex determines what is shown in the dialog box,
the filename is held, after the user fives the ok, in the cd1.filename variable
Code:
Private Sub Command1_Click()
On Error GoTo handling:
Dim cd1 As CommonDialog
Set cd1 = CommonDialog1
cd1.DialogTitle = "Open a File" 'Title of the CD
'Change this bit below to "JPEGS|*.jpg" for pictures
cd1.Filter = "Applications|*.exe|Text Files|*.txt" 'The filters for the files
cd1.FilterIndex = 1 'Choose the index of the filters
cd1.CancelError = True 'Make it so that it will not process if nothing selected
cd1.ShowOpen
'Put your file process stuff here
'
'
'
'
handling: 'a file was not selected
End Sub
do you get it?
-
Aug 31st, 2000, 04:00 AM
#9
Fanatic Member
Code:
'Add a command button and the control to a form and add this code.
Private Sub Command1_Click()
'Brings up the OPEN dialog
Dim iFile As Integer
On Error GoTo User_Cancelled
With CommonDialog1
.CancelError = True
.DialogTitle = "Please select a file..."
.Filter = "File (*.*)|*.*"
.ShowOpen
'Runs the selected program
Shell CommonDialog1.FileName, vbNormalFocus
End With
User_Cancelled:
End Sub
Or if you need to load a picture into a picturebox (from what i could understand) then you would use:
Code:
Private Sub Command1_Click()
'Brings up the OPEN dialog
Dim iFile As Integer
On Error GoTo User_Cancelled
With CommonDialog1
.CancelError = True
.DialogTitle = "Please select a file..."
.Filter = "File *.bmp|*.bmp|File *.jpg|*.jpg|File *.gif|*.gif"
.ShowOpen
'Sets the selected image as the background of the form
'just replace the form1.picture with whatever you need.
Form1.Picture = LoadPicture(CommonDialog1.FileTitle)
End With
User_Cancelled:
End Sub
Hope that helps,
D!m
-
Oct 6th, 2000, 10:37 AM
#10
Member
Hello Dim,
I tried your code and it crashes at:
".CancelError = True"
and says "Object Required"
I don't know what's wrong but I tested the code on a new project and it works but when I incorporate it into my program it crashes on the line above. Do you know what's wrong? Thanks!
Marci Sarwan ([email protected])
-
Oct 6th, 2000, 12:07 PM
#11
Fanatic Member
Marci,
Did you add the Common Dialog Component to the project and then add the Common Dialog object to the form ?
I re-created your error in a new project, but after adding the component and object everything works fine.
-
Oct 6th, 2000, 08:55 PM
#12
Originally posted by Marci S
Hello Dim,
I tried your code and it crashes at:
".CancelError = True"
and says "Object Required"
I don't know what's wrong but I tested the code on a new project and it works but when I incorporate it into my program it crashes on the line above. Do you know what's wrong? Thanks!
Marci Sarwan ([email protected])
Dim has provided error handling to rid any errors, including that one Marci. You should not receive any type of errors. Make sure you have the line On Error Resume Next or, as Dim has, On Error GoTo User_Cancelled.
-
Oct 7th, 2000, 08:31 AM
#13
Hyperactive Member
The WITH statement should have taken care of the "object required" thingy - are you
sure that you have that in your code or that your Common Dialog control is not named
something other than CommonDialog1?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|