[Year 12 SofDev] Working with CSV text files

Timmer-Arends timmer at melbpc.org.au
Fri Aug 26 19:02:31 EST 2011


Re: [Year 12 SofDev] Working with CSV text filesHello Shane

I'm curious to know why you've used
    Do While Openfile.Peek <> -1       'read from file until end of file

rather than
    Do While Not Openfile.EndOfStream     'read from file until end of file


Regards
Robert T-A

----- Original Message ----- 
  From: Andrew Shortell 
  To: Year 12 Software Development Teachers' Mailing List 
  Sent: Friday, August 26, 2011 10:26 AM
  Subject: Re: [Year 12 SofDev] Working with CSV text files


  If you read ahead (so prior to entry and at end of while loop) and test for null or "" then that finds eof. There are multiple ways.
  I do like Shane's method - more elegant
  Andrew
  -- 
  Andrew Shortell

  mailto:shortell at get2me.net 
  Heidelberg Teaching Unit
  Ph 9470 3403
  Fax  9470 3215



  On 26/08/11 10:17 AM, "Mark KELLY" <kel at mckinnonsc.vic.edu.au> wrote:


    Cool. I was wondering how to test for EOF using Streamreader. I ended up using a different file access system via file handles (as it was in the good ol' VB6 and even QB4.5 days).

    On 26 August 2011 09:52, Shane Dawson <shaned at sjc.vic.edu.au> wrote:

      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





  -- 



------------------------------------------------------------------------------


  _______________________________________________
  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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.edulists.com.au/pipermail/sofdev/attachments/20110826/1da846d3/attachment-0001.html 


More information about the sofdev mailing list