|
-
Apr 18th, 2005, 04:23 PM
#1
Thread Starter
Member
[RESOLVED] Help: Should I use Common Dialog or ??
OK. I've got a program that displays pictures, thumbnails, etc.
On the form I have a DriveListBox, DirListBox, and FileListBox, and also a combo box for type of file (.jpg, .gif, .bmp, yadda yadda) for the user's selection. If the user clicks on a thumbnail, a new form pops up with a larger version of the thumbnail. I know ... this is all basic thumbnailing stuff, but I was fortunate in that it all works well, no problem there.
HOWEVER, I would like to add the functionality of giving the user the option of right clicking on either 1) a filename in the FileListBox, 2) a thumbnail, or 3) a larger picture; then having a menu pop up (I also have the menu taken care of ...) offering the following options: Rename (same as SaveAs?), Copy(same as SaveAs?), Move(same as SaveAs?), or Delete.
Included in these would naturally check for a valid path, and if the user specifies a new directory in the Rename, Copy or Move, the directory would be created. What I initially did (and I wound up with a mess) was when the user right-clicked on one of the above, a new form would pop up displaying the current file location/name, and a textbox where the user could type in all the new info, or a "delete" checkbox next to the originally selected file name. Cumbersome and generated a lot of complaints.
There's a lot out here on VBForums and I've been searching for a couple of days for a comprehensive example I could copy and modify to my needs (I know that's a cop-out but I would be modifying it LOL), but, as usual, I've gotten myself into a spider's web of coding with the above-mentioned methodologies. So time to start over with some good guidance!
Thanks in advance.
Last edited by John K; Apr 19th, 2005 at 01:26 PM.
Reason: RESOLVED
-
Apr 18th, 2005, 04:53 PM
#2
Re: Help: Should I use Common Dialog or ??
I'm not 100% sure I fully understand what the question is here, but I think you're wondering what dialogs you should use for the Rename, Copy, and Move functions you have in your popup menu.
I'm a bit confused about this statement:[quote]if the user specifies a new directory in the Rename [/Highlight]If a new path is specified you're not renaming the file since you are moving it.
I would use a Save As dialog for the Copy function. The Browse For Folder for the Move function, since you will only move it to a new path or if you like the ability to move and rename at once you could use the Save As dialog here as well. For the Rename feature I would simply use an InputBox (or my own Form) to get the new name.
Both the Save As dialog as well as the Browse For Folder dialog has the ability to create new folders so you can let your users do so before they close the dialogs.
-
Apr 19th, 2005, 01:57 AM
#3
Re: Help: Should I use Common Dialog or ??
do a search on popup menus
rgds
pete
-
Apr 19th, 2005, 01:23 PM
#4
Thread Starter
Member
Re: Help: Should I use Common Dialog or ??
Isn't it interesting the way education works?
After writing my post, and reading your reply, I was composing a reply when a "light went on" and I solved my problem.
All except one ... I used the following as a template:
Code:
Private Sub cmdSave_Click()
Dim strBuffer As String
Dim intDemoFileNbr As Integer
Dim strFileToSave As String
On Error GoTo cmdSave_Click_Exit
With dlgDemo
.CancelError = True
.InitDir = mstrLastDir
.Flags = cdlOFNOverwritePrompt + cdlOFNPathMustExist
.FileName = ""
.Filter = "Text Files(*.txt)|*.txt|All Files(*.*)|*.*"
.ShowSave
strFileToSave = .FileName
End With
On Error GoTo cmdSave_Click_Error
intDemoFileNbr = FreeFile
Open strFileToSave For Binary Access Write As #intDemoFileNbr
strBuffer = txtTestFile.Text
Put #intDemoFileNbr, , strBuffer
Close #intDemoFileNbr
mstrLastDir = Left$(strFileToSave, InStrRev(strFileToSave, "\") - 1)
Exit Sub
cmdSave_Click_Error:
MsgBox "The following error has occurred:" & vbNewLine _
& "Err # " & Err.Number & " - " & Err.Description, _
vbCritical, _
"Save Error"
cmdSave_Click_Exit:
End Sub
Source: http://www.thevbprogrammer.com/index...ter=10&Topic=3
from a link I found while doing further snooping around on good ol' VBForums!
Again, this is a template and I have modified it for my purposes. It seems to work quite well, all except for the error routine. When I click on "CANCEL" when the CommonDialog window is open, I keep blowing up on "Runtime Error 32755" user selected Cancel.
I'm trying to get around this at the present time and I think I have a solution to that also. If not I'll whine some more 
Thanks for replying, I appreciate it.
-
Apr 19th, 2005, 01:25 PM
#5
Thread Starter
Member
Re: Help: Should I use Common Dialog or ??
 Originally Posted by westconn1
do a search on popup menus
rgds
pete
Thanks for the reply, Pete, but that wasn't my problem. Pls see the post above ... I think I've got it!
Thanks again ... I appreciate the feedback.
-
Apr 19th, 2005, 01:27 PM
#6
Lively Member
Re: [RESOLVED] Help: Should I use Common Dialog or ??
Take out this line
.CancelError = True
or set to false
-
Apr 19th, 2005, 01:29 PM
#7
Re: [RESOLVED] Help: Should I use Common Dialog or ??
Change .CancelError = True to .CancelError = False
-
Apr 19th, 2005, 05:47 PM
#8
Re: [RESOLVED] Help: Should I use Common Dialog or ??
No! Do not change the CancelError property since that's the best way of getting notification if a user has clicked the Cancel button. Simply make a few changes in your code.
VB Code:
Private Sub cmdSave_Click()
Dim strBuffer As String
Dim intDemoFileNbr As Integer
Dim strFileToSave As String
[b] On Error Resume Next [/b]
With dlgDemo
.CancelError = True
.InitDir = mstrLastDir
.Flags = cdlOFNOverwritePrompt + cdlOFNPathMustExist
.FileName = ""
.Filter = "Text Files(*.txt)|*.txt|All Files(*.*)|*.*"
.ShowSave
[b] If Err.Number = cdlCancel Then
Exit Sub
End If [/b]
strFileToSave = .FileName
End With
[b][i] On Error GoTo cmdSave_Click_Error [/i][/b]
intDemoFileNbr = FreeFile
Open strFileToSave For Binary Access Write As #intDemoFileNbr
strBuffer = txtTestFile.Text
Put #intDemoFileNbr, , strBuffer
Close #intDemoFileNbr
mstrLastDir = Left$(strFileToSave, InStrRev(strFileToSave, "\") - 1)
'No errors bail out!
Exit Sub
cmdSave_Click_Error:
MsgBox "The following error has occurred:" & vbNewLine _
& "Err # " & Err.Number & " - " & Err.Description, _
vbCritical, _
"Save Error"
End Sub
-
Apr 20th, 2005, 04:19 AM
#9
Thread Starter
Member
Re: [RESOLVED] Help: Should I use Common Dialog or ??
 Originally Posted by Hack
Change .CancelError = True to .CancelError = False
I've been playing with that already, but I want to be able to check when the user clicks on "CANCEL" ... giving an error of 32755. But it seems I never get to my compare for err or error.number = 32755. When the user presses cancel, I get the message that a run-time error 32755 has been generated and that the user pressed CANCEL.
However, when I'm in DEBUG I see that I wind up on the .ShowSave line and it seems my error compare for 32755 never gets executed.
Ideas?
-
Apr 20th, 2005, 05:59 AM
#10
Re: [RESOLVED] Help: Should I use Common Dialog or ??
Ehhh? Did you try my code?
-
Apr 20th, 2005, 11:10 AM
#11
Thread Starter
Member
Re: [RESOLVED] Help: Should I use Common Dialog or ??
 Originally Posted by Joacim Andersson
Ehhh? Did you try my code?
Oh sorry, Joacim, that I didn't answer you! YES I did try your code, in fact I was happy when I saw it because I was at that stage in my coding and thought to myself that it was a confirmation that it would work! ... however ... as I told Hack, above:
I've been playing with that already, but I want to be able to check when the user clicks on "CANCEL" ... giving an error of 32755. But it seems I never get to my compare for err or error.number = 32755. When the user presses cancel, I get the message that a run-time error 32755 has been generated and that the user pressed CANCEL.
However, when I'm in DEBUG I see that I wind up on the .ShowSave line and it seems my error compare for 32755 never gets executed.
So, even when I try your modifications the same thing happens. When in DEBUG I'm going through that section line by line and the cdlCancel DOES have the value of 32755, but it never gets executed as I can't get out of the .ShowSave.
-
Apr 20th, 2005, 11:25 AM
#12
Thread Starter
Member
Re: [RESOLVED] Help: Should I use Common Dialog or ??
 Originally Posted by Joacim Andersson
Ehhh? Did you try my code?
OK I don't understand this but ...
Out of frustration, I decided to again compile this thing and see how it would run in a real-time environment because there were other areas I wanted to ensure did not need addiitonal work.
I gritted my teeth, went into this routine, and was ready to see the "No-go Charlie!" message, but IT WORKED!
I fired it up a couple of times and tried it over and over again and IT WORKED.
So then I went back into VB6 to add comments where credit is due so I have a record, ran it and the error message with the debugger indicating .ShowSave came up again.
Well, it seems to work though so perhaps I should let it rest, you think?
Thanks all, and Joacim for all your help!
-
Apr 21st, 2005, 06:58 AM
#13
Re: [RESOLVED] Help: Should I use Common Dialog or ??
Your error trapping setting in VB is probably set to break on all errors. Click Tools > Options and select the General tab. Now change the Error Trapping setting to either Break in Class Modules or Break on Unhandled Errors.
-
Apr 21st, 2005, 07:29 AM
#14
Need-a-life Member
Re: [RESOLVED] Help: Should I use Common Dialog or ??
 Originally Posted by Joacim Andersson
No! Do not change the CancelError property since that's the best way of getting notification if a user has clicked the Cancel button. Simply make a few changes in your code.
VB Code:
Private Sub cmdSave_Click()
Dim strBuffer As String
Dim intDemoFileNbr As Integer
Dim strFileToSave As String
[b] On Error Resume Next [/b]
With dlgDemo
.CancelError = True
.InitDir = mstrLastDir
.Flags = cdlOFNOverwritePrompt + cdlOFNPathMustExist
.FileName = ""
.Filter = "Text Files(*.txt)|*.txt|All Files(*.*)|*.*"
.ShowSave
[b] If Err.Number = cdlCancel Then
Exit Sub
End If [/b]
strFileToSave = .FileName
End With
[b][i] On Error GoTo cmdSave_Click_Error [/i][/b]
intDemoFileNbr = FreeFile
Open strFileToSave For Binary Access Write As #intDemoFileNbr
strBuffer = txtTestFile.Text
Put #intDemoFileNbr, , strBuffer
Close #intDemoFileNbr
mstrLastDir = Left$(strFileToSave, InStrRev(strFileToSave, "\") - 1)
'No errors bail out!
Exit Sub
cmdSave_Click_Error:
MsgBox "The following error has occurred:" & vbNewLine _
& "Err # " & Err.Number & " - " & Err.Description, _
vbCritical, _
"Save Error"
End Sub
Isn't it easier to ask for the .FileName's lenght?
VB Code:
Private Sub cmdSave_Click()
Dim strBuffer As String
Dim intDemoFileNbr As Integer
Dim strFileToSave As String
With dlgDemo
.CancelError = [B]False[/B]
.InitDir = mstrLastDir
.Flags = cdlOFNOverwritePrompt + cdlOFNPathMustExist
.FileName = ""
.Filter = "Text Files(*.txt)|*.txt|All Files(*.*)|*.*"
.ShowSave
strFileToSave = .FileName
End With
On Error GoTo cmdSave_Click_Error
[B]If Len(strFileToSave) Then[/B]
intDemoFileNbr = FreeFile
Open strFileToSave For Binary Access Write As #intDemoFileNbr
strBuffer = txtTestFile.Text
Put #intDemoFileNbr, , strBuffer
Close #intDemoFileNbr
mstrLastDir = Left$(strFileToSave, InStrRev(strFileToSave, "\") - 1)
'No errors bail out!
[B]End If[/B]
Exit Sub
cmdSave_Click_Error:
MsgBox "The following error has occurred:" & vbNewLine _
& "Err # " & Err.Number & " - " & Err.Description, _
vbCritical, _
"Save Error"
End Sub
Emiliano F. Martín
If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
Encourage the person who helped you to keep doing it, and give him the points he deserves.
MP3 Organizer: Freeware to logically organize all your MP3s.
-
Apr 21st, 2005, 08:00 AM
#15
Re: [RESOLVED] Help: Should I use Common Dialog or ??
 Originally Posted by Mc Brain
Isn't it easier to ask for the .FileName's lenght?
I don't know. Is it? It might just be me but I like the idea of treating the cancel button as an exception. Besides it's a habit, I remember back in VB2 you could click the Save/Open button without first selecting or typing a file name, which of course would also return an empty string.
-
Apr 21st, 2005, 05:02 PM
#16
Thread Starter
Member
Re: [RESOLVED] Help: Should I use Common Dialog or ??
 Originally Posted by Mc Brain
Isn't it easier to ask for the .FileName's lenght?
Interesting.
I'm doing that elsewhere in the program for other purposes, such as if there is a .jpg out there that is trying to be opened -- if it has a length of 0 I just bypass it (I'll have to code up a routine to go and delete it, but for now the fast & dirty way was just to bypass it). I'll keep your method in my snippets and try it in the future, but for now Joacim's fix has really helped me and it work, so I'll stay with it.
Thanks.
-
Apr 21st, 2005, 05:26 PM
#17
Re: [RESOLVED] Help: Should I use Common Dialog or ??
John, did you check your Error Trapping settings as I described in my last post?
-
Apr 21st, 2005, 07:59 PM
#18
Thread Starter
Member
Re: [RESOLVED] Help: Should I use Common Dialog or ??
 Originally Posted by Joacim Andersson
John, did you check your Error Trapping settings as I described in my last post?
Yes, Joacim, I should have indicated that was the problem. I've set it to Unhandled Errors and it works fine.
Thanks again
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
|