[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 205
  • Last Modified:

How to Parse a comma delimited txt file?

I'm a noob so I'm not sure how to put this exactly.
I'd like to parse a comma delimited text file into an (array?) and use the contents of the array to fill in a webform.

Ralph,Malph,123 st, etc....

I've already got the webform portion handled but I've been getting my data from labels I have on my form ie:

Dim FirstName As String
FirstName = lblFirstName.Text
.Document.Frames("Main").document.Forms(0)("app_first_name").Value = FirstName

But thats kinda cheating, I'd like to do it without using labels, just pull the data from memory.

How would I go about doing that?
2 Solutions
Mike TomlinsonMiddle School Assistant TeacherCommented:
Something like this?...

        Dim fileName As String = "C:\someFile.txt"
        If Not File.Exists(fileName) Then
            MsgBox(fileName, MsgBoxStyle.Critical, "File Not Found")
            Exit Sub
        End If

        Dim sr As StreamReader = New StreamReader(fileName)
        Dim inputLine As String = sr.ReadLine
        If Not (inputLine Is Nothing) Then
            Dim values() As String = Split(inputLine, ",")
            .Document.Frames("Main").document.Forms(0)("app_first_name").Value = values(0)
            .Document.Frames("Main").document.Forms(0)("app_last_name").Value = values(1)
            ' etc...
        End If
Matrix1000Author Commented:
THANKS!  but I get an error underlining "File"  in  "If Not File.Exists(fileName) Then"

Says its not declared.
What do I need do do to make it work?
Add the following to your file OUTSIDE the class declaration:

Imports System.IO

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now