Posted on 2014-11-06
Last Modified: 2014-11-09
I run a program from a main menu

Private Sub SelectEmpToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectEmpToolStripMenuItem.Click
        Windows.Forms.Cursor.Current = Cursors.WaitCursor

        Dim emp As New EmpDispayForm
        emp.ShowInTaskbar = False
    End Sub

and the EmpDisplayForm works fine but if I run the same EmpDisplayform from another screen in the same project it wont compile it has error
type EmpDisplayform is not defined

It is being run by Clicking on an Icon
Me.AddUserAction(Actions.OpenDisplay, True, True, "&Open", True, My.Resources.Open, "Open Employee Display Selection", True, True, False, Keys.None)

Public Overrides Sub RunAction(ByVal id As Integer)
            Select Case id
                Case ListPanel.BaseActions.Open
                Case Actions.OpenDisplay

                Case Else

            End Select

End Sub

''' <summary>
''' open the selected Display
''' </summary>
Private Sub OpenEmp()
     Dim emp As New EmpDisplayForm    'This where the Error occurs
     ' refresh the list

End Sub

Thank You
Question by:Kevinfeening
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
  • 5
  • 4
LVL 15

Expert Comment

ID: 40427278
Can you right click on the empdisplayform in the line causing the error and select goto definition.

If should take you to the form. If it doesn't then the second form does not know about the empdisplayform.

How is empdisplayform defined in the actual form, is it Public, Private or Friend

Author Comment

ID: 40427334
No it doesn't go to definition from the error

From the main menu it does

the form is defined Public Class EmpDisplayform
LVL 40
ID: 40427637
Are you really in the same project, or are you in the same solution but 2 different projects. Some programmers do not really make the difference between a project and a solution, but it is important.

If it is in a solution, and the form is not in the same project as the line that tries to instantiate it, then you will get that error.

The way to go in that case is to first reference the project that contains the form in the project that needs it, and instantiate it by using the namespace of the original project. Let's say that the project that contains the form is called Project1:

Dim emp As New Project1.EmpDisplayForm
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.


Author Comment

ID: 40427674
When you look at the solution explorer its in the same project
if you look at the properties of the Project Assembly name is PayrollSystem, Root Namespace = PayrollSystem
Application type = Windows form application, startup Object = Startup

The folder containing empdisplayform is directly under it
LVL 40
ID: 40427863
The position of the folder or the file means nothing for the compiler, as long as the file is really part of the project.

If Dim emp As New EmpDispayForm works in one place in the project, the class should also be visible everywhere else.

You might try adding the namespace when referencing the class:

Dim emp As New PayrollSystem.EmpDisplayForm

If this does not work, then are Private Sub SelectEmpToolStripMenuItem_Click and Private Sub OpenEmp() in the same project? Although by default the Solution Explorer shows you a directory, the files in it are not necessarily linked to that project. The only sure way to know what is in a project is through the Object Browser (View menu or Ctrl-Alt-J). If it shows there under the Application name, and if it is in the same namespace as the calling code, then it should work.

Author Comment

ID: 40427908
Thanks for you help
I have little experience in VB as my previous questions show


Shows a lot of information

but in it is

--{} Payrollsystem
      + EmpDisplayform
Right click on empdisplayform

select go to definition it correctly displays empdisplayform
Select browse definition shows Public class empdisplayform
Find all references shows
Dim empdisplay as new empdisplayform()
Partial Class empdisplayform  \empdisplayform.Designer.vb(2,15)
public class empdisplayform   \empdisplayform.vb (16,14)

Hope this helps
LVL 40
ID: 40428476
OK. Now, we know that EmpDisplayform is in PayrollSystem.

But is the module or form that contains Private Sub OpenEmp also in the same namespace?

Author Comment

ID: 40429459
found name space by using
dim ns as string = gettype(EmpDisplayform).NameSpace it is in the same namespace as the mainform

and the form calling EmpDisplayform is in a different namespace
it uses ??
namespace company.Payroll.UiLists
'all the code then
end Namespace

Where EmpDisplayform uses
Imports company.Payroll.UiLists

Beyond me
hope this helps
LVL 40

Accepted Solution

Jacques Bourgeois (James Burger) earned 500 total points
ID: 40429533
Good, we found the cause of the problem. If they are not in the same namespace, then you cannot use the form directly only by its class name.

A namespace is nothing but a way to find classes in a system, very similar to directories/paths that enables you to find files in the file system. When it is well organized, you find your way easily. If it was set up without some planning, you end up with a mess. I hope for you that this is not a mess.

You aim is now to find the correct path between the calling code and the form, that is the correct namespace.

If everything is in the same project, then simply giving the namespace of the form you want to open should do it.  Something like the one I gave you before : Dim emp As New PayrollSystem.EmpDisplayForm .

If the calling code and EmpDisplayForm are not in the same project however, the project that wants to use it needs to reference the project that contains it before that code compiles.

Author Comment

ID: 40429635
There has to be something I have done wrong

as Dim emp As New PayrollSystem.EmpDisplayForm the payrollsystem doesn't appear in the selection drop down
I will erase the form and start again

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe 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…
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…
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…
Suggested Courses
Course of the Month7 days, 10 hours left to enroll

632 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