Click here to Skip to main content
16,005,697 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionVB code that will search network folders Pin
akakoom29-Apr-09 8:24
akakoom29-Apr-09 8:24 
AnswerRe: VB code that will search network folders Pin
Henry Minute29-Apr-09 8:41
Henry Minute29-Apr-09 8:41 
Question[Message Deleted] Pin
ymilan29-Apr-09 5:04
ymilan29-Apr-09 5:04 
AnswerRe: Need Assistance on VB.NET code for DoDragDrop events Pin
Henry Minute29-Apr-09 5:47
Henry Minute29-Apr-09 5:47 
QuestionInstall certificate... Pin
p_196029-Apr-09 0:44
p_196029-Apr-09 0:44 
AnswerRe: Install certificate... Pin
Dave Kreskowiak29-Apr-09 7:58
mveDave Kreskowiak29-Apr-09 7:58 
QuestionIF ELSE or LOOP Pin
vijay248229-Apr-09 0:10
vijay248229-Apr-09 0:10 
AnswerRe: IF ELSE or LOOP Pin
riced29-Apr-09 8:24
riced29-Apr-09 8:24 
I think it's a bit more complicated than deciding whether or not to use IF..ELSE or LOOP. You have more than two generations in the data i.e. ASMs contain ASMs that contain PRTs (parent-child-grandchild).

Here's some code that I've been playing with.
There is at least one bug in it but the general idea is sound (I think Smile | :) ).
Imports System.IO

Module Module1

   Sub Main()
      Call Parent_Child1("C:\PlayPen\Names.txt", "C:\PlayPen\Names_OUT.txt")
   End Sub

   Private Sub Parent_Child1(ByVal iFile As String, ByVal oFile As String)
      Dim previousSpaces As Integer
      Dim currentSpaces As Integer
      Dim pF(10) As Integer

      Dim parentStack(5) As String
      Dim generation As Integer = 0

      Dim name As String
      Dim inputLine As String

      Using sw As StreamWriter = New StreamWriter(oFile)
         Using sa As StreamReader = New StreamReader(iFile)
            inputLine = sa.ReadLine()
            Call FillPF(pF, inputLine)
            Call WriteHeader(sa, sw, inputLine, pF)

            'Assume first data record is a parent
            inputLine = sa.ReadLine()
            name = inputLine.Substring(0, pF(1))
            previousSpaces = NbOfCar(name, " ")
            parentStack(generation) = name
            'generation += 1
            While sa.Peek() >= 0
               inputLine = sa.ReadLine()
               name = inputLine.Substring(0, pF(1))
               currentSpaces = NbOfCar(name, " ")

               If currentSpaces = previousSpaces Then
                  sw.WriteLine(parentStack(generation - 1) & name)
               Else
                  If currentSpaces > previousSpaces Then
                     sw.WriteLine(parentStack(generation) & name)
                     previousSpaces = currentSpaces
                     generation += 1
                     parentStack(generation) = name
                  Else
                     ' currentSpaces < previousSpaces
                     generation -= 1
                     previousSpaces = currentSpaces
                     sw.WriteLine(parentStack(generation) & name)
                  End If
               End If
            End While
         End Using
      End Using
   End Sub

   Private Function NbOfCar(ByVal s As String, ByVal c As String) As Integer
      Dim i As Integer = 0
      While (i < s.Length) And (s.Substring(i, 1) = c)
         i += 1
      End While
      NbOfCar = i
   End Function

   Private Sub FillPF(ByVal p() As Integer, ByVal t As String)
      p(0) = t.IndexOf("Nom du Modele")
      p(1) = t.IndexOf("AEC_STANDARD_DESCRIPTION_FRENCH")
      p(2) = t.IndexOf("AEC_FREE_DESCRIPTION_FRENCH")
      p(3) = t.IndexOf("AWW_STANDARD_DESCRIPTION")
      p(4) = t.IndexOf("AEC_FREE_DESCRIPTION_ENGLISH")
      p(5) = t.IndexOf("AEC_ECN")
      p(6) = t.IndexOf("DNF")
      p(7) = t.IndexOf("BALOON")
   End Sub

   Private Sub WriteHeader(ByVal sr As StreamReader, ByVal sw As StreamWriter, ByVal t As String, ByVal p() As Integer)
      Dim s As String = ""
      s = t.Substring(p(1), p(2) - p(1))           ' desF
      s = s & t.Substring(p(2), p(3) - p(2))       ' desAF
      s = s & t.Substring(p(3), p(4) - p(3))       ' desA
      s = s & t.Substring(p(4), p(5) - p(4))       ' desAA
      s = s & t.Substring(p(5), p(6) - p(5))       ' ecn
      s = s & t.Substring(p(6), p(7) - p(6))       ' dnf
      s = s & t.Substring(p(7), t.Length - p(7))   ' baloon

      sw.WriteLine("PARENT" & Space(10) & "CHILD" & Space(10) & s)
      sw.WriteLine(sr.ReadLine()) 'The line of underscores

   End Sub

