VB6 Common Dialog Save - basic.visual

This is a discussion on VB6 Common Dialog Save - basic.visual ; I want to save file Punk_History.def to a directory chosen by the user. When I execute the code below, the dialog box says the file has been saved. Problem is that the file does not exist in the directory I ...

+ Reply to Thread
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 12

VB6 Common Dialog Save

  1. Default VB6 Common Dialog Save

    I want to save file Punk_History.def to a directory chosen by the
    user. When I execute the code below, the dialog box says the file has
    been saved. Problem is that the file does not exist in the directory
    I chose to save it in. Why doesn't it work?


    Dim Pathy as string
    Pathy = "C:\Program Files\Games\"

    With CommonDialog
    .DialogTitle = "Archive File - Punk_History.def"
    .CancelError = True
    .Flags = cdlOFNHideReadOnly + cdlOFNOverwritePrompt +
    cdlOFNPathMustExist + cdlOFNNoChangeDir
    .Filter = "All Files(*.def)|*.def"
    .FilterIndex = 1 '1 = Save and 2 = Open
    .DefaultExt = ".abd"
    .Filename = "Punk_History.def"
    .InitDir = Pathy
    .ShowSave
    MsgBox "You saved the files as " & .Filename
    End With

  2. Default Re: VB6 Common Dialog Save

    notsosmart@notsosmart.fen wrote:
    > I want to save file Punk_History.def to a directory chosen by the
    > user. When I execute the code below, the dialog box says the file has
    > been saved. Problem is that the file does not exist in the directory
    > I chose to save it in. Why doesn't it work?
    >
    >
    > Dim Pathy as string
    > Pathy = "C:\Program Files\Games\"
    >
    > With CommonDialog
    > .DialogTitle = "Archive File - Punk_History.def"
    > .CancelError = True
    > .Flags = cdlOFNHideReadOnly + cdlOFNOverwritePrompt +
    > cdlOFNPathMustExist + cdlOFNNoChangeDir
    > .Filter = "All Files(*.def)|*.def"
    > .FilterIndex = 1 '1 = Save and 2 = Open
    > .DefaultExt = ".abd"
    > .Filename = "Punk_History.def"
    > .InitDir = Pathy
    > .ShowSave
    > MsgBox "You saved the files as " & .Filename
    > End With



    The Common Dialog box allows you to pick, or type in a file name to save the
    file as, it doesn't save anything in and of itself. You'd need to redo your
    code above as ...

    Everything within your With statement except the MsgBox Statement
    Insert code here to actually create the file and write the information into
    it then close the file
    Your MsgBox reporting a successful save, or a failed one if it didn't work.

    Hope this is some help.


    Best,
    Bill



  3. Default Re: VB6 Common Dialog Save

    Hi,

    Perhaps you might like to try this Code:

    ********************************************************
    Private Sub Command1_Click()

    On Error GoTo errhandler

    Dim Pathy, x As String

    Pathy = "C:\Program Files\Games"

    'Firstly, check if the Folder exists. If not, then create it...
    x = Dir(Pathy, 16)
    If x = "" Then
    MkDir Pathy
    Else
    End If

    With CommonDialog1
    .DialogTitle = "Archive File - Punk_History.def"
    .CancelError = True
    .flags = cdlOFNHideReadOnly
    .flags = cdlOFNOverwritePrompt
    .flags = cdlOFNPathMustExist
    .flags = cdlOFNNoChangeDir
    .Filter = "All Files(*.def)|*.def"
    .FilterIndex = 1 '1 = Save and 2 = Open 'This is used to specify which
    extension is displayed on top.
    .DefaultExt = ".abd"
    .FileName = "Punk_History.def"
    .InitDir = Pathy
    .ShowSave
    End With

    'At this point, I don't know where the File "Punk_History.def" is located,
    'so I will assume that it is in the Folder where you are running the VB App.
    'If not, then you will have to change the path...

    Open App.Path & "\Punk_History.def" For Input As #1
    Open CommonDialog1.FileName For Output As #2
    Do Until EOF(1)
    Line Input #1, x
    Print #2, x
    Loop
    Close

    'Now, check if the file is in the Pathy folder

    x = Dir(CommonDialog1.FileName, 0)
    If Not x = "" Then
    MsgBox "You Saved the File as " & CommonDialog1.FileName, vbInformation,
    "File Test"
    Else
    MsgBox "FAILURE! The File was NOT Saved.", vbCritical, "File Test"
    End If

    Exit Sub

    done1:
    Exit Sub

    errhandler:
    Close
    If Left(Error, 6) = "Cancel" Then Resume done1 Else
    MsgBox Error
    Resume done1

    End Sub
    ********************************************************
    Regards,

    Rod Johnson
    unique@eircom.net


    <notsosmart@notsosmart.fen> wrote in message
    news:32g9b35pi3hpb68v38bf6jb4028dsk0qba@4ax.com...
    >I want to save file Punk_History.def to a directory chosen by the
    > user. When I execute the code below, the dialog box says the file has
    > been saved. Problem is that the file does not exist in the directory
    > I chose to save it in. Why doesn't it work?
    >
    >
    > Dim Pathy as string
    > Pathy = "C:\Program Files\Games\"
    >
    > With CommonDialog
    > .DialogTitle = "Archive File - Punk_History.def"
    > .CancelError = True
    > .Flags = cdlOFNHideReadOnly + cdlOFNOverwritePrompt +
    > cdlOFNPathMustExist + cdlOFNNoChangeDir
    > .Filter = "All Files(*.def)|*.def"
    > .FilterIndex = 1 '1 = Save and 2 = Open
    > .DefaultExt = ".abd"
    > .Filename = "Punk_History.def"
    > .InitDir = Pathy
    > .ShowSave
    > MsgBox "You saved the files as " & .Filename
    > End With




  4. Default Re: VB6 Common Dialog Save

    Hi Again,

    Just noticed when viewing the Group Posting of the Code I sent, that some of
    the
    Lines of Code were wrapped around where they should not be. Be careful and
    sort these out or you will have errors.

    If you have any other questions, please contact me.

    Regards, Rod


    <notsosmart@notsosmart.fen> wrote in message
    news:32g9b35pi3hpb68v38bf6jb4028dsk0qba@4ax.com...
    >I want to save file Punk_History.def to a directory chosen by the
    > user. When I execute the code below, the dialog box says the file has
    > been saved. Problem is that the file does not exist in the directory
    > I chose to save it in. Why doesn't it work?
    >
    >
    > Dim Pathy as string
    > Pathy = "C:\Program Files\Games\"
    >
    > With CommonDialog
    > .DialogTitle = "Archive File - Punk_History.def"
    > .CancelError = True
    > .Flags = cdlOFNHideReadOnly + cdlOFNOverwritePrompt +
    > cdlOFNPathMustExist + cdlOFNNoChangeDir
    > .Filter = "All Files(*.def)|*.def"
    > .FilterIndex = 1 '1 = Save and 2 = Open
    > .DefaultExt = ".abd"
    > .Filename = "Punk_History.def"
    > .InitDir = Pathy
    > .ShowSave
    > MsgBox "You saved the files as " & .Filename
    > End With




  5. Default Re: VB6 Common Dialog Save

    Hi,

    In re-running the Code I sent to you, I found that the Overwrite Statement
    is not
    always reliable. If this happens, then insert this Code below under "End
    With"

    Regards, Rod
    *************************************
    x = Dir(CommonDialog1.FileName, 0)
    If Not x = "" Then
    x = MsgBox("This File Already Exists!" & vbCrLf & "Do You Wish to Overwrite
    It?", vbQuestion & vbYesNo, "File Test")
    If x = vbNo Then Exit Sub Else
    Else
    End If
    *************************************
    <notsosmart@notsosmart.fen> wrote in message
    news:32g9b35pi3hpb68v38bf6jb4028dsk0qba@4ax.com...
    >I want to save file Punk_History.def to a directory chosen by the
    > user. When I execute the code below, the dialog box says the file has
    > been saved. Problem is that the file does not exist in the directory
    > I chose to save it in. Why doesn't it work?
    >
    >
    > Dim Pathy as string
    > Pathy = "C:\Program Files\Games\"
    >
    > With CommonDialog
    > .DialogTitle = "Archive File - Punk_History.def"
    > .CancelError = True
    > .Flags = cdlOFNHideReadOnly + cdlOFNOverwritePrompt +
    > cdlOFNPathMustExist + cdlOFNNoChangeDir
    > .Filter = "All Files(*.def)|*.def"
    > .FilterIndex = 1 '1 = Save and 2 = Open
    > .DefaultExt = ".abd"
    > .Filename = "Punk_History.def"
    > .InitDir = Pathy
    > .ShowSave
    > MsgBox "You saved the files as " & .Filename
    > End With




  6. Default Re: VB6 Common Dialog Save


    "Rod Johnson" <unique@eircom.net> wrote in message
    news:Xtfti.21299$j7.381599@news.indigo.ie...
    > Hi,
    >
    > In re-running the Code I sent to you, I found that the Overwrite Statement is
    > not
    > always reliable. If this happens, then insert this Code below under "End With"
    >


    Your code contained:
    .flags = cdlOFNHideReadOnly
    .flags = cdlOFNOverwritePrompt
    .flags = cdlOFNPathMustExist
    .flags = cdlOFNNoChangeDir

    which makes .Flags = cdlOFNNoChangeDir, with none of the other three set.

    You need to Or the flags together:
    .Flags = cdlOFNHideReadOnly _
    Or cdlOFNOverwritePrompt _
    Or cdlOFNPathMustExist _
    Or cdlOFNNoChangeDir




  7. Default Re: VB6 Common Dialog Save

    On Sat, 4 Aug 2007 22:15:06 +0100, "Rod Johnson" <unique@eircom.net>
    wrote:

    >Hi,
    >
    >Perhaps you might like to try this Code:
    >
    >********************************************************
    >Private Sub Command1_Click()
    >
    >On Error GoTo errhandler
    >
    >Dim Pathy, x As String
    >
    >Pathy = "C:\Program Files\Games"
    >
    >'Firstly, check if the Folder exists. If not, then create it...
    >x = Dir(Pathy, 16)
    >If x = "" Then
    >MkDir Pathy
    >Else
    >End If
    >
    >With CommonDialog1
    > .DialogTitle = "Archive File - Punk_History.def"
    > .CancelError = True
    > .flags = cdlOFNHideReadOnly
    > .flags = cdlOFNOverwritePrompt
    > .flags = cdlOFNPathMustExist
    > .flags = cdlOFNNoChangeDir
    > .Filter = "All Files(*.def)|*.def"
    > .FilterIndex = 1 '1 = Save and 2 = Open 'This is used to specify which
    >extension is displayed on top.
    > .DefaultExt = ".abd"
    > .FileName = "Punk_History.def"
    > .InitDir = Pathy
    > .ShowSave
    >End With
    >
    >'At this point, I don't know where the File "Punk_History.def" is located,
    >'so I will assume that it is in the Folder where you are running the VB App.
    >'If not, then you will have to change the path...
    >
    >Open App.Path & "\Punk_History.def" For Input As #1
    >Open CommonDialog1.FileName For Output As #2
    >Do Until EOF(1)
    >Line Input #1, x
    >Print #2, x


    Line Input and Print work on a text file. Punk_History.def is a
    binary file, not a text file. Since I couldn't use CommonDialog to
    copy a binary file, I used another solution. I use the CommonDialog
    because it is familiar to all users, but the file copying is using the
    FileSystemObject. The darn thing works. The user uses the
    commondialog to determine where to copy the file to, and fPath does
    the actual copying.

    Dim fPath As New FileSystemObject, FilePath

    Pathy = "C:\Program Files\Games"

    With CommonDialog
    On Error GoTo Pinko
    .DialogTitle = "Archive File - Punk_History.def"
    .CancelError = True
    .Flags = cdlOFNHideReadOnly + cdlOFNOverwritePrompt +
    cdlOFNPathMustExist + cdlOFNNoChangeDir '&H1000 Or &H200000 Or &H8 Or
    &H2 Or &H800
    .Filter = "All Files(*.def)|*.def"
    .FilterIndex = 1 '1 = Save and 2 = Open
    .DefaultExt = ".def"
    .Filename = "Punk_History.def"
    .InitDir =Pathy
    .ShowSave
    FilePath = .Filename
    If Err.Number Then
    'Caption = "Error"
    fPath.CopyFile Pathy & "\" & "Punk_History.def", FilePath,
    False
    Else
    'Caption = "Overwrite"
    fPath.CopyFile Pathy & "\" & "Punk_History.def", FilePath,
    True
    End If
    End With

    Exit Sub

    Pinko:
    If Err.Number = 32755 Then
    'User hit the Cancel button
    Exit Sub
    End If



  8. Default Re: VB6 Common Dialog Save

    Well, most people with any sense disable the FSO!
    Good luck, happy trails!
    Freaking System Obombonation!

    On Aug 5, 6:18 am, notsosm...@notsosmart.fen wrote:
    > On Sat, 4 Aug 2007 22:15:06 +0100, "Rod Johnson" <uni...@eircom.net>
    > wrote:
    >
    >
    >
    > >Hi,

    >
    > >Perhaps you might like to try this Code:

    >
    > >********************************************************
    > >Private Sub Command1_Click()

    >
    > >On Error GoTo errhandler

    >
    > >Dim Pathy, x As String

    >
    > >Pathy = "C:\Program Files\Games"

    >
    > >'Firstly, check if the Folder exists. If not, then create it...
    > >x = Dir(Pathy, 16)
    > >If x = "" Then
    > >MkDir Pathy
    > >Else
    > >End If

    >
    > >With CommonDialog1
    > > .DialogTitle = "Archive File - Punk_History.def"
    > > .CancelError = True
    > > .flags = cdlOFNHideReadOnly
    > > .flags = cdlOFNOverwritePrompt
    > > .flags = cdlOFNPathMustExist
    > > .flags = cdlOFNNoChangeDir
    > > .Filter = "All Files(*.def)|*.def"
    > > .FilterIndex = 1 '1 = Save and 2 = Open 'This is used to specify which
    > >extension is displayed on top.
    > > .DefaultExt = ".abd"
    > > .FileName = "Punk_History.def"
    > > .InitDir = Pathy
    > > .ShowSave
    > >End With

    >
    > >'At this point, I don't know where the File "Punk_History.def" is located,
    > >'so I will assume that it is in the Folder where you are running the VB App.
    > >'If not, then you will have to change the path...

    >
    > >Open App.Path & "\Punk_History.def" For Input As #1
    > >Open CommonDialog1.FileName For Output As #2
    > >Do Until EOF(1)
    > >Line Input #1, x
    > >Print #2, x

    >
    > Line Input and Print work on a text file. Punk_History.def is a
    > binary file, not a text file. Since I couldn't use CommonDialog to
    > copy a binary file, I used another solution. I use the CommonDialog
    > because it is familiar to all users, but the file copying is using the
    > FileSystemObject. The darn thing works. The user uses the
    > commondialog to determine where to copy the file to, and fPath does
    > the actual copying.
    >
    > Dim fPath As New FileSystemObject, FilePath
    >
    > Pathy = "C:\Program Files\Games"
    >
    > With CommonDialog
    > On Error GoTo Pinko
    > .DialogTitle = "Archive File - Punk_History.def"
    > .CancelError = True
    > .Flags = cdlOFNHideReadOnly + cdlOFNOverwritePrompt +
    > cdlOFNPathMustExist + cdlOFNNoChangeDir '&H1000 Or &H200000 Or &H8 Or
    > &H2 Or &H800
    > .Filter = "All Files(*.def)|*.def"
    > .FilterIndex = 1 '1 = Save and 2 = Open
    > .DefaultExt = ".def"
    > .Filename = "Punk_History.def"
    > .InitDir =Pathy
    > .ShowSave
    > FilePath = .Filename
    > If Err.Number Then
    > 'Caption = "Error"
    > fPath.CopyFile Pathy & "\" & "Punk_History.def", FilePath,
    > False
    > Else
    > 'Caption = "Overwrite"
    > fPath.CopyFile Pathy & "\" & "Punk_History.def", FilePath,
    > True
    > End If
    > End With
    >
    > Exit Sub
    >
    > Pinko:
    > If Err.Number = 32755 Then
    > 'User hit the Cancel button
    > Exit Sub
    > End If




  9. Default Re: VB6 Common Dialog Save

    On 5 Aug, 14:18, notsosm...@notsosmart.fen wrote:

    > Punk_History.def is a binary file,
    > not a text file.


    This is the first time you've told us what kind of file you are
    dealing with and until that little secret was out of the bag the other
    respondents simply posted a sample showing you how to write a text
    based data file purely as an example. The main point of their
    responses was to inform you that the CommonDialog does not actually
    write any files for you. They probably assumed that once they had told
    you that little fact you would be able to write the file yourself
    using a method suitable to the file you are dealing with.

    > I use a CommonDialog because it is familiar to
    > all users, but the file copying [since I was taught
    > how the CommonDialog works by the previous kind
    > reponses to my question!!!] is using the
    > FileSystemObject.


    Now it appears that you are copying a file [where the meaning is quite
    clear] instead of writing one [where it is not clear, because you
    could have meant either crerating from new or copying or almost
    anything]. This is the first time you have told us that you are
    copying an existing file rather than creating one.

    > The darn thing works [the FileSystem object]


    Not on my system it doesn't. Nor on my wife's laptop. And I've just
    nipped over to Uncle Charlie's Kebab shop where he does the accounts
    and, blow me down with a feather, it doesn't work on his computer
    either! I wonder why? Is it perhaps because the FileSystem object
    relies on a scripting system that is historically viewed as a
    potential virus delivery system due to the fact that such scripts can
    be contained in otherwise innocuous files such as word processor
    documents and spreadsheets and things? Do you think the administrator
    might have disabled the little beast in order to protect his sytem
    from it? How sad. I would advise you to follow the advice of Uncle
    Charlie in the Kebab shop and ditch the FSO :-)

    > Line Input and Print work on a text file.


    Ditch the FileSystem object and have a look at standard VB6 file
    handling. Regarding your comments about Input and Print (which of
    course deal mostly with ascii data or ascii repesentations of the
    contents of variables of one sort or another, since that is their job)
    have you looked at all the other built in VB file I/O methods? You'll
    find all sorts of things such as Open for Binary and Get and Put and
    lots of other stuff that allows you to handle files and file data in
    just about any way you wish, including very easy binary data handling.

    > The user uses the commondialog to determine
    > where to copy the file to, and fPath [part of
    > my obnoxious and foul FSO code ;-)] does
    > the actual copying.


    Check out the VB FileCopy statement :-)

    Mike





  10. Default Re: VB6 Common Dialog Save

    On the other hand, Mike, perhaps he is always executing in his own
    environment and neither he, nor a system administrator, has chosen to
    disable FSO (and, if really careful, search and destroy any "rogue
    reinstalls" of the WSH on every startup), as many do. If you can count on
    it being there, FSO pretty much works as advertised, though for the things I
    do, it has never proven any better, and sometimes not so good as, regular,
    traditional VB File I/O.

    I remember FSO being highly touted it in a column in one of the trade
    magazines. You'd have thought it was the greatest discovery since slicing
    bread (or an even more monumental discovery sometimes used as a simile), but
    for each of the examples used, I created a File I/O example that did exactly
    the same thing each with at least one less line of code. When I e-mailed
    about it, the columnist had a hard time not admitting that someone at
    Microsoft had done a good sales job about the wondrousness of FSO.

    A line of code, more or less, is no big deal, but why spend time and effort
    to learn a "new thing," in order to be even minutely LESS efficient, even if
    you could count on it being in random systems where your code might be
    executed (which you can't)?

    Larry


    "Mike Williams" <gagamomo@yahoo.co.uk> wrote in message
    news:1186473538.964936.39480@w3g2000hsg.googlegroups.com...
    > On 5 Aug, 14:18, notsosm...@notsosmart.fen wrote:
    >
    >> Punk_History.def is a binary file,
    >> not a text file.

    >
    > This is the first time you've told us what kind of file you are
    > dealing with and until that little secret was out of the bag the other
    > respondents simply posted a sample showing you how to write a text
    > based data file purely as an example. The main point of their
    > responses was to inform you that the CommonDialog does not actually
    > write any files for you. They probably assumed that once they had told
    > you that little fact you would be able to write the file yourself
    > using a method suitable to the file you are dealing with.
    >
    >> I use a CommonDialog because it is familiar to
    >> all users, but the file copying [since I was taught
    >> how the CommonDialog works by the previous kind
    >> reponses to my question!!!] is using the
    >> FileSystemObject.

    >
    > Now it appears that you are copying a file [where the meaning is quite
    > clear] instead of writing one [where it is not clear, because you
    > could have meant either crerating from new or copying or almost
    > anything]. This is the first time you have told us that you are
    > copying an existing file rather than creating one.
    >
    >> The darn thing works [the FileSystem object]

    >
    > Not on my system it doesn't. Nor on my wife's laptop. And I've just
    > nipped over to Uncle Charlie's Kebab shop where he does the accounts
    > and, blow me down with a feather, it doesn't work on his computer
    > either! I wonder why? Is it perhaps because the FileSystem object
    > relies on a scripting system that is historically viewed as a
    > potential virus delivery system due to the fact that such scripts can
    > be contained in otherwise innocuous files such as word processor
    > documents and spreadsheets and things? Do you think the administrator
    > might have disabled the little beast in order to protect his sytem
    > from it? How sad. I would advise you to follow the advice of Uncle
    > Charlie in the Kebab shop and ditch the FSO :-)
    >
    >> Line Input and Print work on a text file.

    >
    > Ditch the FileSystem object and have a look at standard VB6 file
    > handling. Regarding your comments about Input and Print (which of
    > course deal mostly with ascii data or ascii repesentations of the
    > contents of variables of one sort or another, since that is their job)
    > have you looked at all the other built in VB file I/O methods? You'll
    > find all sorts of things such as Open for Binary and Get and Put and
    > lots of other stuff that allows you to handle files and file data in
    > just about any way you wish, including very easy binary data handling.
    >
    >> The user uses the commondialog to determine
    >> where to copy the file to, and fPath [part of
    >> my obnoxious and foul FSO code ;-)] does
    >> the actual copying.

    >
    > Check out the VB FileCopy statement :-)
    >
    > Mike
    >
    >
    >
    >




+ Reply to Thread
Page 1 of 2 1 2 LastLast

Similar Threads

  1. Replies: 0
    Last Post: 11-19-2007, 08:10 AM
  2. Replies: 0
    Last Post: 11-19-2007, 06:41 AM
  3. Replies: 0
    Last Post: 11-16-2007, 11:24 AM
  4. Replies: 0
    Last Post: 11-16-2007, 11:16 AM
  5. How to Show Common Dialog Control like Open / Save on Web using AS
    By Application Development in forum Inetserver
    Replies: 3
    Last Post: 04-20-2006, 10:53 AM