Looking for examples of class and its properties 
Author Message
 Looking for examples of class and its properties

I am just looking for a simple example of class, function and properties.

Thanks.



Tue, 13 Jul 2004 00:05:35 GMT  
 Looking for examples of class and its properties
Here's a relatively simple example...

HTH,

Jim

Public Class Employee

Public Salary As Integer

Public emp_Name As String

Public emp_Position As String

Public Sub New(ByVal basePay As Integer, ByVal name As String, ByVal
position As String)

Salary = basePay

emp_Name = name

emp_Position = position

End Sub

Public Sub Raise(ByVal amount As Integer)

Salary += amount

End Sub

End Class


Quote:
> I am just looking for a simple example of class, function and properties.

> Thanks.



Tue, 13 Jul 2004 00:06:21 GMT  
 Looking for examples of class and its properties
Jim-

(picking nits here)
You don't have any properties there, those are fields. . . To modify your
example:

Public Class Employee
    Private m_Salary As Integer
    Private m_Name As String
    Private m_Position As String

Public Sub New(ByVal basePay As Integer, ByVal name As String, _
    ByVal position As String)

    Me.Salary = basePay
    Me.Name = name
    Me.Position = position
End Sub

Public Property Salary() As Integer
    Get
        Return m_Salary
    End Get
    Set(ByVal Value As Integer)
        m_Salary = Value
    End Set
End Property

Public Property Name() As String
    Get
        Return m_Name
    End Get
    Set(ByVal Value As String)
        m_Name = Value
    End Set
End Property

Public Property Position() As String
    Get
        Return m_Position
    End Get
    Set(ByVal Value As String)
        m_Position = Value
    End Set
End Property

Public Sub Raise(ByVal amount As Integer)
    Me.Salary += amount
End Sub

End Class
--
Jacob Grass
Microsoft .NET MVP


Quote:
> Here's a relatively simple example...

> HTH,

> Jim

> Public Class Employee

> Public Salary As Integer

> Public emp_Name As String

> Public emp_Position As String

> Public Sub New(ByVal basePay As Integer, ByVal name As String, ByVal
> position As String)

> Salary = basePay

> emp_Name = name

> emp_Position = position

> End Sub

> Public Sub Raise(ByVal amount As Integer)

> Salary += amount

> End Sub

> End Class



> > I am just looking for a simple example of class, function and
properties.

> > Thanks.



Tue, 13 Jul 2004 00:24:03 GMT  
 Looking for examples of class and its properties
Ack, sorry...didn't see his request for properties.  My bad ;-).  Time to
get some more coffee.

Jim



Quote:
> Jim-

> (picking nits here)
> You don't have any properties there, those are fields. . . To modify your
> example:

> Public Class Employee
>     Private m_Salary As Integer
>     Private m_Name As String
>     Private m_Position As String

> Public Sub New(ByVal basePay As Integer, ByVal name As String, _
>     ByVal position As String)

>     Me.Salary = basePay
>     Me.Name = name
>     Me.Position = position
> End Sub

> Public Property Salary() As Integer
>     Get
>         Return m_Salary
>     End Get
>     Set(ByVal Value As Integer)
>         m_Salary = Value
>     End Set
> End Property

> Public Property Name() As String
>     Get
>         Return m_Name
>     End Get
>     Set(ByVal Value As String)
>         m_Name = Value
>     End Set
> End Property

> Public Property Position() As String
>     Get
>         Return m_Position
>     End Get
>     Set(ByVal Value As String)
>         m_Position = Value
>     End Set
> End Property

> Public Sub Raise(ByVal amount As Integer)
>     Me.Salary += amount
> End Sub

> End Class
> --
> Jacob Grass
> Microsoft .NET MVP



> > Here's a relatively simple example...

> > HTH,

> > Jim

> > Public Class Employee

> > Public Salary As Integer

> > Public emp_Name As String

> > Public emp_Position As String

> > Public Sub New(ByVal basePay As Integer, ByVal name As String, ByVal
> > position As String)

> > Salary = basePay

> > emp_Name = name

> > emp_Position = position

> > End Sub

> > Public Sub Raise(ByVal amount As Integer)

> > Salary += amount

> > End Sub

> > End Class



> > > I am just looking for a simple example of class, function and
> properties.

> > > Thanks.



Tue, 13 Jul 2004 00:24:56 GMT  
 Looking for examples of class and its properties
Hey thanks guys.  By the way, what do you which book is best to understand
object, property etc.

Thank you again


Quote:
> Ack, sorry...didn't see his request for properties.  My bad ;-).  Time to
> get some more coffee.

> Jim



> > Jim-

> > (picking nits here)
> > You don't have any properties there, those are fields. . . To modify
your
> > example:

