Read comma delimited text flie into vba variables

Posted on 2009-02-16
Medium Priority
Last Modified: 2013-11-27
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

Question by:coperations07
LVL 120

Accepted Solution

Rey Obrero (Capricorn1) earned 600 total points
ID: 23651046

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
LVL 93

Assisted Solution

by:Patrick Matthews
Patrick Matthews earned 400 total points
ID: 23651051
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.



Author Comment

ID: 23651356
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)

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
The viewer will learn how to  create a slide that will launch other presentations in Microsoft PowerPoint. In the finished slide, each item launches a new PowerPoint presentation and when each is finished it automatically comes back to this slide: …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question