Results 1 to 3 of 3

Thread: Writing to a file

  1. #1

    Thread Starter
    Addicted Member icemanmt78's Avatar
    Join Date
    May 2000
    Posts
    142

    Talking

    I have read in a string

    07/20/00,23,4,14,16

    Then extracted each part formatted it and placed it in a buffer array that contains

    buffer(1) = 20 July 2000
    buffer(2) = 23:45
    buffer(3) = 14
    buffer(4) = 16

    ( If i need to i can use a string that contains the correctly formatted values as follows
    20 July 2000,23:45,14,16)

    I now wish to write the contents of my array or my string to a new text file. I need to write the data as a single line with Speech marks (") and commas as follows:

    "20 July 2000","23:45",14,16

    I only want speech marks around the date and time.

    Any ideas?????

  2. #2
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    It will be easier to use the array (i.e., it will be easier if each field is separate).
    Assuming the buffer array is of type String, your Write statement would look like this:
    Code:
    Write #intOutFile, buffer(1), buffer(2), Val(buffer(3)), Val(buffer(4))
    In general, the Write statement is used to create comma-delimited files. It will automatically enclose String fields in quotes, but will not enclose numeric fields in quotes (which is why the Val function is needed).
    "It's cold gin time again ..."

    Check out my website here.

  3. #3
    Addicted Member
    Join Date
    Jul 2000
    Location
    Scotland
    Posts
    184
    This may be the long way, but it works for me:

    Code:
    Private Sub writeTest()
        Dim buffer(4) As String
        Dim iFile As Integer
        Dim strFileLine As String
        Dim PathToFile1 As String
        Dim strQuotes As String
        
        strQuotes = """"
        
        buffer(1) = "20 July 2000"
        buffer(2) = "23:45"
        buffer(3) = "14"
        buffer(4) = "16"
        
        PathToFile1 = "c:\WINDOWS\Desktop\MyTestFile.txt"
        
        iFile = FreeFile   'Get unused file number.
        Open PathToFile1 For Output As #iFile   'Create file name.
    
        Print #iFile, strQuotes & buffer(1) & strQuotes & "," _
                    & strQuotes & buffer(2) & strQuotes & "," _
                    & buffer(3) & "," & buffer(4)
    
        Close #iFile
    
    End Sub

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