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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with treeview error 13 type mismatch

Status
Not open for further replies.

tolsym

Technical User
Joined
Nov 22, 2004
Messages
3
Location
GB
i have a treeview control to display file directory that works fine when i run the just form as a project in vb.

However when i add the form to a larger project i get a Run-time error '13' Type mismatch at the line to create the root node which is:

Set pnode = treeview1.nodes.add(, , file_name, file_name)

the file_name is a variable containing the file path to the root directory.

How can i correct this error? (the task is completed when i set execution to the next statement at runtime)

I also have a problem in the treeview click event, I get a compile error: Invalid use of New keyword at

Dim node as New node

I would also appreciate a solution to this. the form runs just fine on its own.

thanks

 
What is the value of file_name when it fails?

Dim node As New node will never work because you are attempting to create a variable with the same name as a predefined object type. Try changing to

Dim MyNode As Node

and that problem should disappear.

Andy
--
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
 
Thanks for the response.

The value of file_name when it fails is "C:\Project\" which is the application folder.

as you suggested i changed the name from node to Newnode, but still got the same error.
 
maybe if you dim your node like this :
Dim nodx As MSComctlLib.node

(I had a similar problem, it occured because I was using the wrong library)
 
Hmm. Can you post the relevant code?

Andy
--
"Logic is invincible because in order to combat logic it is necessary to use logic." -- Pierre Boutroux
 
i have sorted out the dim new node bit, thanks. the code:

Option Explicit

Dim fnode As Node
Dim FIndent As Integer
Dim FIndex As Integer
Dim StrtPath As String


Private Sub cmdGo_Click()
Dim x As Integer, S$
Dim file_name As String

file_name = App.Path
If Right$(file_name, 1) <> "\" Then file_name = file_name & "\"
Open file_name & "Mytest.txt" For Output As #1

'Text1.Text = ""
TreeView1.Nodes.Clear

file_name = txtPath.Text
If Right$(file_name, 1) <> "\" Then file_name = file_name & "\"

'Text1.Text = Text1.Text & file_name & vbCrLf
' need \ on end of key here------------|
Set fnode = TreeView1.Nodes.Add(, , file_name, file_name)
'initial data to file; topmost root of tree
Print #1, file_name
'initialise variables
FIndent = 1
FIndex = 0
TreeView1.Visible = False
LblPrompt.Caption = "Processing drive..."
LblPrompt.Refresh
'note does not end with '\'
StrtPath = Left$(file_name, Len(file_name) - 1)
'start the directory reading
Get_Files StrtPath
TreeView1.Visible = True
LblPrompt.Caption = "Finished"

Close 1

End Sub

hope u can help, the funny thing is it works when you open it as a project with a single form.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top