Hi Marcos:
Disagreement is fine but I believe you're missing some of the subtleties.
Notice the title contains "new student" so while fast and good might be
perfect I'll guess "I downloaded FileHelpers" might get him a "C" for effort
it probably won't yield an "A". I can pretty much guarantee he won't get a
passing grade on the final unless he has an Internet connection handy.
The "goal" of the assignment is (I'm certain) not to teach someone how to
read CSV files into arrays. If that is the goal he can send me $25 and I'll
write the code for him. The goal is to learn how to declare variables,
write DO loops, use the StreamReader, etc.
He's learning the basics so he should learn to parse a file. Perhaps then
he could write his own FileHelpers one day or if nothing else be qualified
for a job as a software developer.
Tom
"MarcosMeli" <ma********@gmail.comwrote in message
news:11*********************@m73g2000cwd.googlegro ups.com...
Hi there
Tom let me to disagree with some part of your point of view, I really
belive that is very important to use some time to research and create
your own libraries to learn about how the things work, in fact while
developing the FileHelpers I learn a lot of things and I´m very happy
with it and them worth all the effort.
But in the other hand some times the users only need a fast and good
way to do things and for this case the FileHelpers are perfect.
I must to said that the CSV format has a lot of exceptions and things
that are hard to implement at least for me, here you can read a post of
Leon Bambrick about the CSV parsing and all the gotchas around it.
http://secretgeek.net/csv_trouble.asp
Cheers
Marcos
http://www.filehelpers.com
On 13 nov, 15:46, "Tom Leylan" <g...@iamtiredofspam.comwrote:
Hi... if you are a student I'm going to suggest (unlike the other
response)
that you don't immediately go download some library somewhere. Anybody
can
cut and paste that doesn't make one a software developer. My advice is to
spend a little more time (it's painful but necessary) to solve the
problem.
And here is the advice I give to every student (customized for your
particular example), "if you need to write a program to read a CSV file
don't write a program to read a CSV file." Break it all down into parts
that work and then put the parts together.
So when you take out the Split() and AL.Add() stuff could you reliably
open
the CSV file and read each line? If it can't do that then the rest
doesn't
matter and all the extra code is getting in your way. When it can do that
proceed.
What is Dim B?
In answer to your second question, "No" :-) You could add numbers
together
if they were numbers but you have them as text. And they wouldn't be
accessed through "B" which won't exist after you exit the Do loop. You're
putting all the data into AL remember.
Again I'd suggest you create the StreamReader (an added feature would be
to
check if the file actually exists first) and simply read through the
thing.
Report a count of the number of lines or output the text as you read it to
confirm that you've accomplished Step 1. Then go on to Step 2.
"RallyDSM" <ebennet...@gmail.comwrote in
messagenews:11*********************@m73g2000cwd.go oglegroups.com...
Hello,
I'm currently trying to read a .CSV file and get all the data into an
array so I can work with it in the program.
Here is what I currently have.
Private Sub IntializeData()
Dim AL As New ArrayList
Dim sr As IO.StreamReader
'first, let's open the file
sr = IO.File.OpenText("csvstocks.txt")
Dim Entry As String
Do
Entry = sr.ReadLine
If Not Entry Is Nothing Then
Dim B
Dim data() As String = Split(Entry, ",")
B.stock = data(0)
B.numShares = data(1)
B.datePurchased = data(2)
B.purchasePrice = data(3)
B.currentPrice = data(4)
AL.Add(B)
End If
Loop Until Entry = Nothing
End Sub
I got most of this code from another post on the board, what it does is
read the first line of the .CSV into an array, which is perfect, but
then it crashes.
How do I get all lines into the array? And then when I do get that
part, can I add stuff together by doing.
B.currentPrice(1) + B.currentPrice(2)
Thanks in advance.- Ocultar texto de la cita -- Mostrar texto de la
cita -