R
Ron
I'm making this dog class and I am getting confused on properties and
methods and what they are.
How would I fix this program?
Public Class Form1
Dim mydog As New dog 'This needs to be declared at Form level
Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnCreate.Click
mydog.Name = txtname.Text
mydog.age = txtage.Text
mydog.weight = txtweight.Text
mydog.breed = txtbreed.Text
mydog.temp = txttemp.Text
mydog.color = txtcolor.Text
'etc, etc
End Sub
Private Sub btnSleep_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnSleep.Click
'Sleep should be a method, ie Sub,not a Property (what does
this mean)?
sleepmode()
End Sub
Private Sub btnWakeUp_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnWakeUp.Click
'Dim mydog As New dog
mydog.wakeup() 'wakeup should be a method, ie Sub,not a
Property
sleepmode()
End Sub
Private Sub sleepmode()
'Dim mydog As New dog
If mydog.awake Then
btnWakeUp.Enabled = False
btnSleep.Enabled = True
lblresult.Text = output & " Your new dog is awake" 'What
is output? Where did you declare it?
Else
btnWakeUp.Enabled = True
btnSleep.Enabled = False
lblresult.Text = output & " Your new dog is asleep" 'What
is output? Where did you declare it?
End If
End Sub
Private Sub btnBark_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnBark.Click
Dim mydog As New dog
mydog.bark()
End Sub
End Class
and the dog class:
Public Class dog
'Public name As String = txtname.text 'These textboxes are on the
form
Private mname As String 'Data memebers are Private, only get
exposed via properties
Public breed As String 'the class knows nothing about them
Public temp As String
Public color As String
Public weight As Int16
Public age As Int16
Public Property Name() As String
Get
Return mName
End Get
Set(ByVal value As String)
mName = value
End Set
End Property
Public ReadOnly Property sleep() As Boolean
Get
End Get
End Property
Public ReadOnly Property awake() As Boolean
Get
End Get
End Property
'Public ReadOnly Property bark() As Boolean
Public Function bark() As String
Dim retVal As String = "Woof Woof"
Return retVal
End Function
End Class
methods and what they are.
How would I fix this program?
Public Class Form1
Dim mydog As New dog 'This needs to be declared at Form level
Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnCreate.Click
mydog.Name = txtname.Text
mydog.age = txtage.Text
mydog.weight = txtweight.Text
mydog.breed = txtbreed.Text
mydog.temp = txttemp.Text
mydog.color = txtcolor.Text
'etc, etc
End Sub
Private Sub btnSleep_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnSleep.Click
'Sleep should be a method, ie Sub,not a Property (what does
this mean)?
sleepmode()
End Sub
Private Sub btnWakeUp_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnWakeUp.Click
'Dim mydog As New dog
mydog.wakeup() 'wakeup should be a method, ie Sub,not a
Property
sleepmode()
End Sub
Private Sub sleepmode()
'Dim mydog As New dog
If mydog.awake Then
btnWakeUp.Enabled = False
btnSleep.Enabled = True
lblresult.Text = output & " Your new dog is awake" 'What
is output? Where did you declare it?
Else
btnWakeUp.Enabled = True
btnSleep.Enabled = False
lblresult.Text = output & " Your new dog is asleep" 'What
is output? Where did you declare it?
End If
End Sub
Private Sub btnBark_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnBark.Click
Dim mydog As New dog
mydog.bark()
End Sub
End Class
and the dog class:
Public Class dog
'Public name As String = txtname.text 'These textboxes are on the
form
Private mname As String 'Data memebers are Private, only get
exposed via properties
Public breed As String 'the class knows nothing about them
Public temp As String
Public color As String
Public weight As Int16
Public age As Int16
Public Property Name() As String
Get
Return mName
End Get
Set(ByVal value As String)
mName = value
End Set
End Property
Public ReadOnly Property sleep() As Boolean
Get
End Get
End Property
Public ReadOnly Property awake() As Boolean
Get
End Get
End Property
'Public ReadOnly Property bark() As Boolean
Public Function bark() As String
Dim retVal As String = "Woof Woof"
Return retVal
End Function
End Class