Results 1 to 10 of 10

Thread: writing data to file - vertically (new line).

  1. #1

    Thread Starter
    New Member Highroller's Avatar
    Join Date
    Mar 2001
    Posts
    14

    Red face

    when the program writes to the text file, the data continues to be written horizontally instead of writing to a newline.

    here's the code i am using:

    Open App.Path & "\data.txt" For Append As #1
    For i = 0 To 8

    Write #1, txtField(i).Text,

    Next i
    Close #1


    eg: data.txt
    "132456","R.","Kelly","1","2","3","4","5","6","987654","Michael","Jordan","6","5","4","3","2","1",et c..

    want:
    "132456","R.","Kelly","1","2","3","4","5","6" (without comma at the end)
    "987654","Michael","Jordan","6","5","4","3","2","1"
    etc..


    would anyone know how to make it move to newline?

    thanks.

  2. #2
    AIS_DK
    Guest
    When using write() I don't think you will be able to create a new line, since write() doesn't support this.

    You would therefore have to swicth to another way of writing to the file.

    If you just want this structure you could write:

    dim strTmp as string
    dim i as byte

    Open App.path & "\data.txt" for Append as #1
    For i=0 to 8
    strTmp = chr(34) & txtField(i).Text & Chr(34) & chr(44)
    Next i
    strTmp = Left(StrTmp, len(StrTmp)-1) & chr(13) & chr(10)

    Print #1, strTmp
    Close #1

    I think this should do it, however I havn't tested it.

  3. #3

    Thread Starter
    New Member Highroller's Avatar
    Join Date
    Mar 2001
    Posts
    14

    Unhappy o.k

    o.k i'll give it a try.
    thanks.

  4. #4
    Lively Member
    Join Date
    Apr 2001
    Posts
    111
    Surely you can just do this?

    Code:
    Open App.Path & "\data.txt" For Append As #1 
    For i = 0 To 8 
    
    Write #1, txtField(i).Text & vbCrLf, 
    
    Next i 
    Close #1

  5. #5
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    I only ever use output like follows :

    Code:
    Print #1, something
    if thats of any help
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  6. #6

    Thread Starter
    New Member Highroller's Avatar
    Join Date
    Mar 2001
    Posts
    14
    o.k thanks guys.

    o.k here are the outputs.

    AIS_DK: your method writes the last piece of information and two new lines.

    "(txtField(8).text"
    _
    _


    m0rph: your method writes the information then a newline and in my text boxes there are funny looking squares on the end of the fields.

    "(txtField(1).text
    ","(txtField(2).text
    ","(txtField(3).text
    ","(txtField(4).text


    plenderj: i might play around with Print #1 too.


    thanks guys...

  7. #7
    AIS_DK
    Guest
    Ok my mistake, I wasn't near my computer with VB on, so here is little fix up.

    Print ofcourse terminates any string that you write with a new line, so the correct code should be:

    dim strTmp as string
    dim i as byte

    Open App.path & "\data.txt" for Append as #1
    For i=0 to 8
    strTmp = strTmp & chr(34) & txtField(i).Text & Chr(34) & chr(44)
    Next i

    strTmp = Left(StrTmp, len(StrTmp)-1)

    Print #1, strTmp

    strTmp = ""
    Close #1

    See if that should not fix it

    BTW. Funny looking Squares are mearly characters, that either has no visual "face" or can't be shown by the program you use. IE. If your text reader doesn't interpret TAB, then the program would display the "character" TAB with a square.

  8. #8
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Dont be sad you maggot, just use Print

    Code:
    Dim i As Long
    For i = 0 to txtField.Count -1
        Print #1, txtField(i).Text
    Next i
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  9. #9
    spetnik
    Guest
    maybe instead of VBCRLF, just use either VBCR or VBLF.
    (Try both, not sure which would do it)

  10. #10

    Thread Starter
    New Member Highroller's Avatar
    Join Date
    Mar 2001
    Posts
    14

    thanks

    thanks guys for your help, most of the help posted produced what i wanted in the end.

    thanks.

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