Solved

Synatx Error Instantiating a New Class

Posted on 2007-03-23
1
175 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Object to array 7 27
SQl help with selection 14 44
Form design in vb.net 7 18
VB.Net - CSV to Oracle table 4 27
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

708 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

18 Experts available now in Live!

Get 1:1 Help Now