An Enum question


Author
Message
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Anything for you, Ivan BigGrin
Ivan George Borges
Ivan George Borges
Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
Thanks guys, got the idea.
StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
No, Ivan, you can have as many Imports as you want... they don't affect the runtime whatsoever.  They're more compiler directives than anything.
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Not necessarily.  But keep in mind that you can create multiple sealed classes as well.  It is best to keep things that are related within a single class. 
Ivan George Borges
Ivan George Borges
Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)Strategic Support Team Member (3.5K reputation)
Group: StrataFrame MVPs
Posts: 1.9K, Visits: 21K
Ben Chase (12/12/2006)
Basically, a "sealed" class is what you use in VB to be a container for methods.

Hiya.

Having a sealed class being a container for methods, I might need to write many "Imports" on the top of it for all the methods that will be in the class.

Would this be a bad practice?

StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
You can have as many classes in a file as you want... you can even have nested classes.  Basically, with VB.NET, you can have a 1 file to 1 class relationship, or you can have a multiple file to 1 class relationship (partial classes... part of the class exists in each file), or you can have a 1 file to multiple class relationship.  The code file does not define a class... the Public Class <ClassName> and End Class do.  Open up one of the .designer.vb files for one of your business objects and drop down the left combo box at the top of the file... you'll see how many classes exist in that one file.  And besides the business object, they're all nested.
StarkMike
StarkMike
StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)
Group: Forum Members
Posts: 436, Visits: 944
And here's where my VB6 brain  is having trouble... I dont understand how I can place the enum 'outside' of the Module.

I've seen examples like this:

Public Class Item

End Class

Public Class Inventory

    Dim itm as new Item

End Class

I dont understand how you can have two classes in the same file. I am under the impression that you can only have one class per file.  What gives? Tongue

P.S. I really appreciate this thread and the advice on using a shared class instead of a module... that is invaluable information that I might not otherwise pickup. Cool

StarkMike
StarkMike
StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)
Group: Forum Members
Posts: 436, Visits: 944
Awesome! Thanks for the info.
StrataFrame Team
S
StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)StrataFrame Developer (4.2K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
Basically, a "sealed" class is what you use in VB to be a container for methods.  (C# has a "static" class, but "sealed" is as close as you can get in VB).  You create the class, and it becomes the module (actually, when you compile a module in VB.NET, it creates a class out of the module on the back end.. which you can see if you use reflection).

Public NotInheritable Class MyModuleClass

     '-- A private constructor keeps someone from accidentally trying to create an instance of this class
     Private Sub New() 
     End Sub

     '-- All of your methods and fields are then marked with "Shared"
     Public Shared Function MyFunc(ByVal value As String) As String
          '-- Parse the value
     End Function

End Class

'-- When you access these Shared methods and fields, you access them like this:
MyModuleClass.MyFunc("test") '-- you use the ClassName. syntax and you get all of the shared methods on the class

StarkMike
StarkMike
StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)StrataFrame User (448 reputation)
Group: Forum Members
Posts: 436, Visits: 944
Ok, I moved the enums outside of the Module and now it looks like this:

Public Module Module1

End Module

Public Enum ParentFormIDEnum As Integer
    POReceiving = 1
    Production = 4
    Returns = 5
End Enum

And here's where my VB6 brain Hehe is having trouble... I dont understand how I can place the enum 'outside' of the Module. When I created the module, it created a Module1.vb file... and inside it was

Module Module1

End Module

I assumed that everything had to reside inside there, and the only thing allowed outside was the Imports statements at the top.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search