I am formally studying VB.NET and the teacher has temporarily left us with a textbook to study.
In a chapter on Arrays an example of actual code is given, as shown at the bottom here.
We use Microsoft Visual Basic 2008 Express edition for our code.
However a simple Copy&Paste of the code below will not work.
To be exact the one Build error is : 'Sub Main' was not found in 'Ex1402.Module1'
where Ex1402 is the name of the Project and Module1 is the module in question
( ie. the default name ).

Any ideas as to the exact problem, please ?
Is it related to the fact that there is no module that actually uses this class
and/or that it is a 'ConsoleApplication' ?
Also does 'Namespace' have anything to do with the problem ?

Thank you in advance.

Option Strict On
Imports System
Namespace ArrayDemo ' a simple class to store in the array
    Public Class Employee
        Private empID As Integer ' constructor
        Public Sub New(ByVal empID As Integer)
            Me.empID = empID
        End Sub 'New
        Public Overrides Function ToString() As String
            Return empID.ToString()
        End Function 'ToString
    End Class 'Employee
    Class Tester
        Public Sub Run()
            Dim intArray() As Integer
            Dim empArray() As Employee
            intArray = New Integer(5) {}
            empArray = New Employee(3) {} ' populate the array
            Dim i As Integer
            For i = 0 To empArray.Length - 1
                empArray(i) = New Employee(i + 5)
            Next i
            Console.WriteLine("The Integer array...")
            For i = 0 To intArray.Length - 1
                Console.WriteLine(intArray(i).ToString())
            Next i
            Console.WriteLine(ControlChars.Lf + "The employee array...")
            For i = 0 To empArray.Length - 1
                Console.WriteLine(empArray(i).ToString())
            Next i
        End Sub 'Run
        Shared Sub Main()
            Dim t As New Tester()
            t.Run()
        End Sub 'Main
    End Class 'Tester
End Namespace 'ArrayDemo

Hi,

Because your working with Arrays, you should use the Imports System.Collection namespace.
You can find some explanation, here.

Sorry, but that simply did not work. As per the examples shown in that msdn link
I then used

Imports System
Imports System.Collections
Imports Microsoft.VisualBasic

at the top of the code but still got the same message.

With one extra twist : when I start a new Project I always click View Solution Explorer.
This has the code file defaulted to 'Module1' but I then change that to the Project Name
( in this case 'EX1402' ). However the error message STILL mentions 'Module1',
as mentioned in my first post.

Now also an extra message. The code shown above includes :

Class Tester
Public Sub Run( )
Dim intArray( ) As Integer

Now this third line has the 'intArray( ) As Integer' in a reddish color
and to the left of the line number ( 20 ) is a red disc.
Hovering over these shows that 'Integer represents a 32-bit signed integer' and
'At Ex1402.vb, Line 20 Character 17 ('Run', line 2).

Hope that is not MORE confusing.

Steps:

1. Open VS2008 + File Menu + Project + VisualBasic + Console Application
2. Remove the content of Module1.vb
3. Copy+paste the code you just posted into the Module1.vb
4. Solution explorer + Right click on project name + Properties + Startup Object = Sub Main (choose Sub Main option)
5. F5 to run.

Bingo : it worked. ( Even though I initially managed to click in a wrong place and so mess it up. )

Thank you very much indeed.

However that still leaves the question of what the textbook writer was doing in the first place ?

Was there some ( minor ? ) change that could have been made to that code that would have
obviated my need to, well, post a query here ?

Also, I notice you have amended my previous post, specifically, as I understand it,
regarding my use of the 'CODE' function above this message area.
I thought it was a case of doing a Ctrl&A on the VB.NET code and then clicking 'CODE'.
Or should that be 'ICODE' ?

Thanks again.

commented: :) Thanks. +11

Glad you got it woking. Use [code] [/code] tags to wrap programming code.


Please mark this thread as solved if you have found an answer to your question and good luck!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.