> > Public Class Employee
> >     Private m_Salary As Integer
> >     Private m_Name As String
> >     Private m_Position As String

> > Public Sub New(ByVal basePay As Integer, ByVal name As String, _
> >     ByVal position As String)

> >     Me.Salary = basePay
> >     Me.Name = name
> >     Me.Position = position
> > End Sub

> > Public Property Salary() As Integer
> >     Get
> >         Return m_Salary
> >     End Get
> >     Set(ByVal Value As Integer)
> >         m_Salary = Value
> >     End Set
> > End Property

> > Public Property Name() As String
> >     Get
> >         Return m_Name
> >     End Get
> >     Set(ByVal Value As String)
> >         m_Name = Value
> >     End Set
> > End Property

> > Public Property Position() As String
> >     Get
> >         Return m_Position
> >     End Get
> >     Set(ByVal Value As String)
> >         m_Position = Value
> >     End Set
> > End Property

> > Public Sub Raise(ByVal amount As Integer)
> >     Me.Salary += amount
> > End Sub

> > End Class
> > --
> > Jacob Grass
> > Microsoft .NET MVP



> > > Here's a relatively simple example...

> > > HTH,

> > > Jim

> > > Public Class Employee

> > > Public Salary As Integer

> > > Public emp_Name As String

> > > Public emp_Position As String

> > > Public Sub New(ByVal basePay As Integer, ByVal name As String, ByVal
> > > position As String)

> > > Salary = basePay

> > > emp_Name = name

> > > emp_Position = position

> > > End Sub

> > > Public Sub Raise(ByVal amount As Integer)

> > > Salary += amount

> > > End Sub

> > > End Class



> > > > I am just looking for a simple example of class, function and
> > properties.

> > > > Thanks.



Tue, 13 Jul 2004 00:51:01 GMT  
 Looking for examples of class and its properties
To understand the fundamentals, you may want to pick up a book like
Understanding Objects in VB by John Smiley or an equivalent. . .

--
Jacob Grass
Microsoft .NET MVP


Quote:
> Hey thanks guys.  By the way, what do you which book is best to understand
> object, property etc.

> Thank you again



> > Ack, sorry...didn't see his request for properties.  My bad ;-).  Time
to
> > get some more coffee.

> > Jim



> > > Jim-

> > > (picking nits here)
> > > You don't have any properties there, those are fields. . . To modify
> your
> > > example:

> > > Public Class Employee
> > >     Private m_Salary As Integer
> > >     Private m_Name As String
> > >     Private m_Position As String

> > > Public Sub New(ByVal basePay As Integer, ByVal name As String, _
> > >     ByVal position As String)

> > >     Me.Salary = basePay
> > >     Me.Name = name
> > >     Me.Position = position
> > > End Sub

> > > Public Property Salary() As Integer
> > >     Get
> > >         Return m_Salary
> > >     End Get
> > >     Set(ByVal Value As Integer)
> > >         m_Salary = Value
> > >     End Set
> > > End Property

> > > Public Property Name() As String
> > >     Get
> > >         Return m_Name
> > >     End Get
> > >     Set(ByVal Value As String)
> > >         m_Name = Value
> > >     End Set
> > > End Property

> > > Public Property Position() As String
> > >     Get
> > >         Return m_Position
> > >     End Get
> > >     Set(ByVal Value As String)
> > >         m_Position = Value
> > >     End Set
> > > End Property

> > > Public Sub Raise(ByVal amount As Integer)
> > >     Me.Salary += amount
> > > End Sub

> > > End Class
> > > --
> > > Jacob Grass
> > > Microsoft .NET MVP



> > > > Here's a relatively simple example...

> > > > HTH,

> > > > Jim

> > > > Public Class Employee

> > > > Public Salary As Integer

> > > > Public emp_Name As String

> > > > Public emp_Position As String

> > > > Public Sub New(ByVal basePay As Integer, ByVal name As String, ByVal
> > > > position As String)

> > > > Salary = basePay

> > > > emp_Name = name

> > > > emp_Position = position

> > > > End Sub

> > > > Public Sub Raise(ByVal amount As Integer)

> > > > Salary += amount

> > > > End Sub

> > > > End Class



> > > > > I am just looking for a simple example of class, function and
> > > properties.

> > > > > Thanks.



Tue, 13 Jul 2004 01:10:00 GMT  
 Looking for examples of class and its properties
Jacob-

Just curious - why are you using the 'Me.' syntax inside your
subs instead of assigning to the private variables?



Quote:
> Jim-

> (picking nits here)
> You don't have any properties there, those are fields. . . To modify your
> example:

> Public Class Employee
>     Private m_Salary As Integer
>     Private m_Name As String
>     Private m_Position As String

