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

Visual Basic

 
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 
AnswerRe: IF ELSE or LOOP Pin
riced29-Apr-09 22:36
riced29-Apr-09 22:36 
Here's a version that fixes the bug in previous one.
Private Sub Parent_Child1(ByVal iFile As String, ByVal oFile As String)
   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))
         parentStack(generation) = name
         'Write out first record here if need to
         While sa.Peek() >= 0
            inputLine = sa.ReadLine()
            name = inputLine.Substring(0, pF(1))
            generation = GetGeneration(name)
            parentStack(generation) = name
            If (generation > 0) Then
               sw.WriteLine(parentStack(generation - 1) & name)
            Else
               'Do you need to do this for lines that have no parent?
               sw.WriteLine(parentStack(generation))
            End If
         End While
      End Using
   End Using
End Sub

Private Function GetGeneration(ByVal s As String) As Integer
   Dim g As Integer
   g = NbOfCar(s, " ")
   If (g > 1) Then
      g = (g - 1) / 2
   End If
   GetGeneration = g
End Function

It assumes that the first child generation has 3 spaces; the second has 5 spaces,; the third has 7 spaces and so on. If that's not the case then GetGeneration() might have to be modified.
You'll notice it is a bit different from my original effort. That's because I put my thinking head on and realised that the number of spaces tells you the generation and the parent must be the previous generation! Smile | :)

Regards
David R

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 
GeneralRe: IF ELSE or LOOP Pin
vijay24822-May-09 21:57
vijay24822-May-09 21:57 

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.