|
-
Oct 16th, 2008, 05:10 PM
#1
Thread Starter
New Member
hw problem functions and sub procedures
Code:
Public Class Frmbilling
Dim itemamount, tax, subtotal, total As Double
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
getitem()
calctotal()
calctax()
calcsubtotal()
displaytotal()
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
Rdbcappuccino.Checked = False
RdbEspresso.Checked = False
rdbLatte.Checked = False
RdbIcedLatte.Checked = False
RdbIcedCappuccino.Checked = False
TxtQuantity.Clear()
TxtItemAmount.Clear()
chkTax.Checked = False
TxtQuantity.Focus()
End Sub
Private Sub btnNewOrder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewOrder.Click
Rdbcappuccino.Checked = False
RdbEspresso.Checked = False
rdbLatte.Checked = False
RdbIcedLatte.Checked = False
RdbIcedCappuccino.Checked = False
TxtQuantity.Clear()
TxtItemAmount.Clear()
chkTax.Checked = False
TxtQuantity.Focus()
Txtsubtotal.Clear()
TxtItemAmount.Clear()
txtTax.Clear()
TxtTotal.Clear()
'CalcGrandTotal()
'CalcAddOneCustomer()
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
End
End Sub
Sub getitem()
Dim quantity As Double
TxtQuantity.Text = quantity
If Rdbcappuccino.Checked Then
TxtItemAmount.Text = 2 * quantity
ElseIf RdbEspresso.Checked Then
TxtItemAmount.Text = 2.25 * quantity
ElseIf rdbLatte.Checked Then
TxtItemAmount.Text = 1.75 * quantity
ElseIf RdbIcedLatte.Checked Then
TxtItemAmount.Text = 2.5 * quantity
ElseIf RdbIcedCappuccino.Checked Then
TxtItemAmount.Text = 2.5 * quantity
End If
End Sub
Private Function calcsubtotal()
Dim sub1 As Double
subtotal = sub1 + itemamount
Return (subtotal)
End Function
Private Function calctax()
Dim subtotal As Double
If chkTax.Checked Then
tax = subtotal * 0.08
End If
Return (tax)
End Function
Private Function calctotal()
total = subtotal + tax
Return (total)
End Function
Sub displaytotal()
Txtsubtotal.Text = subtotal
txtTax.Text = tax
TxtTotal.Text = total
End Sub
End Class
i dont know exactly where to go from here, i am getting 0 in all my textboxes, i dont really understand functions and subprocedures and byval and by ref, so can someone help me to figure out what i am doing wrong.
this is a site with the same project on it heres the link if it helps you to understand what i need to accomplish
http://www.shsu.edu/~mis_gab/MIS%202...Chapter8HW.pdf
thanks-
-
Oct 16th, 2008, 05:21 PM
#2
Re: hw problem functions and sub procedures
vb Code:
TxtQuantity.Text = quantity
???
shouldn't that be:
vb Code:
quantity = TxtQuantity.Text
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 16th, 2008, 05:32 PM
#3
Re: hw problem functions and sub procedures
first of all, those functions should have a return datatype. i.e.
vb Code:
Private Function calctotal() as double
the function calls in btnCalculate_Click are incorrectly written and need to be in the right order
vb Code:
itemamount = getitem()
tax = calctax()
subtotal = calcsubtotal()
total = calctotal()
displaytotal()
getItem should be a function with a return value
vb Code:
Function getitem()as string
Dim quantity As Double
quantity = TxtQuantity.Text
If Rdbcappuccino.Checked Then
TxtItemAmount.Text = 2 * quantity
ElseIf RdbEspresso.Checked Then
TxtItemAmount.Text = 2.25 * quantity
ElseIf rdbLatte.Checked Then
TxtItemAmount.Text = 1.75 * quantity
ElseIf RdbIcedLatte.Checked Then
TxtItemAmount.Text = 2.5 * quantity
ElseIf RdbIcedCappuccino.Checked Then
TxtItemAmount.Text = 2.5 * quantity
End If
return TxtItemAmount.Text
End Sub
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 16th, 2008, 06:11 PM
#4
Thread Starter
New Member
Re: hw problem functions and sub procedures
thanks for the help
the quantity =
helped alot, but know when i run my program and hit the clear button it says i cant convert from string to double,
and the subprocedure and tax and total are all still at 0
-
Oct 16th, 2008, 06:14 PM
#5
Re: hw problem functions and sub procedures
change:
vb Code:
Function getitem()as string
to:
vb Code:
Function getitem()as double
&
vb Code:
return TxtItemAmount.Text
to:
vb Code:
return cdbl(TxtItemAmount.Text)
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 16th, 2008, 06:28 PM
#6
Re: hw problem functions and sub procedures
the converting from a string to a double problem is because the string must be a number for you to convert it to a double. if the textbox is empty, it isn't a number and can't be converted to a number. one way round this is to use double tryparse:
vb Code:
Function getitem() As Double
Dim quantity As Double
If Double.TryParse(TxtQuantity.Text, quantity) Then
If Rdbcappuccino.Checked Then
TxtItemAmount.Text = 2 * quantity
ElseIf RdbEspresso.Checked Then
TxtItemAmount.Text = 2.25 * quantity
ElseIf rdbLatte.Checked Then
TxtItemAmount.Text = 1.75 * quantity
ElseIf RdbIcedLatte.Checked Then
TxtItemAmount.Text = 2.5 * quantity
ElseIf RdbIcedCappuccino.Checked Then
TxtItemAmount.Text = 2.5 * quantity
End If
Return CDbl(TxtItemAmount.Text)
else
return 0
End If
End Function
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|