Solved

Synatx Error Instantiating a New Class

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…
Suggested Courses
Course of the Month8 days, 3 hours left to enroll

617 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