Hi,
Im teaching myself VB, specifically, how to create forms(im using VS Express 2013). I wanted to use the values from an xls file( already exported it as LMS.csv, a table with 4 rows X 3 columns) as constants for my form.

I've tried the codes below but its not working properly:

     Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser("C:\LMS.csv")
        MyReader.TextFieldType = FileIO.FieldType.Delimited
        MyReader.SetDelimiters(",")
        Dim currentRow As String()
        Static LMSarray(11) As Double
        While Not MyReader.EndOfData
            currentRow = MyReader.ReadFields()
            Dim currentField As Double
            For Each currentField In currentRow
                Dim I As Integer = 0
                LMSarray(I) = currentField
                I += 1
            Next
        End While
    End Using

I'm lost, Please Help...

P.S. Im not a seasoned programmer, i just want to learn something new....

Why are you declaring the variable "I" inside the loop. Every time the loop completes its round, a new variable "I" creates and initializes with the value 0. And all values are stored into the first element of the array "LMSarray".
Declare the variable "I" outside the loop.

Dim I As Integer = 0
For Each currentField In currentRow
        LMSarray(I) = Val(currentField)
        I += 1
Next

If you are using VS, you better post in the VB.NET forum.
Did you know you don't have to save your excel file first as a cvs file to import from it? Read here how.

@ddanbe, sorry I was confused...

thanks for the link, very useful.

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.