Solved

Synatx Error Instantiating a New Class

Posted on 2007-03-23
1
176 Views
Last Modified: 2013-12-25
I am converting some C# code to VB. I create the class below:
Public Class FileNode
        Inherits TreeNode
        Private _fileInfo As FileInfo
        Private _directoryNode As DirectoryNode

        Public Sub New(ByVal directoryNode As DirectoryNode, ByVal fileInfo As FileInfo)
            MyBase.New(fileInfo.Name)
            Me._directoryNode = directoryNode
            Me._fileInfo = fileInfo

            Me.ImageIndex = 1 'DirectCast(_directoryNode.TreeView, FileSystemTreeView).GetIconImageIndex(_fileInfo.FullName)
            Me.SelectedImageIndex = Me.ImageIndex

            _directoryNode.Nodes.Add(Me)
        End Sub
    End Class

I now call this class from a function (basically building up nodes in  a treeview):

        Public Sub LoadFiles()
            For Each file As FileInfo In _directoryInfo.GetFiles()
                New FileNode(Me, file)
            Next
        End Sub

However, I get a syntax error on the word New (New FileNode(Me, file)). Any ideas how to get around this?
0
Comment
Question by:Craig_Muckleston
1 Comment
 
LVL 7

Accepted Solution

by:
dctuck earned 50 total points
ID: 18780741
You need to your new class instance to a variable, e.g.:

      Public Sub LoadFiles()
            Dim myFileNode As FileNo
            For Each file As FileInfo In _directoryInfo.GetFiles()
                myFileNode = New FileNode(Me, file)
            Next
        End Sub

Also, I've noticed that you are passing Me as a paramter - the constructor for your FileNode class specifies that the first parameter should be a DirectoryNode object, but passing Me as a parameter will pass across the form or class, or wherever you are calling the function from.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MsgBox 4 43
Error on link 14 36
VB.net Facial recognition software (time and attendance) 6 13
Where can I ask about my ASP.NET MVC project? 6 16
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now