How do I fix this class?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ron

    #1

    How do I fix this class?

    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.EventArg s) 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.EventArg s) 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.EventArg s) 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.Enabl ed = False
    btnSleep.Enable d = True
    lblresult.Text = output & " Your new dog is awake" 'What
    is output? Where did you declare it?
    Else
    btnWakeUp.Enabl ed = True
    btnSleep.Enable d = 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(B yVal sender As System.Object, ByVal e
    As System.EventArg s) 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

  • zacks@construction-imaging.com

    #2
    Re: How do I fix this class?

    On Apr 13, 1:45 pm, "Ron" <pts4...@yahoo. comwrote:
    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?
    Just what is wrong with it?

    Comment

    • Ron

      #3
      Re: How do I fix this class?

      On Apr 13, 2:15 pm, z...@constructi on-imaging.com wrote:
      On Apr 13, 1:45 pm, "Ron" <pts4...@yahoo. comwrote:
      >
      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?
      >
      Just what is wrong with it?
      I get these errors:

      Wakeup is not a member of...
      name output is not declared
      name output is not declared

      Comment

      • zacks@construction-imaging.com

        #4
        Re: How do I fix this class?

        On Apr 13, 2:35 pm, "Ron" <pts4...@yahoo. comwrote:
        On Apr 13, 2:15 pm, z...@constructi on-imaging.com wrote:
        >
        On Apr 13, 1:45 pm, "Ron" <pts4...@yahoo. comwrote:
        >
        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?
        >
        Just what is wrong with it?
        >
        I get these errors:
        >
        Wakeup is not a member of...
        name output is not declared
        name output is not declared
        Looks like the answers are in the comments in the code.

        Comment

        • =?Utf-8?B?RXJpY0d1QG5ld3Nncm91cHMubm9zcGFt?=

          #5
          Re: How do I fix this class?

          "Ron" wrote:
          On Apr 13, 2:15 pm, z...@constructi on-imaging.com wrote:
          On Apr 13, 1:45 pm, "Ron" <pts4...@yahoo. comwrote:
          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?
          Just what is wrong with it?
          >
          I get these errors:
          >
          Wakeup is not a member of...
          name output is not declared
          name output is not declared
          >
          >
          Your Dog class does not have a method called Wakeup(). Therefore, Wakeup is
          not a member of...

          In the sleepmode() sub of Form1 you referance output, "lblresult. Text =
          output & " Your new...", but there is no local variable named output and
          Form1 has no field or property named output. Therefore, name output is not
          declared.

          Methods (Subs and Functions) are actions your class performs.

          Properties are data. They are similar to Fields, however within the Get/Set
          you can perform some action, typically data validation.

          Comment

          • zacks@construction-imaging.com

            #6
            Re: How do I fix this class?

            On Apr 13, 3:31 pm, "Ron" <pts4...@yahoo. comwrote:
            On Apr 13, 3:02 pm, z...@constructi on-imaging.com wrote:
            >
            >
            >
            >
            >
            On Apr 13, 2:35 pm, "Ron" <pts4...@yahoo. comwrote:
            >
            On Apr 13, 2:15 pm, z...@constructi on-imaging.com wrote:
            >
            On Apr 13, 1:45 pm, "Ron" <pts4...@yahoo. comwrote:
            >
            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?
            >
            Just what is wrong with it?
            >
            I get these errors:
            >
            Wakeup is not a member of...
            name output is not declared
            name output is not declared
            >
            Looks like the answers are in the comments in the code.- Hide quoted text -
            >
            - Show quoted text -
            >
            I guess I'm not understanding how to mak wakeup a member of the class
            Add a new Sub of Function to the class whose name is wakeup. If the
            method needs to return a value, it needs to be function, otherwise it
            needs to be a sub.

            Public Sub Wakeup()

            ' do something

            End Sub

            Comment

            • Cor Ligthert [MVP]

              #7
              Re: How do I fix this class?

              Ron,

              If you make objects using classes, why dont you than not use binding, either
              by the designer either direct by code?

              Cor

              "Ron" <pts4560@yahoo. comschreef in bericht
              news:1176486354 .101890.61590@e 65g2000hsc.goog legroups.com...
              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.EventArg s) 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.EventArg s) 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.EventArg s) 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.Enabl ed = False
              btnSleep.Enable d = True
              lblresult.Text = output & " Your new dog is awake" 'What
              is output? Where did you declare it?
              Else
              btnWakeUp.Enabl ed = True
              btnSleep.Enable d = 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(B yVal sender As System.Object, ByVal e
              As System.EventArg s) 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
              >

              Comment

              • =?ISO-8859-1?Q?G=F6ran_Andersson?=

                #8
                Re: How do I fix this class?

                Cor Ligthert [MVP] wrote:
                Ron,
                >
                If you make objects using classes, why dont you than not use binding, either
                by the designer either direct by code?
                >
                Cor
                You really should try to write simpler sentences. Even I don't
                understand a thing of what you are trying to say.

                --
                Göran Andersson
                _____
                Göran Anderssons privata hemsida.

                Comment

                • Cor Ligthert [MVP]

                  #9
                  Re: How do I fix this class?

                  Goran,

                  I don't understand what you are writing: What do you mean with *Even I*.
                  What is the distinct between you and other people?

                  Cor

                  "Göran Andersson" <guffa@guffa.co mschreef in bericht
                  news:O6KBUNrfHH A.2640@TK2MSFTN GP06.phx.gbl...
                  Cor Ligthert [MVP] wrote:
                  >Ron,
                  >>
                  >If you make objects using classes, why dont you than not use binding,
                  >either by the designer either direct by code?
                  >>
                  >Cor
                  >
                  You really should try to write simpler sentences. Even I don't understand
                  a thing of what you are trying to say.
                  >
                  --
                  Göran Andersson
                  _____
                  http://www.guffa.com

                  Comment

                  • =?ISO-8859-1?Q?G=F6ran_Andersson?=

                    #10
                    Re: How do I fix this class?

                    Cor Ligthert [MVP] wrote:
                    Goran,
                    >
                    I don't understand what you are writing: What do you mean with *Even I*.
                    What is the distinct between you and other people?
                    >
                    Cor
                    >
                    "Göran Andersson" <guffa@guffa.co mschreef in bericht
                    news:O6KBUNrfHH A.2640@TK2MSFTN GP06.phx.gbl...
                    >Cor Ligthert [MVP] wrote:
                    >>Ron,
                    >>>
                    >>If you make objects using classes, why dont you than not use binding,
                    >>either by the designer either direct by code?
                    >>>
                    >>Cor
                    >You really should try to write simpler sentences. Even I don't understand
                    >a thing of what you are trying to say.
                    >>
                    >--
                    >Göran Andersson
                    >_____
                    >http://www.guffa.com
                    >
                    >
                    Yes, you obviously do understand what I am writing, you just want to
                    question it. I, on the other hand, truly did not understand what you
                    were writing in your previous post. All the words were familiar, but
                    they did not form a sentence that made sense.

                    The difference between me and the "other people", as you put it, is that
                    the "other people" are the ones that you directed your message at, and
                    they are beginners at programming. I have several years of experience
                    developing .NET applications, and many more in programming in general,
                    but not even that knowledge enabled me to understand what you were
                    trying to say.

                    --
                    Göran Andersson
                    _____
                    Göran Anderssons privata hemsida.

                    Comment

                    • Cor Ligthert [MVP]

                      #11
                      Re: How do I fix this class?

                      Goran

                      Maybe you understand it seeing this. It is only a small part.

                      \\\
                      Public Class Form1
                      Private mydog As New dog("Goran", 15)
                      Private Sub Form1_Load(ByVa l sender As System.Object, _
                      ByVal e As System.EventArg s) Handles MyBase.Load
                      txtName.DataBin dings.Add("Text ", mydog, "Name")
                      txtAge.DataBind ings.Add("Text" , mydog, "Age")
                      End Sub
                      End Class
                      ///

                      \\\
                      Public Class dog
                      Private mName As String
                      Private mAge As Integer
                      Public Sub New(ByVal name As String, ByVal age As Integer)
                      mName = name
                      mAge = age
                      End Sub
                      Public Property Name() As String
                      Get
                      Return mName
                      End Get
                      Set(ByVal value As String)
                      mName = value
                      End Set
                      End Property
                      Public Property Age() As Integer
                      Get
                      Return mAge
                      End Get
                      Set(ByVal value As Integer)
                      mAge = value
                      End Set
                      End Property
                      End Class
                      ///




                      "Göran Andersson" <guffa@guffa.co mschreef in bericht
                      news:%233I9f11f HHA.3960@TK2MSF TNGP02.phx.gbl. ..
                      Cor Ligthert [MVP] wrote:
                      >Goran,
                      >>
                      >I don't understand what you are writing: What do you mean with *Even I*.
                      >What is the distinct between you and other people?
                      >>
                      >Cor
                      >>
                      >"Göran Andersson" <guffa@guffa.co mschreef in bericht
                      >news:O6KBUNrfH HA.2640@TK2MSFT NGP06.phx.gbl.. .
                      >>Cor Ligthert [MVP] wrote:
                      >>>Ron,
                      >>>>
                      >>>If you make objects using classes, why dont you than not use binding,
                      >>>either by the designer either direct by code?
                      >>>>
                      >>>Cor
                      >>You really should try to write simpler sentences. Even I don't
                      >>understand a thing of what you are trying to say.
                      >>>
                      >>--
                      >>Göran Andersson
                      >>_____
                      >>http://www.guffa.com
                      >>
                      >>
                      >
                      Yes, you obviously do understand what I am writing, you just want to
                      question it. I, on the other hand, truly did not understand what you were
                      writing in your previous post. All the words were familiar, but they did
                      not form a sentence that made sense.
                      >
                      The difference between me and the "other people", as you put it, is that
                      the "other people" are the ones that you directed your message at, and
                      they are beginners at programming. I have several years of experience
                      developing .NET applications, and many more in programming in general, but
                      not even that knowledge enabled me to understand what you were trying to
                      say.
                      >
                      --
                      Göran Andersson
                      _____
                      http://www.guffa.com

                      Comment

                      Working...