|
-
Oct 1st, 2000, 04:02 PM
#1
Thread Starter
Frenzied Member
Well, this problem has been bugging me the whole day, so I though maybe you experts could help me...
The idea is really simple: when you click cmdAdd, the contents of Text1 are added to TreeView1. It's supposed to receive a "path", delimited with "\" characters, and add nodes to the treeview according to them, much like in Windows Explorer.
My code is as follows:
Code:
Private Sub cmdAdd_Click()
On Error Resume Next
Dim TempArray() As String
Dim TempStr As String
Dim FolderFound As Boolean
TempArray = Split(Text1.Text, "\")
For i = 0 To UBound(TempArray) + 1
TempStr = TempStr & TempArray(i) & "\"
For j = 1 To TreeView1.Nodes.Count
If TreeView1.Nodes(j).FullPath & "\" & TreeView1.Nodes(j).Text = TempStr & "\" Then
FolderFound = True
Exit For
End If
Next j
If Not FolderFound Then
TreeView1.Nodes.Add i + 1, tvwChild, , TempArray(i)
End If
Next i
End Sub
But it doesn't work!
I hope you can help me on this one.
Thanks for reading!
Bye,
-Jotaf98
-
Oct 1st, 2000, 04:55 PM
#2
Well, what makes it "Not work"?
-
Oct 1st, 2000, 05:41 PM
#3
Hyperactive Member
A few errors:
Hello Jotaf98,
I think you would find the bugs easier if you did not include on Error Resume Next. In your code, you should not get ANY errors if it is written properly.
If you examine the code below which I have tried to keep as similar as possible to your original, you may see where the flaws were in your code.
Good Luck
Code:
Private Sub cmdAdd_Click()
'On Error Resume Next
Dim TempArray() As String
Dim TempStr As String
Dim FolderFound As Boolean
Dim i, j As Integer
Dim myParent As Long
TempArray = Split(Text1.Text, "\")
myParent = 0
For i = 0 To UBound(TempArray)
TempStr = TempStr & TempArray(i) & "\"
For j = 1 To TreeView1.Nodes.Count
FolderFound = False
Debug.Print TreeView1.Nodes(j).FullPath
If TreeView1.Nodes(j).FullPath & "\" = TempStr Then
FolderFound = True
myParent = TreeView1.Nodes(j).Index
Exit For
End If
Next j
If Not FolderFound Then
If myParent = 0 Then
myParent = TreeView1.Nodes.Add(, tvwFirst, , TempArray(i)).Index
Else
myParent = TreeView1.Nodes.Add(myParent, tvwChild, , TempArray(i)).Index
End If
End If
Next i
End Sub
Regards
-
Oct 1st, 2000, 06:08 PM
#4
Sorry, about the last post. I got the error and here's the solution:
Code:
Public x As Long
Private Sub Form_Load()
TreeView1.Style = tvwTreelinesPlusMinusText
TreeView1.LineStyle = tvwRootLines
TreeView1.Indentation = 1
End Sub
Private Sub cmdAdd_Click()
On Error Resume Next
Dim TempArray() As String
Dim TempStr As String
Dim FolderFound As Boolean, i As Long, j As Long, k As Long
TempArray = Split(Text1.Text, "\")
For i = 0 To UBound(TempArray)
TempStr = TempArray(i)
For j = 1 To TreeView1.Nodes.Count
If TreeView1.Nodes(j).Text = TempStr Then
FolderFound = True
TreeView1.SelectedItem = TreeView1.Nodes(j)
Exit For
End If
Next j
If Not FolderFound Then
x = x + 1
If i > 0 Then TreeView1.Nodes.Add TreeView1.SelectedItem.Index, tvwChild, Str(x) & "x", TempArray(i) Else TreeView1.Nodes.Add , , Str(x) & "x", TempArray(i)
TreeView1.SelectedItem = TreeView1.Nodes(Str(x) & "x")
End If
FolderFound = False
Next i
End Sub
-
Oct 2nd, 2000, 02:54 AM
#5
Thread Starter
Frenzied Member
Thanks everyone!
The code worked almost ok when I first made it, but there was a small flaw that I just couldn't work out, so I started messing with the code and the result was what you all saw 
Bye
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|