Results 1 to 18 of 18

Thread: [RESOLVED] Help: Should I use Common Dialog or ??

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2005
    Posts
    61

    Resolved [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

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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.

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Help: Should I use Common Dialog or ??

    do a search on popup menus

    rgds
    pete

  4. #4

    Thread Starter
    Member
    Join Date
    Mar 2005
    Posts
    61

    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.

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2005
    Posts
    61

    Re: Help: Should I use Common Dialog or ??

    Quote 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.

  6. #6
    Lively Member
    Join Date
    Apr 2005
    Posts
    68

    Re: [RESOLVED] Help: Should I use Common Dialog or ??

    Take out this line
    .CancelError = True
    or set to false

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [RESOLVED] Help: Should I use Common Dialog or ??

    Change .CancelError = True to .CancelError = False

  8. #8
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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:
    1. Private Sub cmdSave_Click()
    2.     Dim strBuffer       As String
    3.     Dim intDemoFileNbr  As Integer
    4.     Dim strFileToSave   As String
    5.    [b] On Error Resume Next [/b]
    6.     With dlgDemo
    7.         .CancelError = True
    8.         .InitDir = mstrLastDir
    9.         .Flags = cdlOFNOverwritePrompt + cdlOFNPathMustExist
    10.         .FileName = ""
    11.         .Filter = "Text Files(*.txt)|*.txt|All Files(*.*)|*.*"
    12.         .ShowSave
    13. [b]        If Err.Number = cdlCancel Then
    14.             Exit Sub
    15.         End If [/b]
    16.         strFileToSave = .FileName
    17.     End With
    18. [b][i]    On Error GoTo cmdSave_Click_Error [/i][/b]
    19.     intDemoFileNbr = FreeFile
    20.     Open strFileToSave For Binary Access Write As #intDemoFileNbr
    21.     strBuffer = txtTestFile.Text
    22.     Put #intDemoFileNbr, , strBuffer
    23.     Close #intDemoFileNbr
    24.     mstrLastDir = Left$(strFileToSave, InStrRev(strFileToSave, "\") - 1)
    25.     'No errors bail out!
    26.     Exit Sub
    27.  
    28. cmdSave_Click_Error:
    29.     MsgBox "The following error has occurred:" & vbNewLine _
    30.          & "Err # " & Err.Number & " - " & Err.Description, _
    31.            vbCritical, _
    32.            "Save Error"
    33. End Sub

  9. #9

    Thread Starter
    Member
    Join Date
    Mar 2005
    Posts
    61

    Re: [RESOLVED] Help: Should I use Common Dialog or ??

    Quote 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?

  10. #10
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: [RESOLVED] Help: Should I use Common Dialog or ??

    Ehhh? Did you try my code?

  11. #11

    Thread Starter
    Member
    Join Date
    Mar 2005
    Posts
    61

    Re: [RESOLVED] Help: Should I use Common Dialog or ??

    Quote 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.

  12. #12

    Thread Starter
    Member
    Join Date
    Mar 2005
    Posts
    61

    Resolved Re: [RESOLVED] Help: Should I use Common Dialog or ??

    Quote 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!

  13. #13
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    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.

  14. #14
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,808

    Re: [RESOLVED] Help: Should I use Common Dialog or ??

    Quote 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:
    1. Private Sub cmdSave_Click()
    2.     Dim strBuffer       As String
    3.     Dim intDemoFileNbr  As Integer
    4.     Dim strFileToSave   As String
    5.    [b] On Error Resume Next [/b]
    6.     With dlgDemo
    7.         .CancelError = True
    8.         .InitDir = mstrLastDir
    9.         .Flags = cdlOFNOverwritePrompt + cdlOFNPathMustExist
    10.         .FileName = ""
    11.         .Filter = "Text Files(*.txt)|*.txt|All Files(*.*)|*.*"
    12.         .ShowSave
    13. [b]        If Err.Number = cdlCancel Then
    14.             Exit Sub
    15.         End If [/b]
    16.         strFileToSave = .FileName
    17.     End With
    18. [b][i]    On Error GoTo cmdSave_Click_Error [/i][/b]
    19.     intDemoFileNbr = FreeFile
    20.     Open strFileToSave For Binary Access Write As #intDemoFileNbr
    21.     strBuffer = txtTestFile.Text
    22.     Put #intDemoFileNbr, , strBuffer
    23.     Close #intDemoFileNbr
    24.     mstrLastDir = Left$(strFileToSave, InStrRev(strFileToSave, "\") - 1)
    25.     'No errors bail out!
    26.     Exit Sub
    27.  
    28. cmdSave_Click_Error:
    29.     MsgBox "The following error has occurred:" & vbNewLine _
    30.          & "Err # " & Err.Number & " - " & Err.Description, _
    31.            vbCritical, _
    32.            "Save Error"
    33. End Sub
    Isn't it easier to ask for the .FileName's lenght?


    VB Code:
    1. Private Sub cmdSave_Click()
    2.     Dim strBuffer       As String
    3.     Dim intDemoFileNbr  As Integer
    4.     Dim strFileToSave   As String
    5.  
    6.     With dlgDemo
    7.         .CancelError = [B]False[/B]
    8.         .InitDir = mstrLastDir
    9.         .Flags = cdlOFNOverwritePrompt + cdlOFNPathMustExist
    10.         .FileName = ""
    11.         .Filter = "Text Files(*.txt)|*.txt|All Files(*.*)|*.*"
    12.         .ShowSave
    13.         strFileToSave = .FileName
    14.     End With
    15.     On Error GoTo cmdSave_Click_Error
    16.     [B]If Len(strFileToSave) Then[/B]
    17.         intDemoFileNbr = FreeFile
    18.         Open strFileToSave For Binary Access Write As #intDemoFileNbr
    19.         strBuffer = txtTestFile.Text
    20.         Put #intDemoFileNbr, , strBuffer
    21.         Close #intDemoFileNbr
    22.         mstrLastDir = Left$(strFileToSave, InStrRev(strFileToSave, "\") - 1)
    23.         'No errors bail out!
    24.     [B]End If[/B]
    25.  
    26.     Exit Sub
    27.  
    28. cmdSave_Click_Error:
    29.     MsgBox "The following error has occurred:" & vbNewLine _
    30.          & "Err # " & Err.Number & " - " & Err.Description, _
    31.            vbCritical, _
    32.            "Save Error"
    33. 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.

  15. #15
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: [RESOLVED] Help: Should I use Common Dialog or ??

    Quote 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.

  16. #16

    Thread Starter
    Member
    Join Date
    Mar 2005
    Posts
    61

    Re: [RESOLVED] Help: Should I use Common Dialog or ??

    Quote 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.

  17. #17
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: [RESOLVED] Help: Should I use Common Dialog or ??

    John, did you check your Error Trapping settings as I described in my last post?

  18. #18

    Thread Starter
    Member
    Join Date
    Mar 2005
    Posts
    61

    Re: [RESOLVED] Help: Should I use Common Dialog or ??

    Quote 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
  •  



Click Here to Expand Forum to Full Width