Results 1 to 6 of 6

Thread: Common Dialog Box question

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    258

    Question

    Morning Everyone ,

    How can I tell when a user selects a file in a common dialog box . I have a CDB to let the user browsw to a file , I want to know when he has selected it and pressed "open"

    Thnks

    []P
    Visual Basic 6 SP4 on win98se

    QUIT THE RAT RACE BECAUSE YOUR MESSING THE WORLD UP !!!!!

  2. #2
    Guest
    Your code will stop at

    Code:
    CommonDialog1.ShowOpen
    until the user clicks Open or Cancel. So:

    Code:
    CommonDialog1.ShowOpen
    Msgbox "selected"
    The message box will come up after the user has click Open or Cancel.

    Sunny

  3. #3
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151

    More data.

    Here is some more about Common Dialogue box. Following is copied from code which worked.
    Code:
    Private Sub mnuFileOpen_Click()
    
    'cdlOFNCreatePrompt   &H2000  File should not exist'
    'cdlOFNFileMustExist  &H1000'
    'cdlOFNOverwritePrompt   &H2'
    'cdlOFNPathMustExist   &H800'
    'cdlOFNLongNames    &H200000'
    dlogCommon.Flags = &H201800  'Long Names; File & Path must exist'
    dlogCommon.CancelError = True
    dlogCommon.DialogTitle = "Gravity: Read File"
    dlogCommon.FileName = GrvtyFile
    dlogCommon.InitDir = GrvtyDirectory
    dlogCommon.Filter = "Gravity Files(*.grv)|*.grv|All Files(*.*)|*.*"
    
    On Error GoTo BadOpen
    
    dlogCommon.ShowOpen
        'Fall through here if User does not cancel/close'
        GrvtyFileName = dlogCommon.FileName
        Call BodyGettor(GrvtyFileName)
        cboxBodyName.SetFocus
      Exit Sub
    
    BadOpen:
        'Ignore: User changed him mind about opening file'
        cboxBodyName.SetFocus
    End Sub
    Some of the above is specific to my application, but it should give you some ideas.
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

  4. #4
    New Member
    Join Date
    Jul 2000
    Posts
    7
    You can also just put

    CommonDialog1.ShowOpen
    FileName = CommonDialog1.FileName
    if FileName = "" then exit sub

    If the user clicks cancel, the subroutine won't continue.

  5. #5
    Guest
    Originally posted by olaf_001
    You can also just put

    CommonDialog1.ShowOpen
    FileName = CommonDialog1.FileName
    if FileName = "" then exit sub

    If the user clicks cancel, the subroutine won't continue.
    You must have CancelError set to true and error handling as well so that if the user presses cancel, you won't get any error.


    'On Error Resume Next
    'CommonDialog.CancelError = True

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    258
    Thnks Guys , I was trying to figure out WHEN I could get the the stats of the File selected like size and type . Now I know

    Thanks again ,

    []P
    Visual Basic 6 SP4 on win98se

    QUIT THE RAT RACE BECAUSE YOUR MESSING THE WORLD UP !!!!!

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