just had a walkthrough in class and the example code our teacher gave us does not return a value. I am having alot of trouble with my current assignment because I do not see whats wrong with it. It is supposed to take two numbers entered by the user and add them together for a total with a tax rate, but it continues to return all 0’s
heres what the code looks like:
Public Class Form1
Private Sub BtnCalc_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles BtnCalc.Click
Dim amount1 As Decimal
Dim amount2 As Decimal
Dim myinvoice As Invoice
myinvoice = New Invoice
myinvoice.setlineitemamount(amount1 = Convert.ToDecimal(TextBoxAmt1.Text))
myinvoice.setlineitemamount2(amount2 = Convert.ToDecimal(TextBoxAmt2.Text))
LblTotal.Text = myinvoice.calculateinvoicetotal
MessageBox.Show(myinvoice.getlineitemamount2)
amount1 = TextBoxAmt1.Text
amount2 = TextBoxAmt2.Text
End Sub
End Class
And heres the code inside my class:
Public Class Invoice
'created new class for my invoice functions
Private lineItemamount1 As Decimal
Private lineItemamount2 As Decimal
Private lineItemamount3 As Decimal
Private lineItemamount4 As Decimal
Private invoiceDate As Date
Private customer As Integer
Private invoicetotal As Decimal
Private invoicetaxrate As Decimal = 0.1
Public Function getlineitemamount()
Return lineItemamount1
End Function
Public Sub setlineitemamount(ByVal amount1 As Decimal)
lineItemamount1 = amount1
End Sub
Public Function getlineitemamount2()
Return lineItemamount2
End Function
Public Sub setlineitemamount2(ByVal amount2 As Decimal)
lineItemamount2 = amount2
End Sub
Public Function calculateinvoicetotal()
Return (lineItemamount1 + lineItemamount2) * invoicetaxrate
End Function
End Class
Can you try this plz
And
when it’s a function you need to specify the TYPE of the returned value
but i’m not sure it’s your problem but it worths a try