Results 1 to 6 of 6

Thread: Writing

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Posts
    225
    Hiyas,

    I know how to write an array to a file ...

    Code:
    Dim NumberOfStrings as Integer
    Dim String(2) as String
    String(0) = "This"
    String(1) = " is"
    String(2) = " text!"
    NumberOfStrings = 3
    Open FileName For Output as #1
    Write #1, NumberOfStrings
    For a = 1 to NumberOfStrings
        Write #1, String(a)
    Next a
    Close #1
    This will produce a file like:

    Code:
    0
    "This"," is"," text!"
    How can I write to a file using the same data above, but putting it all on the same line like: (keep in mind I need to use the array, like above)

    Code:
    0,"This"," is"," text!"
    Anyone know?

    -Git

  2. #2
    New Member
    Join Date
    Feb 2000
    Location
    Fayetteville, AR 72701
    Posts
    12
    In your for loop, instead of writing them to the file collect them in a temporary string then write the long string. Like the following:


    Dim NumberOfStrings as Integer
    Dim String(2) as String
    dim temp as string

    String(0) = "This"
    String(1) = " is"
    String(2) = " text!"
    NumberOfStrings = 3
    Open FileName For Output as #1
    temp = NumberOfStrings
    For a = 1 to NumberOfStrings
    temp = temp & String(a)
    Next a
    Write #1, temp
    Close #1
    STEngineer

    visit stengineer.com for all your Star Trek and LCARS Programming needs

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Posts
    225
    Cool, thanks!

    -Git

  4. #4
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Question

    but stengineer sample code will not produce what you mention rite:

    Code:
    0,"This"," is"," text!"
    Where all the double qoute will be missing.



    [Edited by Chris on 01-05-2001 at 04:04 AM]

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jul 2000
    Posts
    225
    It's ok, I changed it slightly and I think it works now...

    But... how do I write to a file withought the ""'s around a string?

    -Git

  6. #6
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Thumbs up

    Juz open the file as Append mode

    Code:
    tmp = Join(Str, Chr(44))
    tmp = NumberOfStrings & Chr(44) & tmp
    
    Open Filename For Append As #1
        Print #1, tmp
    Close #1
    Again, you can not name your Array with String 'coz String is the reserve word in VB.

    Cheers!

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