I have a CSV textfile that contains "Student" and "Grades". I need to find the average of the grades but my array has a string data type and I keep getting an error message b/c I need to someread read the grades without reading the Students. Any Help?

You should post some code to show what you've tried.

That being said, can we assume you're using a "Line Input" type of construct to read each line of your file into a string? If so, you might want to try using "SPLIT" to break it into pieces. Just keep in mind that the "split" statement returns a Variant array, so you have to use "myVariant(1)", "myVariant(2)", etc. to reference the individual parts of the broken-up input line. Then you can translate your grades (A, B, C, etc.) to numbers, assuming they're letter-grades.

Another possibility is to use a straight "Input #1" type of construct. That way, you can assign each part of your input into a separate variable. Then you can do a translation if needed, and store or accumulate the values as a numeric datatype.

You also need to keep count of how many lines of input you have so you can perform your averaging.

Hope this helps! Post your solution!

Apparently, your text file has input something like the following:

George, 99
Lisa, 82
WaltP, 100


Each line in the text file can be assigned to a variable. And then you can declare a variable to keep track of the information. One popular method is to declare your own type. Custom types are great for related information.

Private Type Student
    strName As String
    intGrade As Integer
End Type

' ...............

Dim MyStudents(100) as Student

Since you are using a comma separated value (CSV) text file as a source of data, use the Instr function to determine where the comma is and then save the data:

Dim strInput as String, intPlace as Integer 
     
intPlace = Instr(1, strInput, ",", vbTextCompare)

That will tell you the place of the comma in the string input value; and then you can use the Right or Left string operations to separate the values and store them into the Student type. If you need help on inputting data from a file, post some of you what you have attempted and we'll see if we can help you out.

But that along with BitBlt's suggestions should get you started.

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.