dcsimg
Results 1 to 10 of 10

Thread: [RESOLVED] writing text file

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    779

    Resolved [RESOLVED] writing text file

    i'm stuck on this, maybe someone could offer some insight. I am creating a text file like this. it works just as it should.

    Code:
    Write #1, CStr(SeqNumber); rs3![ENDORSEMENT]; Addressee; rs3![Address]; rs3![CSZ]; ""; ""; ""; ""; rs3![Barcode]
    my problem is i have a combo box that the user can enter in text. i want to loop through the number of list items entered in the combo box (which i have saved in an array) and add them to the beginning of the text line above.

  2. #2
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: writing text file

    This will save the entire contents of the Combo. Is that what you are after?
    Code:
    Dim i As Long
      Open "c:\ComboBox.txt" For Output As #1
        For i = 0 To Combo1.ListCount - 1
            Combo1.ListIndex = i
            Print #1, Combo1.List(Combo1.ListIndex)
        Next
        Close #1
    End Sub
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    779

    Re: writing text file

    write #1, text1; text2

    if user adds item to combo box then

    write #1 combotext1; text1; text2

    but what if user adds 5 items to combo box? how can i loop through combo and add each entry to begining of the line?

  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,692

    Re: writing text file

    Hack gave you the code to iterate through the combobox items.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    779

    Re: writing text file

    how do i write the item to the beginning of the line of text that already exists? thats my problem.

  6. #6
    Lively Member
    Join Date
    Oct 2007
    Posts
    68

    Re: writing text file

    If you're trying to insert the combo text before the other text, couldn't you string together the combo box items first and then print, something like this?

    Code:
    dim i as long
    dim holdstring as string
    
    for i = 0 to combo1.count -1
        holdstring = holdstring & combo1.list(i) & ";"
    next
    Then do your print stmt...
    Code:
        Open "c:\ComboBox.txt" For Output As #1
        Print #1, holdstring & "any other text you want to print after"
        Close #1

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,692

    Re: writing text file

    Code:
    Dim i As Long
      Open "c:\ComboBox.txt" For Output As #1
        For i = 0 To Combo1.ListCount - 1
            Combo1.ListIndex = i
            Print #1, Combo1.List(Combo1.ListIndex)
        Next
        Write #1, CStr(SeqNumber); rs3![ENDORSEMENT]; Addressee; rs3![Address]; rs3![CSZ]; ""; ""; ""; ""; rs3![Barcode]
        Close #1
    End Sub
    Print will save the text (contents of the line in the ComboBox, in this case) as it is.
    Write will save it with commas between items and quotes around each string item.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    779

    Re: writing text file

    i need it all on the same line. i'm creating a comma delimited text file. each combo item must be enclosed in quotation marks and separated by a comma. that is why i'm using the write function.

  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,692

    Re: writing text file

    Just a slight change
    Code:
    Dim i As Long
      Open "c:\ComboBox.txt" For Output As #1
        For i = 0 To Combo1.ListCount - 1
            Combo1.ListIndex = i
            Write #1, Chr$(34);Combo1.List(Combo1.ListIndex);Chr$(34);",";
        Next
        Write #1, CStr(SeqNumber); rs3![ENDORSEMENT]; Addressee; rs3![Address]; rs3![CSZ]; ""; ""; ""; ""; rs3![Barcode]
        Close #1
    End Sub
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    779

    Re: writing text file

    thanks for the help. turns out you don't have to add your own quotes or commas, the write function does it for you. just make sure to use the semi colon. this is how i did it (i saved the combo into an array):

    Code:
    For y = 0 To UBound(TagLineArray) - 1
        Write #1, TagLineArray(y);
    Next y
    Write #1, rs3![ENDORSEMENT]; Addressee; rs3![Address]; rs3![CSZ]; ""; ""; ""; ""; rs3![Barcode]
    Close #1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width