Confused by classes (Nightmare!)

  • Thread starter Thread starter C CORDON
  • Start date Start date
C

C CORDON

I am verry confused about classes. I understand that classes can encapsulate
properties, methods, events (don't know hoy to add events to a class), etc.

I am confused with this: if you can encapsulate all this in a class, how do
you decide or when is it necessary to Dim x as new MyClass or when to use
Imports MyClass. Eather way you have access to all that is inside it.

If I make a class calld User and I want it to handle everything related to
the user: LoginUser, IsLogged, Store the user info. and make that info last
through all the time the app is running how do I get this functionality.

This are my main questions.

If there is a good and understanable document about this please point me to
it.

TIA!
 
"C CORDON"
I am verry confused about classes. I understand that classes can
encapsulate properties, methods, events (don't know hoy to add events to a
class), etc.
Public/Friend Class MyClassA
Friend/Public Event myevent(byval mes as string)
Private sub/function whatever
raise myevent("Hello")
End sub/function
I am confused with this: if you can encapsulate all this in a class, how
do you decide or when is it necessary to Dim x as new MyClass or when to
use Imports MyClass. Eather way you have access to all that is inside it.

These two you have not much to do with each other.

Dim x as new MyClassa (myclass is reserverd a reserved word) is for a class
that looks like this beneath (very ugly written in this as all samples not
nice however written as short as possible)

Public Class MyClassa
Public A as integer
End Class

Than you should first create an object from it what is
dim x as new myClassa
and use it as
x.a = 1
You can make from this as much objects as you want and they are deleted, as
soon as they go out of scoop or/and that there are no references anymore
to/from it, by the Garbage Collector

While you can use a so called shared class that looks like this
Public Class MyClassa
Public shared a as integer
End class

This you can use direct as
MyClassa.x
And this will not be deleted by the Garbage Collector however destroyed with
the program at the end and therefore would be used with care. You would not
make objects from it, this way of using is named "shared class" in VBNet

You can import the last as
import yourprojectname.myclassa
And than you can write
a=1
And become probably everywhere in conflict when you would use "a" :-)
If I make a class calld User and I want it to handle everything related to
the user: LoginUser, IsLogged, Store the user info. and make that info
last through all the time the app is running how do I get this
functionality.

This are my main questions.
I hope that I answered your first question with the "shared class".

I hope this helps something?

Cor
 
C CORDON said:
events (don't know hoy to add events to a class)

Visual Basic Language Concepts -- Events and Delegates
<URL:http://msdn.microsoft.com/library/en-us/vbcn7/html/vaconEventsDelegatesInheritance.asp>


..NET Framework Developer's Guide -- Handling and Raising Events
I am confused with this: if you can encapsulate all this in a class, how
do you decide or when is it necessary to Dim x as new MyClass or when to
use Imports MyClass. Eather way you have access to all that is inside it.

By importing a class, you will only get unqualified access to /shared/
members of a class, but not to its instance members.
If I make a class calld User and I want it to handle everything related to
the user: LoginUser, IsLogged, Store the user info. and make that info
last through all the time the app is running how do I get this
functionality.

\\\
Public Module Program
Private m_User As New User()

Public Sub Main()
m_User = New User()
...
Application.Run(New MainForm())
End Sub

Public ReadOnly Property User() As User
Get
Return m_User
End Get
End Property
End Module
///

Access to the user: 'Program.User'.
 
Thnak you verry much for pointing me in the right direction.

Have a little doubt about when shoul it be used buy ill look up some more
information on the web.

Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top