Enum namespace problem in Class Library dll

tnorton

Member
Joined
Sep 28, 2007
Messages
19
Programming Experience
1-3
I am trying to create a dll that looks up a name from a list of ENUM and returns a serial control string to control an external device.
My problem is the full namespace needs to be put befor the ENUM to use it.

This is my class called PSdata
VB.NET:
Expand Collapse Copy
Namespace Nortronics
    Public Class PSdata
        Enum enmCommand
            CameraSelect
            MultiScreen
        End Enum
        Shared Function PSCommand(ByVal myCommand As enmCommand) As String
            Select Case myCommand
                Case enmCommand.CameraSelect
                    Return "OCS"
                Case enmCommand.MultiScreen
                    Return "OMS"
                Case Else
                    Return "nothing"
            End Select
        End Function
    End Class
End Namespace

This is the EXE that will use the DLL.

VB.NET:
Expand Collapse Copy
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim PSdata As PSdata.Nortronics.PSdata
     
    TextBox1.Text = PSdata.PSCommand(PSdata.enmCommand.MultiScreen)

End Sub

As you can see, I need to use the full Namespace to reference the enum
TextBox1.Text = PSdata.PSCommand(PSdata.enmCommand.MultiScreen)

Any what I can make this become
TextBox1.Text = PSdata.PSCommand(MultiScreen)
 
No, you can make it become
TextBox1.Text = PSdata.PSCommand(enmCommand.MultiScreen)
by putting the enum declaration outside the class.
 
No, you can make it become
TextBox1.Text = PSdata.PSCommand(enmCommand.MultiScreen)
by putting the enum declaration outside the class.

This sort of worked
I had to create a refernect to the ENUM in the form once I moved it out of the class.

Form code
VB.NET:
Expand Collapse Copy
    Dim PSdata As PSdata.Nortronics.PSdata
    Dim PScmd As PSdata.enmCommand

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = PSdata.PSCommand(PScmd.MultiScreen)
        TextBox1.Text = PSdata.PSCommand(Global.PSdata.enmCommand.CameraSelect)
    End Sub


Class Code
VB.NET:
Expand Collapse Copy
[COLOR="Red"]Public Enum enmCommand
    CameraSelect
    MultiScreen
End Enum[/COLOR]
Namespace Nortronics

    Public Class PSdata

        Shared Function PSCommand(ByVal myCommand As enmCommand) As String
            Select Case myCommand
                Case enmCommand.CameraSelect
                    Return "OCS"
                Case enmCommand.MultiScreen
                    Return "OMS"
                Case Else
                    Return "nothing"
            End Select


        End Function
    End Class
End Namespace
 
Why did you move it outside the namespace? Also use the Imports statement, you're already using it loads with the framework itself. So putting "Imports PSdata.Nortronics" at the top of your form class solves that. You can also go to project properties, referencess tab, and checkbox the namespace the to import it, you will see many checks already for framework imported namespaces. Creating a variable of that type is not a good solution for working with namespaces.
 
Why did you move it outside the namespace? Also use the Imports statement, you're already using it loads with the framework itself. So putting "Imports PSdata.Nortronics" at the top of your form class solves that. You can also go to project properties, referencess tab, and checkbox the namespace the to import it, you will see many checks already for framework imported namespaces. Creating a variable of that type is not a good solution for working with namespaces.


Your a bloody ledgend. Thanks
 
Back
Top