Author Topic: StreamReader  (Read 1514 times)

0 Members and 1 Guest are viewing this topic.

djee

  • Newt
  • Posts: 49
StreamReader
« on: July 02, 2015, 08:11:49 PM »
I'm a newby to VB.NET... I need to create a StreamReader SUB that would open a text file containing the following structure;
Code: [Select]
Projectname , TemplatePath , Plotstylepath
Projectname , TemplatePath , Plotstylepath
Projectname , TemplatePath , Plotstylepath
I need to populate a LISTBOX containing only the Projectname variable... I'm having some difficulty with this one...
Any suggestion would be greatly appreciated...


Jeff H

  • Needs a day job
  • Posts: 6150
Re: StreamReader
« Reply #1 on: July 02, 2015, 10:16:27 PM »
Open file with StreamReader


Code - Visual Basic: [Select]
  1. Imports System.IO
  2.  
  3. Module Module1
  4.  
  5.     Sub Main()
  6.         ReadCSV("C:\temp\New Text Document.txt")
  7.         Console.Read()
  8.  
  9.     End Sub
  10.     Public Sub ReadCSV(strFileName As String)
  11.  
  12.         Dim sr As New StreamReader(strFileName)
  13.  
  14.  
  15.         Dim strline As String = ""
  16.  
  17.         Dim vals As String() = Nothing
  18.  
  19.         While Not sr.EndOfStream
  20.  
  21.             strline = sr.ReadLine()
  22.  
  23.             vals = strline.Split(",")
  24.  
  25.             Console.WriteLine(vals(0))
  26.         End While
  27.  
  28.     End Sub
  29. End Module
  30.  

djee

  • Newt
  • Posts: 49
Re: StreamReader
« Reply #2 on: July 06, 2015, 12:48:08 PM »
Perfect! thanks a bunch!