browse folder code..cancel button

Author Message
elly00

  • Total Posts : 61
  • Scores: 0
  • Reward points : 0
  • Joined: 2/27/2009
  • Status: offline
browse folder code..cancel button Monday, January 23, 2012 9:18 PM (permalink)
0
Hi I have this code sample
This work correctly, It gives an error pressing cancel button..
I would like to valorize the variable even if CANCEL button is pressed to C: value
How can I do that?
 
Const MY_COMPUTER = &H11&
Const WINDOW_HANDLE = 0
Const OPTIONS = 0
Dim objShell
Dim objFolder
Dim objFolderItem
Dim strPath
Dim objPath

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(MY_COMPUTER)
Set objFolderItem = objFolder.Self
strPath = objFolderItem.Path
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder _
(WINDOW_HANDLE, "Selezionare il percorso di salvataggio:", OPTIONS, strPath)

If objFolder Is Nothing Then
ShowOpenFolder="C:"
End If
Set objFolderItem = objFolder.Self
objPath = objFolderItem.Path
 
#1
    59cobalt

    • Total Posts : 981
    • Scores: 91
    • Reward points : 0
    • Joined: 7/17/2011
    • Status: offline
    Re:browse folder code..cancel button Monday, January 23, 2012 10:43 PM (permalink)
    0
    elly00
    Hi I have this code sample
    This work correctly, It gives an error pressing cancel button..
    [...]
    If objFolder Is Nothing Then
    ShowOpenFolder="C:"
    End If
    Set objFolderItem = objFolder.Self
    That's because when objFolder is Nothing, setting ShowOpenFolder="C:" doesn't change anything about that. Which in turn causes objFolder.Self to fail, because objFolder still is Nothing.

    elly00
    I would like to valorize the variable even if CANCEL button is pressed to C: value
    How can I do that?
    You make sure that objFolder references an appropriate object before trying to access objFolder.Self:
    If objFolder Is Nothing Then
     Set objFolder = objShell.Namespace("C:\")
    End If
    Set objFolderItem = objFolder.Self

     
    #2

      Online Bookmarks Sharing: Share/Bookmark

      Jump to:

      Current active users

      There are 0 members and 1 guests.

      Icon Legend and Permission

      • New Messages
      • No New Messages
      • Hot Topic w/ New Messages
      • Hot Topic w/o New Messages
      • Locked w/ New Messages
      • Locked w/o New Messages
      • Read Message
      • Post New Thread
      • Reply to message
      • Post New Poll
      • Submit Vote
      • Post reward post
      • Delete my own posts
      • Delete my own threads
      • Rate post

      2000-2012 ASPPlayground.NET Forum Version 3.9