Results 1 to 29 of 29

Thread: saving multiple textboxes to 1 file

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2001
    Location
    Belgium
    Posts
    18

    Post saving multiple textboxes to 1 file

    how do i save multiple textboxes to one file for example a textfile

  2. #2
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Gig Harbor, WA; Posts: 89950
    Posts
    360
    OK Lets say there a re 3 text boxes.


    Option Explicit
    Dim str(2) As String 'array holds 3 strings 0, 1, 2


    Private Sub cmdSave_Click()
    str(0) = Text1
    str(1) = Text2
    str(2) = Text3

    Open App.Path & "\words.txt" For Output As #1
    'Then save the strings to the file:
    Write #1, str(0), str(1), str(2)

    Close #1
    End Sub

    OK I wrote the app in full,
    Last edited by Lee M.; Jun 30th, 2001 at 01:15 PM.
    Mahalo
    VB6(SP5), VC++, COBOL, Basic, JAVA
    MBA, MCSD, MCSE, A+
    Computer Forensics

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2001
    Location
    Belgium
    Posts
    18

    Angry doesn't work

    does someone else have an idea that actually works??

  4. #4
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Gig Harbor, WA; Posts: 89950
    Posts
    360
    It works. Let me see your code. You will not get answers with that attitude. If you look at the text file your data will be there. If you need to retrieve the data you will need to add the code for that.
    As I have said numerous times, This will get you on the right path. I am not here to do your work for you.
    Mahalo
    VB6(SP5), VC++, COBOL, Basic, JAVA
    MBA, MCSD, MCSE, A+
    Computer Forensics

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Apr 2001
    Location
    Belgium
    Posts
    18

    Unhappy but

    i can't start retrieving data if the saving piece doesn't even work

  6. #6
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Gig Harbor, WA; Posts: 89950
    Posts
    360
    Post your code
    Mahalo
    VB6(SP5), VC++, COBOL, Basic, JAVA
    MBA, MCSD, MCSE, A+
    Computer Forensics

  7. #7
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Gig Harbor, WA; Posts: 89950
    Posts
    360
    OK I wrote the code in it's entirety for you. Look above, I didn't want to do it, but you seemed stumped.
    Lee

    Now, if you want to retrieve the data change the code as follows:

    Clear the textboxes:
    txt1 = ""
    txt2 = ""
    txt3 = ""

    Open app.path & "\words.txt" For Input As #1
    Input #1, str(0), str(1), str(2)
    Then set them to the textboxes

    txt1 = str(0)
    txt2 = str(1)
    txt3 = str(2)
    close #1


    Does that make sense?
    Last edited by Lee M.; Jun 30th, 2001 at 01:24 PM.
    Mahalo
    VB6(SP5), VC++, COBOL, Basic, JAVA
    MBA, MCSD, MCSE, A+
    Computer Forensics

  8. #8

    Thread Starter
    Junior Member
    Join Date
    Apr 2001
    Location
    Belgium
    Posts
    18

    Talking thnx

    it works now thnx allot sorry i was a bit bold in the beginning

  9. #9

    Thread Starter
    Junior Member
    Join Date
    Apr 2001
    Location
    Belgium
    Posts
    18

    Question How do I?

    use a commondialog in this piece of code showopen and showsave would be nice for the user to determine where to save and wich file to open

  10. #10
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Gig Harbor, WA; Posts: 89950
    Posts
    360
    Add the control to the form(s)
    Let's say it's called cdl1

    cdl1.showopen (will show the Open screen)
    cdl1.ShowSave (will show the save screen)

    Look up Common Dialog Box in the Help file it's quite descriptive
    Mahalo
    VB6(SP5), VC++, COBOL, Basic, JAVA
    MBA, MCSD, MCSE, A+
    Computer Forensics

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Apr 2001
    Location
    Belgium
    Posts
    18

    Question i already new that but

    when i save a file there is no file created now what?

  12. #12
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397
    Question:

    Do you Know about the different ways to Open
    a file, ie... Append, Read, Write, and so on?

    I would not worry about a Common Dialog Box, and how to
    pass strings & values to and from it, until I had the code to
    do the actual reading and writeing accomplished.

    MyFileNum = freefile 'Look Up FreeFile
    Open "C:\temp.text" for OutPut as #MyFileNum 'Look Up Open, Output
    Print #MyFileNum, "This is the First Line"
    Print #MyFileNum, "This is the Second Line"
    Close #MyFileNum


    MyFileNum = freefile
    open "c:\temp.text" for input as #MyFileNum
    While Not EOF(MyFileNum)
    Line Input #MyFileNum, X$ 'Look up Line Input
    msgbox X$
    wend
    close #MyFileNum
    msgbox "All Done"

    -The above is for illustration purpose
    -Hop this Helps
    -Lou

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Apr 2001
    Location
    Belgium
    Posts
    18

    ??

    i know append and so on and thnx for that last piece of code but now i still don't have my question answered there is no file created but here's my code could someone please tell me the changes i have to make

    Private Sub mnusave_Click(Index As Integer)
    str(0) = txtZoon.Text
    str(1) = txtDochter.Text
    str(2) = txtVader1.Text

    CMDialog1.ShowSave
    CMDialog1.FileName = txtringnummer.Text
    If CMDialog1.CancelError Then End Sub

    Open App.Path & "\words.txt" For Output As #1
    'Then save the strings to the file:
    Write #1, str(0), str(1), str(2)

    Close #1
    End Sub

    Private Sub mnuOpen_Click(Index As Integer)
    'Clear the textboxes:
    txtZoon.Text = ""
    txtDochter.Text = ""
    txtVader1.Text = ""

    CMDialog1.ShowOpen
    Open App.Path & "\words.txt" For Input As #1
    Input #1, str(0), str(1), str(2)
    'Then set them to the textboxes
    If CMDialog1.CancelError Then End Sub

    txtZoon.Text = str(0)
    txtDochter.Text = str(1)
    txtVader1.Text = str(2)
    Close #1

  14. #14
    Frenzied Member Skitchen8's Avatar
    Join Date
    Feb 2001
    Location
    Binghamotn, NY
    Posts
    1,943
    I don't get why your using the common dialog to show the open box, the code you have has nothing to do with the common dialog, your opening something regardless of what you pick in the common-dialog box. if you want to link it to the common dialog you should use code like
    with commondialog1
    .filter "text files|*.txt"
    .showopen
    end with
    'im sorta new so you have to put your own code in here
    'that would split up the text file into your different parts
    'probably use the Len command, and assign each different
    'part to each text-box

    [/end vb code]

    sorry if that wasn't what you wanted i tried at least... now can i gutter the thread since i took my time to post in it??
    Government is another way to say better…than…you.
    It’s like ice but no pick, a murder charge that won’t stick,
    it’s like a whole other world where you can smell the food,
    but you can’t touch the silverware.
    Huh, what luck. Fascism you can vote for.
    Humph, isn’t that sweet?
    And we’re all gonna die some day, because that’s the American way
    -Stone Sour

  15. #15

    Thread Starter
    Junior Member
    Join Date
    Apr 2001
    Location
    Belgium
    Posts
    18

    Unhappy sorry but that didn't help

    can anyone help me i need to save multiple text boxes to 1 file and i want to use an dialogbox or something else so the user can decide where to save the file my code is posted above but in that state their is no file created this is going for a week now will someone please come up with some answers??????

  16. #16
    Frenzied Member Skitchen8's Avatar
    Join Date
    Feb 2001
    Location
    Binghamotn, NY
    Posts
    1,943
    here is a sample i made that does what you want... i think

    the design is very crude, but i just made it in like 10 mins just to see if i could do it
    Attached Files Attached Files
    Last edited by Skitchen8; Jul 2nd, 2001 at 02:32 PM.
    Government is another way to say better…than…you.
    It’s like ice but no pick, a murder charge that won’t stick,
    it’s like a whole other world where you can smell the food,
    but you can’t touch the silverware.
    Huh, what luck. Fascism you can vote for.
    Humph, isn’t that sweet?
    And we’re all gonna die some day, because that’s the American way
    -Stone Sour

  17. #17
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397
    Same here.
    CommonDialog Open SaveAs, TextBoxes, Everything.

    Except Comments.

    Ask if its Hazy.

    -Lou
    Attached Files Attached Files

  18. #18
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397
    Skitchen8,

    Great Variable name, the value you assign to text4.text!
    Pretty Funny!

    -Just got Posted, See Ya
    -Lou

  19. #19
    Frenzied Member Skitchen8's Avatar
    Join Date
    Feb 2001
    Location
    Binghamotn, NY
    Posts
    1,943
    yea... i waz mad at my bro and hes like 3 so thats all i can call him so i used it as the variable name, did you get it to work all right, and do what you wanted??
    Government is another way to say better…than…you.
    It’s like ice but no pick, a murder charge that won’t stick,
    it’s like a whole other world where you can smell the food,
    but you can’t touch the silverware.
    Huh, what luck. Fascism you can vote for.
    Humph, isn’t that sweet?
    And we’re all gonna die some day, because that’s the American way
    -Stone Sour

  20. #20
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Gig Harbor, WA; Posts: 89950
    Posts
    360
    OK I have been gone, I see you are still stuck on this.

    This is a BRIEF explantion on the Common Dialog Box.
    (Although I don't see why you need to use it)

    Use the save as dialog.
    Put a CommonDialog control on the form and use the following code:


    code:--------------------------------------------------------------------------------
    Private Sub button_Click()
    Dim iFileNum As Integer
    Dim sFileName As String

    With CommonDialog1
    .CancelError = True
    .DefExt = "txt"
    .Filter = "Text files|*.txt|All files|*.*"
    'the above properties can be set during design time
    .Flags = cdlOFNPathMustExist + cldOFNHideReadOnly + cdlOFNOverwritePrompt
    On Error Resume Next
    .ShowSave
    If Err = cdlCancel Then
    'the user click on the cancel button so bail out
    Exit Sub
    End If
    sFileName = .Filename
    End With
    iFileNum = FreeFile
    Open sFileName For Output As iFileNum
    Print #iFileNum, form.textbox.Text
    Close iFileNum

    basic.Text = form.textbox.Text
    End Sub

    Now, before you go and plug this code into your module, it will not work. I did not use your naming conventions. You will need to set the Filters and Flags yourself. I don't see why you need this, because your application saves to a specific file. Unless you want to save multiple files (in which a database may be in order). Read up on the Flags and Filters for the common dialog box. As your code stands now it will open and read the file, it will erase and re write the file, then pull it's data into the GUI.
    Mahalo
    VB6(SP5), VC++, COBOL, Basic, JAVA
    MBA, MCSD, MCSE, A+
    Computer Forensics

  21. #21
    Frenzied Member Skitchen8's Avatar
    Join Date
    Feb 2001
    Location
    Binghamotn, NY
    Posts
    1,943
    I think that we did just fine doing our codes, so stop bein a little butthole!! LOL
    Government is another way to say better…than…you.
    It’s like ice but no pick, a murder charge that won’t stick,
    it’s like a whole other world where you can smell the food,
    but you can’t touch the silverware.
    Huh, what luck. Fascism you can vote for.
    Humph, isn’t that sweet?
    And we’re all gonna die some day, because that’s the American way
    -Stone Sour

  22. #22

    Thread Starter
    Junior Member
    Join Date
    Apr 2001
    Location
    Belgium
    Posts
    18

    Talking thnx allot

    finally it works thnx allot you guys if i could ever do something in return just ask

  23. #23
    Frenzied Member Skitchen8's Avatar
    Join Date
    Feb 2001
    Location
    Binghamotn, NY
    Posts
    1,943
    It was no problem, im happy that you posted this, because i basically taught myself how to do that only because i had to so thank you

    don't tell that to parksie... he'lll want you to bend over and pick up the soap
    Government is another way to say better…than…you.
    It’s like ice but no pick, a murder charge that won’t stick,
    it’s like a whole other world where you can smell the food,
    but you can’t touch the silverware.
    Huh, what luck. Fascism you can vote for.
    Humph, isn’t that sweet?
    And we’re all gonna die some day, because that’s the American way
    -Stone Sour

  24. #24
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397
    NoProb,

    I think we all like to help when we can.

    -Lou

  25. #25
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Gig Harbor, WA; Posts: 89950
    Posts
    360

    Question

    Who ya callin a butthole?
    Mahalo
    VB6(SP5), VC++, COBOL, Basic, JAVA
    MBA, MCSD, MCSE, A+
    Computer Forensics

  26. #26
    Frenzied Member Skitchen8's Avatar
    Join Date
    Feb 2001
    Location
    Binghamotn, NY
    Posts
    1,943
    lol
    Government is another way to say better…than…you.
    It’s like ice but no pick, a murder charge that won’t stick,
    it’s like a whole other world where you can smell the food,
    but you can’t touch the silverware.
    Huh, what luck. Fascism you can vote for.
    Humph, isn’t that sweet?
    And we’re all gonna die some day, because that’s the American way
    -Stone Sour

  27. #27
    Lively Member
    Join Date
    Jul 2001
    Location
    New Hampshire, USA
    Posts
    127

    Re: ??

    Originally posted by Robke

    If CMDialog1.CancelError Then End Sub
    I get a syntax error at the End Sub. Any Ideas?

    [My Code:]

    Private Sub mnuOpen_Click(Index As Integer)
    CommonDialog1.ShowOpen
    If CommonDialog1.CancelError Then End Sub
    Open openpath For Input As #1
    stext = Input(LOF(1), 1)
    Close #1
    RichTextBox1.Text = stext
    End Sub

    [End My Code.]

    Any ideas?

  28. #28
    pathfinder NotLKH's Avatar
    Join Date
    Apr 2001
    Posts
    2,397
    End Sub should be used at the bottom of a procedure only.
    Exit Sub can be used everywhere else to conditionally
    break out of a sub.

    -Lou

  29. #29
    Lively Member
    Join Date
    Jul 2001
    Location
    New Hampshire, USA
    Posts
    127

    Thanks

    Thanks a lot.

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