[Year 12 SofDev] Reading and Writing text data files in VB2010

Travis Parker Travis.Parker at beaconhills.vic.edu.au
Thu May 12 09:48:59 EST 2011


Wow Damien thanks for the speedy response - That's exactly what I need! 

 

I'll try to get my application working and do a bit more practice
working through the VITTA one as well (Jackson's pond emporium - Mine is
based around that structure) then see where we end up. I was going to
use a 2D array to store all of what you have as Values so I could read
them all into the same place and sort by the priority (Last value in
each line - 1, 2 or 3) but I can see 2D arrays are part of U4O1  not
U3O2 so will get around that and send my (Hopefully fully functional)
solution through!

 

Thanks again

 

Trav

 

 

 

From: sofdev-bounces at edulists.com.au
[mailto:sofdev-bounces at edulists.com.au] On Behalf Of ATKINSON-BUCK,
Damien
Sent: Thursday, 12 May 2011 9:38 AM
To: Year 12 Software Development Teachers' Mailing List
Subject: Re: [Year 12 SofDev] Reading and Writing text data files in
VB2010

 

Mark, thanks for another great tutorial. Building on Marks work might be
what you need Trav

 

One of the more common uses of reading a text file is to read various
values of a CSV (comma separated values) file, where individual items
(think fields of a flat file database) are read into an array for future
processing. Visual Basic has a very nice easy way to do this using the
Split function. Imagine that you have the above text file with the
following data copied from this week's Aria charts;

 

1,WE RUN THE NIGHT,DJ Havana Brown,ISL/UMA

2,FROM THE MUSIC,The Potbelleez,VIC/UMA

3,WHAT HAPPENED TO USJessica Mauboy Feat. Jay Sean,SME

4,DANCE WITH ME,Justice Crew Feat. Flo Rida,SME

5,FRIDAY TO SUNDAY,Justice Crew,SME

6,MAYBE,Sick Puppies,VIR/EMI

 

        Dim TextFile As New System.IO.StreamReader("u:\albums.txt ")

        Dim strAlbumName As String

        strAlbumName = TextFile.ReadLine()

        Do Until strAlbumName Is Nothing

            'lstAlbums.Items.Add(strAlbumName)

            Dim Values() As String = Split(strAlbumName, ",")

            strAlbumName = TextFile.ReadLine()

       ' Values(0) now contains first column value,

       ' Values(1) contains second column, etc.

        Loop

        TextFile.Close()

        TextFile.Dispose()

 

Cheers

Damien Atkinson-Buck
Member of Academic Staff (Secondary)

________________________________

  <http://myivanhoe.net/> 

 

PO BOX 91 The Ridgeway, Ivanhoe, Victoria 3079 Australia
Telephone +61 3 9490 3848 Facsimile +61 3 9490 3490
mailto:damien.atkinson-buck at ivanhoe.com.au
<mailto:damien.atkinson-buck at ivanhoe.com.au> 
http://myivanhoe.net <http://myivanhoe.net/> 

 

 

From: Travis Parker [mailto:Travis.Parker at beaconhills.vic.edu.au] 
Sent: Thursday, 12 May 2011 9:26 AM
To: Year 12 Software Development Teachers' Mailing List
Subject: Re: [Year 12 SofDev] Reading and Writing text data files in
VB2010

 

Thanks for that Mark. I have been using something similar with my
students, particularly as the SAC I have written includes reading from a
text file (A prototype helpdesk, including type of job, computer,
priority, etc) and creating a new text file with jobs for the techies in
a prioritised order.

 

One thing I was wondering though, does anyone have anything good on
reading comma separated text files? All the programs I have gotten my
students to create read them a line at a time, but I would ideally like
to see something like this line - tim.cox, hardware, 12, ps40, 2 read
into arrays. So I would have a "Name", "Issue", "Computer_Number",
"Room_Number", "Priority" or something like that. I'm fine with the
arrays, but how would I read it in word at a time (i.e. Between commas"
rather than line at a time?

 

With many thanks for a first year SD newbie......

 

Trav

 

 

 

 

 

From: sofdev-bounces at edulists.com.au
[mailto:sofdev-bounces at edulists.com.au] On Behalf Of Mark KELLY
Sent: Wednesday, 11 May 2011 12:45 PM
To: Year 12 Software Development Teachers' Mailing List
Subject: [Year 12 SofDev] Reading and Writing text data files in VB2010

 

Hi, you paragons of pedagogy.  I've been putting off teaching my kids
how to read and write text data files in VB but having investigated
today, it's not really more difficult than the days of VB6 with OPEN
"file" FOR INPUT AS 1 ... INPUT #1, data.

I've attached an adapted tutorial on reading and writing text files with
a task involving reading and writing a preferences file (with solution).

Once your kids can do data files, it greatly opens the scope for
populating and playing with really large arrays and makes loops
meaningful.  

I remember how excited I was when I first discovered text files decades
ago - it was like finding mum's car keys.  My programming world
blossomed from that point.

-- 
Mark Kelly
Manager of ICT, Reporting, IT Learning Area
McKinnon Secondary College
McKinnon Rd McKinnon 3204, Victoria, Australia
Direct line / Voicemail: +613 8520 9085, Fax +613 9578 9253
kel at mckinnonsc.vic.edu.au
VCE IT Lecture Notes: http://vceit.com
Moderator: IT Applications Edulist

Want a good time? Call 0112358. Ask for Mr Fibonacci.





Privacy, Virus and Copyright Warning

The information contained in this electronic message (e-mail), and any
files transmitted with it:

* is intended for the named recipients only. If you have received this
in error, please advise the sender and delete it and any copies
immediately;
* Any personal information in this email must be used in accordance with
the Privacy Act 1988 and this always applies even if it has been sent to
you in error.
* represents the views of the sender and does not necessarily represent
the views or formal advice of Ivanhoe Grammar School;
* may be subject to Copyright, so no further use should be made of it
without the author's permission.

The School does not represent or warrant that the email or any files
attached do not contain errors or are free from computer viruses or
other defects nor does it accept responsibility for any loss or damage
resulting directly or indirectly from the use of the email or any
attached files. 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.edulists.com.au/pipermail/sofdev/attachments/20110512/dd2adcc8/attachment-0001.html 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: image/jpeg
Size: 9302 bytes
Desc: image001.jpg
Url : http://www.edulists.com.au/pipermail/sofdev/attachments/20110512/dd2adcc8/attachment-0001.jpe 


More information about the sofdev mailing list