Results 1 to 5 of 5

Thread: [RESOLVED] help with csv files and arrays

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2011
    Posts
    8

    Resolved [RESOLVED] help with csv files and arrays

    Hi all, so im new to VB.net, What I need to do is open a csv file which contains 4 fields and many rows, then I want to do different operations determined on the value in the fields.

    for example :

    My CSV will be in the following format.

    ID,Name,Number,Status

    Heres what I have so far
    Code:
     Private Sub OpenFileDialog1_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles OpenFileDialog1.FileOk
    
            Dim strm As System.IO.Stream
            strm = OpenFileDialog1.OpenFile()
            TextBox1.Text = OpenFileDialog1.FileName.ToString()
            If Not (strm Is Nothing) Then
    
                Dim filestream As StreamReader
                filestream = File.OpenText(OpenFileDialog1.FileName.ToString())
                Dim readcontents As String
                Dim counter As Integer
                Dim Fails As Integer
                Dim Delivered As Integer
    
                Do Until filestream.EndOfStream
                    readcontents = filestream.ReadLine()
                    Dim textdelimiter As String
                    textdelimiter = ","
                    Dim splitout = Split(readcontents, textdelimiter)
    
                    counter = counter + 1
    
                    'Check the values of each field
    
                    
                Loop
                filestream.Close()
    
                strm.Close()
                MessageBox.Show("counter:" & counter & "Records in file")
                MessageBox.Show("Operation Complete")
            End If
    
        End Sub

    My issue is that whilst in the loop I want to extract the data from the array and assign it to a variable but I don't know how to do this without receiving an out of bound exception ( I can do this simple task in perl and php but as I am new to VB.net I haven't the slightest idea how.


    Could somebody point me in the right direction, I would appreciate it alot.

    EDIT: - I want to perform an IF statement on each field of the csv.. e.g :

    if status = 'good' then
    do something
    Else
    do something else
    Last edited by minimatrix; Mar 3rd, 2011 at 08:59 AM. Reason: Missed out some information ( Now appended )

Tags for this Thread

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