Results 1 to 2 of 2

Thread: simple quest

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2001
    Posts
    4

    Question

    I have an input text file with data in 4 columns. I want to put this data into an array arr((1 to 20), (1 to 4)) how do i write the 4 columns of data to the specific colum in the array - note the columns are separated by spaces?

  2. #2
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    736
    Something along these lines, presuming you are using Visual Basic 6 so you can use the Split Function.
    Code:
    Private Sub Command1_Click()
        Dim tstArray(1 To 20, 1 To 4) As String
        Dim intfilenum As Integer
        Dim fileName As String
        Dim splitArray() As String
        Dim counter As Integer
        Dim x As Integer
        Dim tempString As String
        fileName = "c:/testfile.txt"
        intfilenum = FreeFile
        Open fileName For Input As #intfilenum
        
        counter = 1
        Do Until EOF(intfilenum)
            Line Input #intfilenum, tempString
            splitArray = Split(tempString, " ")
            tstArray(counter, 1) = splitArray(0)
            tstArray(counter, 2) = splitArray(1)
            tstArray(counter, 3) = splitArray(2)
            tstArray(counter, 4) = splitArray(3)
            counter = counter + 1
        Loop
        Close #intfilenum
        
        For x = 1 To UBound(tstArray)
            Debug.Print tstArray(x, 1) & " " & tstArray(x, 2) & " " & _
                tstArray(x, 3) & " " & tstArray(x, 4)
        Next x
    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