> Public Sub New(ByVal basePay As Integer, ByVal name As String, _
>     ByVal position As String)

>     Me.Salary = basePay
>     Me.Name = name
>     Me.Position = position
> End Sub

> Public Property Salary() As Integer
>     Get
>         Return m_Salary
>     End Get
>     Set(ByVal Value As Integer)
>         m_Salary = Value
>     End Set
> End Property

> Public Property Name() As String
>     Get
>         Return m_Name
>     End Get
>     Set(ByVal Value As String)
>         m_Name = Value
>     End Set
> End Property

> Public Property Position() As String
>     Get
>         Return m_Position
>     End Get
>     Set(ByVal Value As String)
>         m_Position = Value
>     End Set
> End Property

> Public Sub Raise(ByVal amount As Integer)
>     Me.Salary += amount
> End Sub

> End Class
> --
> Jacob Grass
> Microsoft .NET MVP



> > Here's a relatively simple example...

> > HTH,

> > Jim

> > Public Class Employee

> > Public Salary As Integer

> > Public emp_Name As String

> > Public emp_Position As String

> > Public Sub New(ByVal basePay As Integer, ByVal name As String, ByVal
> > position As String)

> > Salary = basePay

> > emp_Name = name

> > emp_Position = position

> > End Sub

> > Public Sub Raise(ByVal amount As Integer)

> > Salary += amount

> > End Sub

> > End Class



> > > I am just looking for a simple example of class, function and
> properties.

> > > Thanks.



Wed, 14 Jul 2004 04:13:36 GMT  
 Looking for examples of class and its properties
Hal-

If it's a Read/Write or Write-Only property, then there may be logic or
validation in the Property Set statement.  So, I use the Me syntax to ensure
that the code is called. . . If it's a read-only property, then I just set
the private variable.

--
Jacob Grass
Microsoft .NET MVP


Quote:
> Jacob-

> Just curious - why are you using the 'Me.' syntax inside your
> subs instead of assigning to the private variables?



> > Jim-

> > (picking nits here)
> > You don't have any properties there, those are fields. . . To modify
your
> > example:

> > Public Class Employee
> >     Private m_Salary As Integer
> >     Private m_Name As String
> >     Private m_Position As String

> > Public Sub New(ByVal basePay As Integer, ByVal name As String, _
> >     ByVal position As String)

> >     Me.Salary = basePay
> >     Me.Name = name
> >     Me.Position = position
> > End Sub

> > Public Property Salary() As Integer
> >     Get
> >         Return m_Salary
> >     End Get
> >     Set(ByVal Value As Integer)
> >         m_Salary = Value
> >     End Set
> > End Property

> > Public Property Name() As String
> >     Get
> >         Return m_Name
> >     End Get
> >     Set(ByVal Value As String)
> >         m_Name = Value
> >     End Set
> > End Property

> > Public Property Position() As String
> >     Get
> >         Return m_Position
> >     End Get
> >     Set(ByVal Value As String)
> >         m_Position = Value
> >     End Set
> > End Property

> > Public Sub Raise(ByVal amount As Integer)
> >     Me.Salary += amount
> > End Sub

> > End Class
> > --
> > Jacob Grass
> > Microsoft .NET MVP



> > > Here's a relatively simple example...

> > > HTH,

> > > Jim

> > > Public Class Employee

> > > Public Salary As Integer

> > > Public emp_Name As String

> > > Public emp_Position As String

> > > Public Sub New(ByVal basePay As Integer, ByVal name As String, ByVal
> > > position As String)

> > > Salary = basePay

> > > emp_Name = name

> > > emp_Position = position

> > > End Sub

> > > Public Sub Raise(ByVal amount As Integer)

> > > Salary += amount

> > > End Sub

> > > End Class



> > > > I am just looking for a simple example of class, function and
> > properties.

> > > > Thanks.



Wed, 14 Jul 2004 04:55:11 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Looking for a very simply example for object and property

2. Looking for 3rd Party Class Library (Collection Class) for Visual Basic

3. Looking for 3rd Party Class Library (Collection Class) for Visual Basic

4. Exposing Properties collection in custom classes as many MS Classes do

5. Exposing a Properties collection in custom classes as many MS Classes do

6. Properties Property for a Custom Class

7. Can a class property have properties?

8. Can a class property have properties?

9. Proposal: alt.binaries.examples.vb4 , alt.binaries.examples.vcpp , alt.binaries.examples.java

10. Proposal: alt.binaries.examples.vb4 , alt.binaries.examples.vcpp , alt.binaries.examples.java

11. Looking for a basic example

12. Looking for Examples of ...

 

 
Powered by phpBB® Forum Software