Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LOOP trought cildren nodes 1

Status
Not open for further replies.

sal21

Programmer
Apr 26, 2004
422
IT
Code:
Private Sub Command3_Click()

    Dim myChild As Node
    Dim myNode As Node
    Dim myFile As String
    Dim K As Integer, X As Integer
    Dim NDX As Node

    If Dir("C:\TABULATI\TREEVIEW_" & ANNO & ".csv") <> "" Then
        Kill "C:\TABULATI\TREEVIEW_" & ANNO & ".csv"
    End If

    myFile = "C:\TABULATI\TREEVIEW_" & ANNO & ".csv"
    Close #1
    Open myFile For Output As #1

    For Each myNode In TreeView1.Nodes

        If myNode.Children > 0 And Mid(myNode.Text, 3, 1) = "-" Then
        
            Print #1, myNode.Text

        End If

    Next

    Close #1

    Me.Text1.SetFocus

End Sub

Now how to loop each day in month?

attached my treeview
 
 https://files.engineering.com/getfile.aspx?folder=b6ccfb5e-36da-49e6-b01a-2024535e1ede&file=Immagine.jpg
Assuming I've understood your question correctly, this minor change of youre C ommand3 code should illustrate one solution:

Code:
Private Sub Command3_Click()

    Dim myChild As Node
    Dim myNode As Node
    Dim myFile As String
    Dim K As Integer, X As Integer
    Dim NDX As Node

    If Dir("C:\TABULATI\TREEVIEW_" & ANNO & ".csv") <> "" Then
        Kill "C:\TABULATI\TREEVIEW_" & ANNO & ".csv"
    End If

    myFile = "C:\TABULATI\TREEVIEW_" & ANNO & ".csv"
    Close #1
    Open myFile For Output As #1

    For Each myNode In TreeView1.Nodes

        If myNode.Children > 0 And Mid(myNode.Text, 3, 1) = "-" Then
        
            Print #1, myNode.Text
            
 [b][COLOR=red]           Set myNode = myNode.Child
            Do Until myNode Is Nothing
                Debug.Print myNode
                Set myNode = myNode.Next
            Loop[/color][/b]

        End If

    Next

    Close #1

    Me.Text1.SetFocus

End Sub
 
Strongm, TKS!!!!

You read in my mind!

Work perfect!
 
OPS....

Why the last line in .csv have a blank row/line?

I need to print in csv also until the row 377, 378 is a blank row!

my last code:

Code:
Private Sub Command3_Click()

    Dim myChild As Node
    Dim myNode As Node
    Dim myFile As String
    Dim K As Integer, X As Integer
    Dim NDX As Node

    If Dir("C:\TABULATI\TREEVIEW_" & ANNO & ".csv") <> "" Then
        Kill "C:\TABULATI\TREEVIEW_" & ANNO & ".csv"
    End If

    myFile = "C:\TABULATI\TREEVIEW_" & ANNO & ".csv"
    Close #1
    Open myFile For Output As #1

    For Each myNode In TreeView1.Nodes

        If myNode.Children > 0 And Mid(myNode.Text, 3, 1) = "-" Then
        
            Print #1, myNode.Text
            
            Set myNode = myNode.Child
            Do Until myNode Is Nothing
                 Print #1, Tab, myNode
                Set myNode = myNode.Next
            Loop

        End If

    Next

    Close #1

    Me.Text1.SetFocus

End Sub
 
 https://files.engineering.com/getfile.aspx?folder=0a83e7aa-3573-4fdb-8d59-edc8f5abbfd9&file=TREEVIEW_2022.zip
>Why the last line in .csv have a blank row/line?

We've explained this to you before: thread222-1810582

And here's the very minor change to your code to get the result you seem to want.

Code:
Private Sub Command3_Click()

    Dim myChild As Node
    Dim myNode As Node
    Dim myFile As String
    Dim K As Integer, X As Integer
    Dim NDX As Node

    If Dir("C:\TABULATI\TREEVIEW_" & ANNO & ".csv") <> "" Then
        Kill "C:\TABULATI\TREEVIEW_" & ANNO & ".csv"
    End If

    myFile = "C:\TABULATI\TREEVIEW_" & ANNO & ".csv"
    Close #1
    Open myFile For Output As #1

    For Each myNode In TreeView1.Nodes

        If myNode.Children > 0 And Mid(myNode.Text, 3, 1) = "-" Then
        
            Print #1, myNode.Text
            
            Set myNode = myNode.Child
            Do Until myNode[COLOR=red].Next[/color] Is Nothing
                 Print #1, Tab, myNode
                Set myNode = myNode.Next
            Loop
            [COLOR=red]Print #1, Tab, myNode;[/color]
        End If

    Next

    Close #1

    Me.Text1.SetFocus

End Sub
 
Might I suggest that you put in a request to Site management to get your role changed from Programmer to something more appropriate, as it continues to seem as if you don't actually make any programming effort of your own.

Code:
Private Sub Command3_Click()

    Dim myChild As Node
    Dim myNode As Node
    Dim myFile As String
    Dim K As Integer, X As Integer
    Dim NDX As Node
    [COLOR=red]Dim firstmonth As Boolean[/color]

    If Dir("C:\TABULATI\TREEVIEW_" & ANNO & ".csv") <> "" Then
        Kill "C:\TABULATI\TREEVIEW_" & ANNO & ".csv"
    End If

    myFile = "C:\TABULATI\TREEVIEW_" & ANNO & ".csv"
    Close #1
    Open myFile For Output As #1

[COLOR=red]    firstmonth = True[/color]
    For Each myNode In TreeView1.Nodes

        If myNode.Children > 0 And Mid(myNode.Text, 3, 1) = "-" Then
            
            [COLOR=red]If Not firstmonth Then
                Print #1
            Else
                firstmonth = False
            End If[/color]
            Print #1, myNode.Text
            
            Set myNode = myNode.Child
            Do Until myNode.Next Is Nothing
                 Print #1, Tab, myNode
                Set myNode = myNode.Next
            Loop
            Print #1, Tab, myNode;
        End If

    Next

    Close #1

    Me.Text1.SetFocus

End Sub
 
now work perfect!

but forgotten, the comma, in:

Print #1,
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top