End Module


It fails on the last record in this test file (and there may be other bugs.)

        Nom du Modele         AEC_STANDARD_DESCRIPTION_FRENCH  AEC_FREE_DESCRIPTION_FRENCH           AWW_STANDARD_DESCRIPTION            AEC_FREE_DESCRIPTION_ENGLISH      AEC_ECN    DNF   BALOON
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
01530501.ASM                              
   4281484M1.PRT     
   3009508X1.PRT
   3009508X1.PRT         
   3009506X1.PRT         
   3009506X1.PRT         
   3583428M1.PRT         
   3583428M1.PRT         
   3583428M1.PRT         
   4282884M92.ASM         
     4282885M2.PRT         
     4281478M1.PRT         
     4281479M1.PRT         
   390734X1.PRT         
   390734X1.PRT         
   390734X1.PRT         
   3009495X1.PRT         
   3009495X1.PRT         
   3009495X1.PRT         
   3385604M2.PRT         
   3385604M2.PRT         
   391039X1.PRT         
   4287200M3.ASM         
   391176X1.PRT         
   4281283M93.ASM         
     4284820M94.ASM         
       4282976M2.ASM         
       4282971M2.ASM         
       4285693M1.PRT         
       4284511M1.PRT         
       4284511M1.PRT         
       4284511M1.PRT         
       4284511M1.PRT         
       4284511M1.PRT         
       4284511M1.PRT         
       4284511M1.PRT         
       4284511M1.PRT         
   4281283XXX.ASM         

You'll notice that I've dropped all the fields you were not outputting but they should be ewasy to put back in.
Hope this helps Smile | :)

Regards
David R

AnswerRe: IF ELSE or LOOP Pin
riced29-Apr-09 22:36
riced29-Apr-09 22:36 
GeneralMessage Closed Pin
29-Apr-09 23:38
vijay248229-Apr-09 23:38 
GeneralRe: IF ELSE or LOOP Pin
riced30-Apr-09 0:53
riced30-Apr-09 0:53 
GeneralRe: IF ELSE or LOOP Pin
vijay248230-Apr-09 1:32
vijay248230-Apr-09 1:32 
GeneralRe: IF ELSE or LOOP Pin
riced30-Apr-09 1:45
riced30-Apr-09 1:45 
GeneralRe: IF ELSE or LOOP Pin
riced30-Apr-09 1:34
riced30-Apr-09 1:34 
GeneralRe: IF ELSE or LOOP Pin
vijay248230-Apr-09 3:30
vijay248230-Apr-09 3:30 
GeneralRe: IF ELSE or LOOP Pin
riced30-Apr-09 4:10
riced30-Apr-09 4:10 
GeneralMessage Closed Pin
30-Apr-09 4:27
vijay248230-Apr-09 4:27 
GeneralRe: IF ELSE or LOOP Pin
riced30-Apr-09 7:34
riced30-Apr-09 7:34 
GeneralMessage Closed Pin
30-Apr-09 11:27
vijay248230-Apr-09 11:27 
GeneralRe: IF ELSE or LOOP Pin
riced30-Apr-09 12:58
riced30-Apr-09 12:58 
GeneralRe: IF ELSE or LOOP Pin
vijay24821-May-09 1:06
vijay24821-May-09 1:06 
GeneralRe: IF ELSE or LOOP Pin
riced1-May-09 1:23
riced1-May-09 1:23 
GeneralRe: IF ELSE or LOOP Pin
vijay24821-May-09 7:27
vijay24821-May-09 7:27 
GeneralRe: IF ELSE or LOOP Pin
riced2-May-09 3:32
riced2-May-09 3:32 
GeneralRe: IF ELSE or LOOP Pin
riced2-May-09 11:50
riced2-May-09 11:50 

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.