Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

How To Save Files - Visual Basic 6 Enterprise Edition

the_plaguethe_plague Member Posts: 8
I need help saving files using visual basic 6 enterprise edition.
(((sorry if this post doesnt belong here)))

I have a TEXTBOX, COMMONDIALOG control,& COMMAND BUTTON on my form.
this is the code i put in:

Private Sub SaveButton_Click()
CommonDialog1.DialgTitle = "Save"
CommonDialog1.FileName = "*.txt"
CommonDialog1.InitDir = "C:"
CommonDialog1.Filter = "*.txt"
CommonDialog1.DefaultExt = "*.txt"
End Sub

Whats wrong???

Michael Peacock - Programming Maniac

Comments

  • JonathanJonathan Member Posts: 2,914
    : I need help saving files using visual basic 6 enterprise edition.
    : (((sorry if this post doesnt belong here)))
    Go find the Visual Basic forum for your future VB posts. They're better there.

    :
    : I have a TEXTBOX, COMMONDIALOG control,& COMMAND BUTTON on my form.
    : this is the code i put in:
    :
    : Private Sub SaveButton_Click()
    : CommonDialog1.DialgTitle = "Save"
    : CommonDialog1.FileName = "*.txt"
    : CommonDialog1.InitDir = "C:"
    : CommonDialog1.Filter = "*.txt"
    : CommonDialog1.DefaultExt = "*.txt"
    : End Sub
    :
    : Whats wrong???
    Setting .FileName to "*.txt" is probably not the right thing to do - so get rid of that line. That aside, the rest is just fine. Of course, I guess you want it to do something? ;-)

    You need to call CommonDialog1.ShowSave (if I remember correctly) to bring up the Save File dialog. Once that has happened you can read the filename the user selected from CommonDialog.Filename, then use that in your code to save the file.

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • the_plaguethe_plague Member Posts: 8
    [b][red]This message was edited by the_plague at 2004-1-18 19:52:22[/red][/b][hr]
    : : I need help saving files using visual basic 6 enterprise edition.
    : : (((sorry if this post doesnt belong here)))
    : Go find the Visual Basic forum for your future VB posts. They're better there.
    :
    : :
    : : I have a TEXTBOX, COMMONDIALOG control,& COMMAND BUTTON on my form.
    : : this is the code i put in:
    : :
    : : Private Sub SaveButton_Click()
    : : CommonDialog1.DialgTitle = "Save"
    : : CommonDialog1.FileName = "*.txt"
    : : CommonDialog1.InitDir = "C:"
    : : CommonDialog1.Filter = "*.txt"
    : : CommonDialog1.DefaultExt = "*.txt"
    : : End Sub
    : :
    : : Whats wrong???
    : Setting .FileName to "*.txt" is probably not the right thing to do - so get rid of that line. That aside, the rest is just fine. Of course, I guess you want it to do something? ;-)
    :
    : You need to call CommonDialog1.ShowSave (if I remember correctly) to bring up the Save File dialog. Once that has happened you can read the filename the user selected from CommonDialog.Filename, then use that in your code to save the file.
    :
    : Jonathan
    :
    ok i changed it to this. now it works a little bit better, like it only shows text files when i click my save button.
    heres what i changed it to...
    Private Sub Command2_Click()
    CommonDialog1.DialogTitle = "SaveAs"
    CommonDialog1.Filter = "TextFiles(*.txt)|*.txt"
    CommonDialog1.ShowSave
    End Sub

    But it still doesnt save the file. How am i supposed to use the CommonDialog1.FileName and use it to save my file. What the code and what controls do i need to have with it.


  • WaltPWaltP Member Posts: 335
    : ok i changed it to this. now it works a little bit better, like it only shows text files when i click my save button.
    : heres what i changed it to...
    : Private Sub Command2_Click()
    : CommonDialog1.DialogTitle = "SaveAs"
    : CommonDialog1.Filter = "TextFiles(*.txt)|*.txt"
    : CommonDialog1.ShowSave
    : End Sub
    :
    : But it still doesnt save the file. How am i supposed to use the CommonDialog1.FileName and use it to save my file. What the code and what controls do i need to have with it.
    :
    :
    [b]You[/b] have to save the file. All the common dialog does is get a filename nad path where the file can be saved. Now open the file for output, write the data you want to the file, and close it.

    ----------------
    Walt


  • the_plaguethe_plague Member Posts: 8
    : : ok i changed it to this. now it works a little bit better, like it only shows text files when i click my save button.
    : : heres what i changed it to...
    : : Private Sub Command2_Click()
    : : CommonDialog1.DialogTitle = "SaveAs"
    : : CommonDialog1.Filter = "TextFiles(*.txt)|*.txt"
    : : CommonDialog1.ShowSave
    : : End Sub
    : :
    : : But it still doesnt save the file. How am i supposed to use the CommonDialog1.FileName and use it to save my file. What the code and what controls do i need to have with it.
    : :
    : :
    : [b]You[/b] have to save the file. All the common dialog does is get a filename nad path where the file can be saved. Now open the file for output, write the data you want to the file, and close it.
    :
    : ----------------
    : Walt
    :
    :
    :
    Ok now all i need is how to write the data to the file.
    ------------------------------------------------------------------------
    Dim i As String
    i = Text1.Text
    CommonDialog1.DialogTitle = "Save"
    CommonDialog1.InitDir = "C:"
    CommonDialog1.Filter = "Text Files(*.txt)|*.txt"
    CommonDialog1.ShowSave
    Open (CommonDialog1.FileName) For Append As 1
    ' What goes here
    Close
    ------------------------------------------------------------------------

    Michael Peacock - Programming Maniac

  • melissa_may1melissa_may1 Member Posts: 937
    Did you check out the answer to this in the VB forum? Somebody (it was you?) posted the exact same quesiton, and it has been answered there.

    Good luck!



    [purple]Melissa[/purple]

  • MAANNSSOORMAANNSSOOR Member Posts: 4
    This post has been deleted.
  • MAANNSSOORMAANNSSOOR Member Posts: 4
    hi,,,,

    i'm haveing the same problem , but i want to save pics


    any way here is the script you asked about

    open commondialog1.filename for output as #1

    write #1, "what ever you want to write in your file"

    close #1

    also there are many uses for this script such as writing and adding
    also creating new file to write in .
    ----
    open commondialog1.filename for append as #1
    input
    output
    ----
    append= write from the last line , without deleting former linse
    input =read from files
    output=save values ,creat new file or replace it if it was there
    ----

    also if you want to write in the same line you should use this
    --
    write #1 ,"what ever" ; "what ever"
    --
    you should add ;
    a semicolon between the expressions

    --
    to read all the line

    lineiput #1 ,string


    also to kill the file

    kill nameoffile

    ex:


    Kill "C:mm.txt"


    that will delete the file


    ----------------
    Private Sub Command1_Click()

    CommonDialog1.Filter = "text [*.txt]|*.txt"

    CommonDialog1.ShowSave

    Open CommonDialog1.FileName For Output As #1

    Write #1, "the access"; "faild"

    Close #1

    Exit Sub


    End Sub


    Private Sub Command2_Click()
    Dim man, nan As String

    CommonDialog1.ShowOpen

    Open CommonDialog1.FileName For Input As #1

    Input #1, man, nan

    Close #1

    Text1.Text = man

    Text2.Text = nan


    End Sub


    /// this script will save 2 words in to the file after clicking command1
    and will read it and show it in the textbox by clicking command2

    hope you got it :)


    any questions






Sign In or Register to comment.