Results 1 to 11 of 11
  1. #1
    New Lounger
    Join Date
    Apr 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Using a class (VB)

    I don't understand how to use classes very well. This form is for a kids camp sale and has several options. There are four check boxes grouped into two group boxes (Member and Non-Member) with different prices for each. These check boxes are Member Day Rate = $20, Member Month Rate = $150, Non-Member Day Rate = $25, Non-Member Month Rate = $250. They select which one they want and then enter in the number of kids into a text box. When you hit the "Calculate Total" button, it will calculate the subtotal, tax amount, and final total in three seperate labels. How would you define the class and then call it in the main form? Here's what I have so far:

    The class:
    Public Class kidscamp
    Private decday As Decimal = 20.0
    Private decmonth As Decimal = 150.0
    Private decnonday As Decimal = 25.0
    Private decnonmonth As Decimal = 250.0
    Private SubTotal As Decimal
    Private TaxAmt As Decimal
    Private Total As Decimal
    Private numKids As Decimal
    Private memberday As Decimal
    Private Const TaxRate As Decimal = 0.045D


    Sub New(ByVal Day As Decimal, ByVal month As Decimal, ByVal nonday As Decimal, ByVal nonmonth As Decimal, ByVal numkids As Decimal)

    Me.Month = month
    Me.Day = Day
    Me.NonDay = nonday
    Me.nonmonth = nonmonth
    Me.numKids = numkids




    End Sub

    #Region "Properties"
    Property Day() As Decimal
    Get
    Return decday
    End Get
    Set(ByVal Value As Decimal)
    decday = Value
    End Set
    End Property

    Property Month() As Decimal
    Get
    Return decmonth
    End Get
    Set(ByVal Value As Decimal)
    decmonth = Value
    End Set
    End Property

    Property NonDay() As Decimal
    Get
    Return decnonday
    End Get
    Set(ByVal Value As Decimal)
    decnonday = Value
    End Set
    End Property

    Property nonmonth() As Decimal
    Get
    Return nonmonth
    End Get
    Set(ByVal Value As Decimal)
    nonmonth = Value
    End Set
    End Property

    Property subtotal1() As Decimal
    Get
    Return SubTotal
    End Get
    Set(ByVal Value As Decimal)
    SubTotal = Value
    End Set
    End Property

    Property TaxAmt1() As Decimal
    Get
    Return TaxAmt
    End Get
    Set(ByVal Value As Decimal)
    TaxAmt = Value
    End Set
    End Property

    Property Total1() As Decimal
    Get
    Return Total
    End Get
    Set(ByVal Value As Decimal)
    Total = Value
    End Set
    End Property
    Property NumbKids() As Decimal
    Get
    Return numKids

    End Get
    Set(ByVal Value As Decimal)
    numKids = Value
    End Set
    End Property

    #End Region
    #Region "Methods"
    Public Overridable Function ASubtotal() As Decimal
    subtotal1 = decday * numKids
    End Function
    Public Overridable Function Ataxamt() As Decimal
    TaxAmt1 = TaxAmt * subtotal1
    End Function
    Public Overridable Function Atotal() As Decimal
    Total1 = TaxAmt1 + subtotal1
    End Function


    #End Region




    End Class


    The Kids Camp form:
    Public Class KidsCampSale
    Inherits System.Windows.Forms.Form

    Private Sub menuReturnMM_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReturnMM.Click
    Me.Close()
    End Sub

    Private Sub menuAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles menuAbout.Click
    Dim messageString As String

    messageString = "Designed and Programmed by: " _
    & ControlChars.NewLine & ControlChars.NewLine _
    & "Bryan Eccleston, Lindsay Madison, & Rocky Vaughters"

    MessageBox.Show(messageString, "Programmers", MessageBoxButtons.OK, MessageBoxIcon.Information)
    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, mnuFileClear.Click
    chkDay.Checked = False
    chkMonth.Checked = False
    chkNonDay.Checked = False
    chkNonMonth.Checked = False
    SubTotalLbl.Text = " "
    TaxAmountLbl.Text = " "
    txtKids.Text = " "
    lblTotal.Text = " "
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Const decday As Decimal = 20.0
    Const decmonth As Decimal = 150.0
    Const decnonday As Decimal = 25.0
    Const decnonmonth As Decimal = 250.0
    Dim SubTotal As Decimal
    Dim TaxAmt As Decimal
    Dim Total As Decimal
    Dim numKids As Decimal
    Const TaxRate As Decimal = 0.045D
    numKids = CDec(txtKids.Text)

    If chkDay.Checked Then

    End If





    End Sub

    Private Sub KidsCampSale_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
    End Class

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Using a class (VB)

    This looks a lot like a student assignment in a VB.Net course. Is it? Is there a reason for using an external class rather than building the functionality into the form?
    Charlotte

  3. #3
    New Lounger
    Join Date
    Apr 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using a class (VB)

    You're exactly right. This is for a software development class. And we have a huge collaborative project and one of the things we must have in our project is a class. That's why I didn't do the functionality within the form. Any suggestions? I don't understand classes at all.

  4. #4
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using a class (VB)

    You have to instantiate the class (create an instance of it) in order to use the methods and properties availbale in it.

    Basically, you have to use the following syntax:

    Dim myClass as New YourClass()

    Then you can use the methods availbale in the class like:

    Dim myInteger as Integer
    myInteger = myClass.GetSomeValue()

    See this article for more details. Also, do a Google for vb.net instantiate class site:microsoft.com for more articles.

  5. #5
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using a class (VB)

    I would think that there is a recommended VB .NET book for the course you are taking.

    If not, start with the VB .NET Step by Step book from Microsoft Press.
    A good beginner's book is the one by Paul Vick.

    Balena's book may be best overall as it is excellent for both learning and as a reference.

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Using a class (VB)

    Are you using a typed dataset? If so, you could create a class as a wrapper for the typed dataset using the inherits keyword. Then when you want to use the typed dataset, just grab an instance of the class.
    Charlotte

  7. #7
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Using a class (VB)

    Classes, in any language, are difficult to understand at first for most people, Howard. Even when a book explains them. Sometimes it takes a Q&A session to really internalize the concept. <img src=/S/thinks.gif border=0 alt=thinks width=15 height=15>
    Charlotte

  8. #8
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    Newbury, Berkshire, England
    Posts
    712
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using a class (VB)

    For anyone wanting to learn about classes, I highly recommend Joe Hummel's webcasts here:

    Joe Hummel suggests a list of design rules for Classes.

    My rough notes on lectures 2 and 3 here:

  9. #9
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using a class (VB)

    Unkamunka recommended this site to me some time back.
    It's geared to VB6, but the concepts are relevant to .NET as well - very well done IMO, with lots of info and insights. Worth a visit!

    Alan

  10. #10
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Melbourne, Victoria, Australia
    Posts
    5,016
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Using a class (VB)

    Although I haven't delved into .NET (yet), a lot of what I've read sounds very familiar in terms of the C++ I was weened on i.e. the many more aspects of the object-oriented paradigm embraced by .NET than by VB, say. So yep <img src=/S/yep.gif border=0 alt=yep width=15 height=15> the VB link I pointed to is an intro to just some aspects of the concept of classes. However when the OP says "I don't understand classes at all." I thought it mightn't be a bad place to start. I also noticed the date of the OP after posting a reply, so it probably doesn't matter any more. <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    Alan

  11. #11
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Using a class (VB)

    One big difference is that .Net *is* object oriented, complete with inheritance, so classes in .Net go way beyond what they could do in VB6.
    Charlotte

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •