Read comma delimited text flie into vba variables

Using VBA 2000, I need to read a comma seperated text file "C:\Textfile.txt".
It will always have only 1 line.
It could have 2 to 6 values at anytime.
I've attached the code that I've been trying. It is reading the file and storing the line of csv's into sTemp, but I haven't got "Split" to work. Not sure if I just don't know how to use it or if I should try something else.
I need to store each value in a variable. How can I accomplish this?

Dim sLayout, sTemp As String
    Dim Value$
    Open "C:\add_slide.txt" For Input As #2
    Line Input #2, Value$
    sTemp = Value$
    sLayout = Split(sTemp, ",")

Open in new window

Who is Participating?
Rey Obrero (Capricorn1)Commented:

Dim sLayout, sTemp As String
    Dim Value$, j as integer
    Open "C:\add_slide.txt" For Input As #2
    Line Input #2, Value$
    sTemp = Value$
    sLayout = Split(sTemp, ",")

    for j=0 to ubound(sLayout)

          debug.print slayout(j)
    next j
Patrick MatthewsCommented:
Hello coperations07,

Please explain what you mean by "I haven't got "Split" to work".  That code should have rendered sLayout
as a zero-based array with the values from that line of text.


coperations07Author Commented:
Thanks guys!
Split was working. I just didn't know how to get the data from it.
I just added variables like this and it works perfectly.

            s1 = sLayout(0)
            s2 = sLayout(1)
            s3 = sLayout(2)
            s4 = sLayout(3)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.