Hi all,

I need to read my text file that contain first name, last name, age and blood types.
All of it separated by semicolon sign.
Eg: Trudy;Canavan;41;AB

What i need to achieve is read the text file into different arrays.

Please help me.
Thank you

Recommended Answers

All 2 Replies

Something like this should working :

Function ReadFileText(ByVal filename As String) As String
        Dim handle As Integer

           ' ensure that the file exists
        If Len(Dir$(filename)) = 0 Then
            Err.Raise 53  ' File not found
        End If

           ' open in binary mode
        handle = FreeFile
        Open filename$ For Binary As #handle
           ' read the string and close the file
        ReadFileText = Space$(LOF(handle))
        Get #handle, , ReadFileText
        Close #handle
End Function

Private Sub Command1_Click()
Dim temp() As String
Dim temp2() As String
Dim FNArr() As String
Dim LNArr() As String
Dim AgeArr() As String
Dim BloddArr() As String

    ' split text file by new line (enter)
    temp = Split(ReadFileText("D:\Dani.txt"), vbNewLine)

    ' get how many rows in array
    x = UBound(temp) 

    ' redim each array with new rows. 
    ReDim FNArr(x)
    ReDim LNArr(x)
    ReDim AgeArr(x)
    ReDim BloddArr(x)

    For i = 0 To x
        ' split each line by semicolon sign
        temp2 = Split(temp(i), ";")

        ' write each data to proper arrays
        FNArr(i) = temp2(0)
        LNArr(i) = temp2(1)
        AgeArr(i) = temp2(2)
        BloddArr(i) = temp2(3)
    Next i

End Sub
commented: Thanks for the great code sir. +1

Wow. This really great sir.
Many thanks for the helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.