is the a (Form) a (Class) or an (Object) ?

Are we going back to VB6 ?!?!?!

Page 1 of 1

12 Replies - 1218 Views - Last Post: 04 August 2008 - 04:09 PM Rate Topic: -----

#1 vbnetskywalker  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 98
  • Joined: 08-June 08

is the a (Form) a (Class) or an (Object) ?

Posted 01 August 2008 - 05:23 PM

in VB.Net 2003 the form was a class .....
by the name of the class we can access only the (Shared) members (that is the right I think).


in VB.Net 2005 the form is also a class
but I see by the name of the class we can access members that are not (shared)(and this is not right is it ???!?!!??!)
are we going back to VB6 ?!?!?!


if any one see what I missed please tell me cuz I see this is out of programming principles

I hope I'm missing something

Is This A Good Question/Topic? 0
  • +

Replies To: is the a (Form) a (Class) or an (Object) ?

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2253
  • View blog
  • Posts: 9,443
  • Joined: 29-May 08

Re: is the a (Form) a (Class) or an (Object) ?

Posted 01 August 2008 - 06:14 PM

Its both everything thing in VB.Net is an Object.
A Class is a definition for an object.

I help this is informative.
Was This Post Helpful? 0
  • +
  • -

#3 jacobjordan  Icon User is offline

  • class Me : Perfection
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,499
  • Joined: 11-June 08

Re: is the a (Form) a (Class) or an (Object) ?

Posted 01 August 2008 - 06:40 PM

Your form you are editing in the designer is a class that inherits from a base class System.Windows.Forms.Form. Any data type, a class, structure, enum, property, or anything, is an object.

Quote

by the name of the class we can access only the (Shared) members (that is the right I think).

If you are not creating an instance of your class, yes only the shared members are visible. Shared means you can access that object without creating an instance of it. However, if you are creating an instance of it (like if you use a Dim SomeName As Form statement), then the Shared and Public members will be visible. If the class in question is in the same assembly as the code you are accessing it from, and you are creating an instance of it, then the Shared, Public, and Friend members will be visible.
Was This Post Helpful? 0
  • +
  • -

#4 lewax00  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 24
  • Joined: 13-January 08

Re: is the a (Form) a (Class) or an (Object) ?

Posted 02 August 2008 - 10:01 AM

And if you're just seeing a listing of members in the Intellisense it may not mean they're usable, because I believe it lists all Public, Friend, and Shared members regardless. In the same way instances will have shared members listed even if they aren't usable from the instance.
Was This Post Helpful? 0
  • +
  • -

#5 vbnetskywalker  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 98
  • Joined: 08-June 08

Re: is the a (Form) a (Class) or an (Object) ?

Posted 04 August 2008 - 11:54 AM

sorry for being late ,.... I was busy a little bit.

I'm sorry I couldn't read carefully what you posted .... because I see you feeling this is right ,
and all I was thinking about is one idea I couldn't stop thinking about
and I think if you read it now you will feel the way I feel (Wrong) . so I think I wasn't clear enough last time
here it is clearly

let's say I have two forms (Form1 , Form2)

	Public Class Form2
		Public Memb As Integer
		' forget about other members
	End Class



and in any sub in the Form1
	Public Class Form1
		Private Sub AnySub()
			Form2.Memb = 1  ' it's accessible !!!!!
		End Sub
	End Class



the questions is all about :
if I can access the members that are not (Shared) then what does the KeyWord (Shared) do ???
what happened says : it's not needed .... let's just throw it away out of the language.

I see there has to be something wrong .... and I'll get it some day .... I promise
Was This Post Helpful? 0
  • +
  • -

#6 jacobjordan  Icon User is offline

  • class Me : Perfection
  • member icon

Reputation: 113
  • View blog
  • Posts: 1,499
  • Joined: 11-June 08

Re: is the a (Form) a (Class) or an (Object) ?

Posted 04 August 2008 - 12:43 PM

Shared is very useful. A shared object can be access without actually creating an instance of that object. For example, with your form1 form2 example

Here is the code in form 2:
    Public Class Form2
        Public PublicMemb As Integer
        Shared SharedMemb As Integer
        ' forget about other members
    End Class


And here is the code for form1:
    Public Class Form1
        Private Sub AnySub()
            Dim F2 As New Form2() 'Creating an instance of form2
            F2.PublicMemb = 1  'public objects are accessible
            F2.SharedMemb = 1  'shared objects are accessible
        End Sub
    End Class


In that code, we created an instance of form2 with Dim F2 As New Form2(). When you create an instance of an object, public and shared members are visible.

In another version of Form1, we will not create an instance of Form2:
    Public Class Form1
        Private Sub AnySub()
            'No instance of form2 created, we will access it directly
            Form2.SharedMemb = 1  'shared objects are accessible
            'In this example, trying to access PublicMemb will result in a compile error,
            'because we never created an instance of Form2.
            Form2.PublicMemb = 1  'ERROR: Cannot access non-shared objects without creating an instance of it
        End Sub
    End Class


Was This Post Helpful? 0
  • +
  • -

#7 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2253
  • View blog
  • Posts: 9,443
  • Joined: 29-May 08

