Click here to Skip to main content
15,909,741 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionHelp in reading File Pin
yaya_star24-Nov-08 21:28
yaya_star24-Nov-08 21:28 
AnswerRe: Help in reading File Pin
indian14324-Nov-08 21:43
indian14324-Nov-08 21:43 
GeneralRe: Help in reading File Pin
yaya_star24-Nov-08 21:52
yaya_star24-Nov-08 21:52 
GeneralRe: Help in reading File Pin
Ashfield24-Nov-08 22:10
Ashfield24-Nov-08 22:10 
GeneralRe: Help in reading File Pin
yaya_star24-Nov-08 22:15
yaya_star24-Nov-08 22:15 
GeneralRe: Help in reading File Pin
Ashfield25-Nov-08 1:13
Ashfield25-Nov-08 1:13 
AnswerRe: Help in reading File Pin
Christian Graus24-Nov-08 23:08
protectorChristian Graus24-Nov-08 23:08 
AnswerRe: Help in reading File Pin
riced26-Nov-08 1:55
riced26-Nov-08 1:55 
You could try something like this.
The example data could be interpreted as
(a) a set of files where each file contains one 11 record,
or (b) one file that has multiple 11 records with each one followed by 12, 13 and 14 records.

I assume the latter.

Imports System
Imports System.Text
Imports System.IO

module CSVReader
   public Sub Main()
      Dim theFile As String = "C:\PlayPen\TheData.txt"
      Dim rdr As StreamReader = new StreamReader(theFile)
      Using (rdr)
         Dim theKey As String = ""
         Dim input As String
         Dim recType As String
         
         while (rdr.Peek >= 0)
            input = rdr.ReadLine()       'Should check that not a blank line
            Dim recArray As String()     'if there is one then following fails
            recArray = input.Split(",")
            recType = recArray(0)
            Select Case(recType)
               case "11":
                  theKey = recArray(1)   'Need to change this to get type 11 key
                  Process11(input)
               case "12":
                  Process12(theKey, input)
               case "13":
                  Process13(theKey, input)
               case "14":
                  Process14(theKey, input)
               case else
                  Console.WriteLine("Oops: {0}", input)
            End Select
         End While
      End Using
   End Sub

   private Sub Process11(rec As String)
      Console.WriteLine("Proc11 {0}",rec)
   End Sub

   private Sub Process12(key11 As String, rec As String)
      Console.WriteLine("Proc12 key = {0}: {1}", key11, rec)
   End Sub

   private Sub Process13(key11 As String, rec As String)
      Console.WriteLine("Proc13 key = {0}: {1}", key11, rec)
   End Sub

   private Sub Process14(key11 As String, rec As String)
      Console.WriteLine("Proc14 key = {0}: {1}", key11, rec)
   End Sub
End Module


The text file I used to test this is as follows:
11,one,xyz
13,abc_one,xyz
12,aaa_one,xyz
14,bad_one,xyz
13,abc_one,xyz
12,aaa_one,xyz
11,two,xyz
13,abc_two,xyz
14,bad_two,xyz
13,abc_two,xyz
14,bad_two,xyz
14,bad_two,xyz
13,abc_two,xyz
13,abc_two,xyz
14,bad_two,xyz
11,three,xyz
12,aaa_three,xyz
13,abc_three,xyz
11,four,xyz
14,bad_four,xyz
12,aaa_four,xyz
13,abc_four,xyz
11,five,xyz
12,aaa_five,xyz
12,aaa_five,xyz
14,bad_five,xyz
14,bad_five,xyz
14,bad_five,xyz
14,bad_five,xyz
13,abc_five,xyz
13,abc_five,xyz
11,six,xyz
12,aaa_six,xyz

Obviously your data has more fields but the general technique should work.
GeneralRe: Help in reading File Pin
yaya_star1-Dec-08 18:54
yaya_star1-Dec-08 18:54 
GeneralRe: Help in reading File Pin
riced3-Dec-08 13:13
riced3-Dec-08 13:13 
QuestionVisual Basic IDE [modified] Pin
indian14324-Nov-08 20:24
indian14324-Nov-08 20:24 
AnswerRe: Visual Basic IDE Pin
Christian Graus24-Nov-08 20:35
protectorChristian Graus24-Nov-08 20:35 
GeneralRe: Visual Basic IDE Pin
indian14324-Nov-08 21:07
indian14324-Nov-08 21:07 
GeneralRe: Visual Basic IDE Pin
Christian Graus24-Nov-08 21:23
protectorChristian Graus24-Nov-08 21:23 
GeneralRe: Visual Basic IDE Pin
indian14324-Nov-08 21:33
indian14324-Nov-08 21:33 
GeneralRe: Visual Basic IDE Pin
Paul Conrad25-Nov-08 18:33
professionalPaul Conrad25-Nov-08 18:33 
AnswerRe: Visual Basic IDE Pin
N a v a n e e t h24-Nov-08 21:24
N a v a n e e t h24-Nov-08 21:24 
GeneralRe: Visual Basic IDE Pin
indian14324-Nov-08 21:30
indian14324-Nov-08 21:30 
GeneralRe: Visual Basic IDE Pin
N a v a n e e t h24-Nov-08 21:32
N a v a n e e t h24-Nov-08 21:32 
AnswerRe: Visual Basic IDE Pin
Jon_Boy25-Nov-08 1:23
Jon_Boy25-Nov-08 1:23 
GeneralRe: Visual Basic IDE Pin
indian14325-Nov-08 2:02
indian14325-Nov-08 2:02 
Questionoracle connection in background worker Pin
captainmogo24-Nov-08 6:36
captainmogo24-Nov-08 6:36 
QuestionHow to Solve Dead Lock problem in Sql Server 2005 Question Pin
pdnet24-Nov-08 1:36
pdnet24-Nov-08 1:36 
AnswerRe: How to Solve Dead Lock problem in Sql Server 2005 Question Pin
Dave Kreskowiak24-Nov-08 2:05
mveDave Kreskowiak24-Nov-08 2:05 
QuestionI am not able to open the report for my VB6.0 application using Crystal Reports 9 in the client machine Pin
manoharbalu23-Nov-08 23:17
manoharbalu23-Nov-08 23:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.