Solved

Synatx Error Instantiating a New Class

Posted on 2007-03-23
1
178 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

749 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