Class/Constructor Question - RESOLVED
So I am new to VB, and I am struggling through my final project for my VB course.
My question is this:
I have a main form with the main controls, text fields, checkboxes, etc.
I also have a class that I designed (as per the requirements).
I am going off of what they have in the text book, and most of the things I have found are too general. I *think* I have the main values linked ok (from the class to the form), but I am not sure how to handle the checkbox and radio button options.
Basically the user could check 0 - 3 check boxes (each adding cost to a total), as well as any one of 3 radio buttons that will add a different amount to the total. In the example in my text, there is a checkbox; they put it into a subclass and it just called that subclass when the class called.
So do I have to have a different subclass for every possible combination of radio buttons and check boxes? Or can I just work it into the main class in some constructors and call that. If so, all the constructors I add are just called new, how do I call different ones (if that is even something you can do)?
I think this is probably a fairly simple VB program, so if someone could take a look and show/tell me how to implement the input of the checkboxes and radio buttons (currently constants), and/or if this looks OK so far, it would be much appreciated.
As I said, I don't know what the heck I am doing, and right now it is returning 0 for all of the values.
Thanks!
My main form code:
My class code:
So I am new to VB, and I am struggling through my final project for my VB course.
My question is this:
I have a main form with the main controls, text fields, checkboxes, etc.
I also have a class that I designed (as per the requirements).
I am going off of what they have in the text book, and most of the things I have found are too general. I *think* I have the main values linked ok (from the class to the form), but I am not sure how to handle the checkbox and radio button options.
Basically the user could check 0 - 3 check boxes (each adding cost to a total), as well as any one of 3 radio buttons that will add a different amount to the total. In the example in my text, there is a checkbox; they put it into a subclass and it just called that subclass when the class called.
So do I have to have a different subclass for every possible combination of radio buttons and check boxes? Or can I just work it into the main class in some constructors and call that. If so, all the constructors I add are just called new, how do I call different ones (if that is even something you can do)?
I think this is probably a fairly simple VB program, so if someone could take a look and show/tell me how to implement the input of the checkboxes and radio buttons (currently constants), and/or if this looks OK so far, it would be much appreciated.
As I said, I don't know what the heck I am doing, and right now it is returning 0 for all of the values.
Thanks!
My main form code:
VB.NET:
Try
With Me
apurchaseobject = New purchaseobject(Decimal.Parse(.tbxCarSales.Text), Decimal.Parse(.tbxTradein.Text))
'Calculate and format the result
.tbxSubtotal.Text = apurchaseobject.ammountduedecimal.ToString("C")
.tbxTotal.Text = apurchaseobject.totaldecimal.ToString("C")
.tbxTax.Text = apurchaseobject.taxdecimal.ToString("C")
.tbxAmmDue.Text = apurchaseobject.ammountduedecimal.ToString("C")
.tbxAccess.Text = apurchaseobject.accessoriesdecimal.ToString("C")
End With
Catch ex As Exception
MessageBox.Show("enter numeric data.", "VBAuto", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Try
VB.NET:
Public Class purchaseobject
Public subtotaldecimal As Decimal
Public totaldecimal As Decimal
Public ammountduedecimal As Decimal
Public salepricedecimal As Decimal
Public allowancedecimal As Decimal
Public accessoriesdecimal As Decimal
Public finishdecimal As Decimal
Public accessfinishtotal As Decimal
Public taxdecimal As Decimal
Private Const STEREO_PRICE_Decimal As Decimal = 425.76D
Private Const LEATHER_PRICE_Decimal As Decimal = 987.41D
Private Const NAVIGATION_PRICE_Decimal As Decimal = 1741.23D
Private Const STANDARD_PRICE_Decimal As Decimal = 0D
Private Const PEARL_PRICE_Decimal As Decimal = 345.72D
Private Const DETAIL_PRICE_Decimal As Decimal = 599.99D
Private Const TAX_RATE_Decimal As Decimal = 0.08D
Sub New(ByVal carsaleprice As Decimal, ByVal tradeinallowance As Decimal)
'Assign property values
With Me
.carsaleprice = carsaleprice
.tradeinallowance = tradeinallowance
End With
GetAccessoriestotal()
Getsubtotal()
GetTax()
GetTotal()
GetDue()
End Sub
Sub New()
End Sub
Public Property carsaleprice() As Decimal
Get
Return salepricedecimal
End Get
Set(ByVal value As Decimal)
End Set
End Property
Public Property accessoriesandfinish() As Decimal
Get
Return accessfinishtotal
End Get
Set(ByVal value As Decimal)
End Set
End Property
Public Property subtotal() As Decimal
Get
Return subtotaldecimal
End Get
Set(ByVal value As Decimal)
End Set
End Property
Public Property salestax() As Decimal
Get
Return taxdecimal
End Get
Set(ByVal value As Decimal)
End Set
End Property
Public Property total() As Decimal
Get
Return totaldecimal
End Get
Set(ByVal value As Decimal)
End Set
End Property
Public Property tradeinallowance() As Decimal
Get
Return allowancedecimal
End Get
Set(ByVal value As Decimal)
End Set
End Property
Public Property amountdue() As Decimal
Get
Return ammountduedecimal
End Get
Set(ByVal value As Decimal)
End Set
End Property
Public Property Stereo() As Integer
Get
Return STEREO_PRICE_Decimal
End Get
Set(ByVal value As Integer)
End Set
End Property
Public Property Leather() As Integer
Get
Return LEATHER_PRICE_Decimal
End Get
Set(ByVal value As Integer)
End Set
End Property
Public Property Navigation() As Integer
Get
Return NAVIGATION_PRICE_Decimal
End Get
Set(ByVal value As Integer)
End Set
End Property
''' <value></value>
Public Property Standard() As Integer
Get
Return STANDARD_PRICE_Decimal
End Get
Set(ByVal value As Integer)
End Set
End Property
Public Property Pearlized() As Integer
Get
Return PEARL_PRICE_Decimal
End Get
Set(ByVal value As Integer)
End Set
End Property
Public Property Detailing() As Integer
Get
Return DETAIL_PRICE_Decimal
End Get
Set(ByVal value As Integer)
End Set
End Property
Public Sub GetAccessoriestotal()
accessfinishtotal = finishdecimal + accessoriesdecimal
End Sub
Public Sub Getsubtotal()
subtotaldecimal = accessfinishtotal + salepricedecimal
End Sub
Public Sub GetTax()
taxdecimal = subtotaldecimal * TAX_RATE_Decimal
End Sub
Public Sub GetTotal()
totaldecimal = subtotaldecimal + taxdecimal
End Sub
Public Sub GetDue()
ammountduedecimal = totaldecimal - allowancedecimal
End Sub
End Class
Last edited: