[Year 12 SofDev] Working with CSV text files

Travis Parker Travis.Parker at beaconhills.vic.edu.au
Fri Aug 26 10:14:39 EST 2011


Awesome - Thanks. It works great!

Cheers

Trav



-----Original Message-----
From: sofdev-bounces at edulists.com.au
[mailto:sofdev-bounces at edulists.com.au] On Behalf Of Shane Dawson
Sent: Friday, 26 August 2011 9:52 AM
To: Year 12 Software Development Teachers' Mailing List
Subject: Re: [Year 12 SofDev] Working with CSV text files

If you are using the str.split(",") function in VB.Net and have an array
that stores how many columns of data you have eg. Splitstring(50,4) (50
rows, 4 coulmns) you can then read in each csv line and store it as
separate elements in the array.

You can then use this to populate the relevant text boxes.

cmbDish.Items.Clear() 'clear the combobox containing dishes
        'cmbDish.Items.Add("") 'add a first line that is empty in
combobox
        Dim C As Integer = 0 'count for dishes
        Dim Openfile As StreamReader = File.OpenText(TextFile) 'open
text file for the selected section of the menu
        Do While Openfile.Peek <> -1 'read from file until end of file
            strDish = Openfile.ReadLine() 'read a line from the text
file and store into a string
            strsplit = strDish.Split(",") 'split the stored line into
dish and cost
            cmbDish.Items.Add(strsplit(0)) 'add the dish name to the the
dish combobox
            strDishCost(C) = Val(strsplit(1)) 'store the dish cost into
an array
            C = C + 1 'add one to the dish count
        Loop
        Openfile.Close()

-----Original Message-----
From: sofdev-bounces at edulists.com.au
[mailto:sofdev-bounces at edulists.com.au] On Behalf Of Travis Parker
Sent: Friday, 26 August 2011 9:41 AM
To: Year 12 Software Development Teachers' Mailing List
Subject: [Year 12 SofDev] Working with CSV text files

Dear All,

I am halfway through a program with my Year 12 SD class that writes to a
text file (Comma separated) and allows them to add and delete records
from it (Using similar techniques to Adrian Janson's "Hi-scores table"
in his great "VB.net for education" book). I have included many
validation techniques, including range checking for a person's age (They
must be a uni student so this is a bit controversial, particularly about
mature age students!), existence checking for names, and data type
checking for numbers (They must enter numbers only for phone numbers -
Not necessarily correct in real life but just using it as an example). 

I have also created a funky little program that validates email
addresses (Attached as a zip file). It makes sure that it follows a
logical structure, including containing the "@" symbol and a ".com" or
equivalent at the end. Students incorporate this code into their
validation of user entries as well.

One thing that I am doing at the moment though is looking at editing
individual records. I have tried numerous methods using past code for
CSV files, and ideally I would have the user select a record (Displayed
in a listbox) and click btnEdit, then the program would read each field
back into the original textbox that it was entered (i.e. Their name is
read back into the text property of txtName). So far all I can manage is
having it read the entire text file back into a multiline textbox and
allow the user to edit it there, then save or discard the changes. This
works, but is more prone to human error and I would like a better way of
doing things.

If anyone can help or is facing a similar issue it would be great if you
could give me some idea of what to do here.

Many thanks

Trav



_______________________________________________
http://www.edulists.com.au - FAQ, Subscribe, Unsubscribe IT Software
Development Mailing List kindly supported by http://www.vcaa.vic.edu.au
- Victorian Curriculum and Assessment Authority and
http://www.vcaa.vic.edu.au/vce/studies/infotech/softwaredevel3-4.html
http://www.vitta.org.au  - VITTA Victorian Information Technology
Teachers Association Inc



More information about the sofdev mailing list