Re: is the a (Form) a (Class) or an (Object) ?

Posted 04 August 2008 - 01:00 PM

Shared is very useful as it allows the you to share a property / variable among new instances of a class.
For example keeping track of node id numbers.
Class Node
 Shared AllNodeIDs as new list(of long)
    Protected mConnctedToNodes As New List(Of Node)


    Private mText As String
    Public Property Text() As String
        Get
            Return mText
        End Get
        Set(ByVal value As String)
            mText = value
        End Set
    End Property
    Private mID As Long
    Public Property ID() As Long
        Get
            Return mID
        End Get
        Set(ByVal value As Long)
            mID = value
        End Set
    End Property

    Public Sub AddNodal(ByRef ThisNodel As Node)
        If mConnctedToNodes .Contains(ThisNode) Then Exit Sub
        mConnctedToNodes .Add(ThisNode)
    End Sub
    Public Sub New(ByRef nid As Long, Optional ByRef ThisText As String = "")
' The shared variable allows this to self-contained, so I don't need a mangement class     
   If AllNodeIDs .Contains(nid) Then
            Me.Finalize()
            Exit Sub
        End If
        AllNodeIDs .Add(nid)
        mText = ThisText

    End Sub
End Class


Was This Post Helpful? 0
  • +
  • -

#8 vbnetskywalker  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 98
  • Joined: 08-June 08

Re: is the a (Form) a (Class) or an (Object) ?

Posted 04 August 2008 - 01:11 PM

every one knows what (Shared) dose
forget about what I said

Quote

what does the KeyWord (Shared) do ???
what happened says : it's not needed .... let's just throw it away out of the language.

this was for poetry :D


I wanna know why it allowed me to access the members that are (public)and not (shared) by the name of the class

they are not shared ......not shared ...
how could I access them from the name of the class?!?!?!?!? :blink: :blink: :blink:
Was This Post Helpful? 0
  • +
  • -

#9 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2253
  • View blog
  • Posts: 9,443
  • Joined: 29-May 08

Re: is the a (Form) a (Class) or an (Object) ?

Posted 04 August 2008 - 01:19 PM

View Postvbnetskywalker, on 4 Aug, 2008 - 09:11 PM, said:

every one knows what (Shared) dose
forget about what I said

Quote

what does the KeyWord (Shared) do ???
what happened says : it's not needed .... let's just throw it away out of the language.

this was for poetry :D


I wanna know why it allowed me to access the members that are (public)and not (shared) by the name of the class

they are not shared ......not shared ...
how could I access them from the name of the class?!?!?!?!? :blink: :blink: :blink:

Maybe because their Public?
Was This Post Helpful? 0
  • +
  • -

#10 vbnetskywalker  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 98
  • Joined: 08-June 08

Re: is the a (Form) a (Class) or an (Object) ?

Posted 04 August 2008 - 01:32 PM

public ...so what??????? :blink:

don't worry
days are coming , and I will find it :rolleyes:

thanks for trying to help me .... I appreciate it :^:
Was This Post Helpful? 0
  • +
  • -

#11 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2253
  • View blog
  • Posts: 9,443
  • Joined: 29-May 08

Re: is the a (Form) a (Class) or an (Object) ?

Posted 04 August 2008 - 01:58 PM

In a class
A Public definition is created for each new instance.
eg
Class Person
 Public Name_Pub as string
End Class



Where as a Shared definition is created once and is shared amongst the instances of that class
Class Person
 Public Name_Pub as string
 Shared People As New List(Of People) ' This is only accessible from within the Person Class
end class


Class Person
 Public Name_Pub as string
 Public Shared People As New List(Of People) ' This is only accessible from outside of the Person Class
end class



Accessing via
Dim ThisPerson as New Person
ThisPerson.Name_Pub="Adam"




But it is better practice to use properties
Class Person
 Private myName as string
    Public Property Name() As String
        Get
            Return myName 
        End Get
        Set(ByVal value As String)
            myName = value
        End Set
    End Property



Dim ThisPerson as new Person
ThisPerson.Name="Adam"



If asking why you can see protected and private things whilst you are type (intellisense), they maybe set to displayed.
They can be turned off by
Opening Object Browser
clicking on Object Browser Setting (Last one in toolbar)
De selecting the items you don't want to see.
Was This Post Helpful? 0
  • +
  • -

#12 lewax00  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 24
  • Joined: 13-January 08

Re: is the a (Form) a (Class) or an (Object) ?

Posted 04 August 2008 - 02:42 PM

If I remember correctly, Public, Friend, and Shared are all accessible from other objects, while Private and Protected are not. The differences with Shared have already been explained so I'll skip that. I'm not really sure what Dim is but I generally don't use it except as temporary local variables.

(I can't say I remember the difference between Public and Friend and between Private and Protected with enough certainty to post it, so I won't)
Was This Post Helpful? 0
  • +
  • -

#13 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2253
  • View blog
  • Posts: 9,443
  • Joined: 29-May 08

Re: is the a (Form) a (Class) or an (Object) ?

Posted 04 August 2008 - 04:09 PM

A Better Exaplanation of the Difference
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1