How to transfer data from a text file into an array



Using VB .NET, this tutorial demonstrates how to use a StreamReader object to move the contents of a text file into your program. It then demonstrates how to add data from the textfile into an array.

7 Comments

  • this was helpful, but it was going me one tiny problem.  i had to add in code to close the streamreader as it was conflicting with other parts of something i was working on

  • This was very helpful! I have a question though, how do you get numeric values out of a file that you can add text to through the program. My file looks like this:

    1,Plain Burger Buns,60,30,30/10/14,2.00
    2,Chicken Breast,60,30,20/08/14,2.00
    3,Tomatoes,99,30,30/08/14,0.50
    4,Cheddar Cheese,50,20,30/08/14,4.00
    5,Chilli Powder,20,10,30/08/15,2.00
    6,Avocados,20,10,30/08/15,3.00
    7,Mayonaise,20,10,30/12/14,4.00
    8,Beef Mince,10,10,30/08/14,5.00
    9,Turkish Bread,5,10,08/08/14,3.00
    10,Butter,20,15,30/12/14,2.00
    11,Lettuce,20,20,08/08/14,1.00

    I would like to grab the second value of each line and multiply it with the last of each line. And ultimately add the answers of each at the end. I'm trying to make it work so that you can input another line in text file, or edit on of the existing ones. 

    Any help is appreciated, thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *