Welcome to Dream.In.Code
Getting VB.NET Help is Easy!

Join 136,415 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,408 people online right now. Registration is fast and FREE... Join Now!




Getting incorrect output

 
Reply to this topicStart new topic

Getting incorrect output, Need help with functions and procedures

milton7888
15 Oct, 2008 - 07:57 AM
Post #1

New D.I.C Head
*

Joined: 11 Sep, 2008
Posts: 18

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%20291-old.../Chapter8HW.pdf

thanks-

This post has been edited by jayman9: 15 Oct, 2008 - 01:36 PM
User is offlineProfile CardPM
+Quote Post

Jayman
RE: Getting Incorrect Output
15 Oct, 2008 - 01:36 PM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,939



Thanked: 42 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
Topic renamed to be more descriptive of the problem.
User is online!Profile CardPM
+Quote Post

dbasnett
RE: Getting Incorrect Output
15 Oct, 2008 - 02:05 PM
Post #3

D.I.C Head
**

Joined: 1 Oct, 2008
Posts: 161



Thanked: 5 times
My Contributions
example

this
Sub getitem()
Dim quantity As Double
TxtQuantity.Text = quantity

EVERY time getitem is called quantity will be new. that means 0.

try it like this

Dim quantity As Double
Sub getitem()
TxtQuantity.Text = quantity

User is online!Profile CardPM
+Quote Post

milton7888
RE: Getting Incorrect Output
16 Oct, 2008 - 02:14 PM
Post #4

New D.I.C Head
*

Joined: 11 Sep, 2008
Posts: 18

i dont really understand, r u sayign to make it a global variable?....i think i am just not passing things right, like i dont have byval or byref for my funstions
User is offlineProfile CardPM
+Quote Post

AdamSpeight2008
RE: Getting Incorrect Output
16 Oct, 2008 - 02:34 PM
Post #5

LINQ D.I.C.
Group Icon

Joined: 29 May, 2008
Posts: 799



Thanked: 51 times
Dream Kudos: 2175
My Contributions
QUOTE(milton7888 @ 16 Oct, 2008 - 11:14 PM) *

i dont really understand, r u sayign to make it a global variable?....i think i am just not passing things right, like i dont have byval or byref for my funstions


They are say this, when you define a variable without assigning it a value, will be a default value usually 0 (Zero) or Nothing
eg.
CODE

Dim quantity as Double

So at this point quantity = 0.0

CODE

Dim quantity as double
Dim q As Double
If Double.TryParse(TxtQuantity.Text, q) = False Then
Throw New Exception("Quantity entered is not a number.")
End If


I hope this helps.
User is offlineProfile CardPM
+Quote Post

Damage
RE: Getting Incorrect Output
16 Oct, 2008 - 02:44 PM
Post #6

D.I.C Addict
Group Icon

Joined: 5 Jun, 2008
Posts: 738



Thanked: 7 times
Dream Kudos: 75
My Contributions
what he's saying, you are creating quantity(and not giving it a value) every time you call getItem().
so you either need to increase the scope of quantity and define it outside of the sub

or you need to pass a value to getItem and assign it to quantity

CODE


public sub getItem(byval tempQaunt as double)
Dim quantity As Double = tempquant
end sub

getItem(12)



your doing something similar with all your methods

and functions should have the return type in the signature

CODE

public function blah() as string
dim bla as string
return bla
end function


If you use byVal the value of the original variable will not be changed whereas if you use byRef it will

ie

CODE


dim test1,test2 as integer

test1 =2
test2 =4
msgbox test1 &" "& test2

test(test1,test2)

public sub test(byval test1 as integer, byref test2 as integer)
test1 =3
test2 =5
end sub

msgbox test1 &" "&test2



if i've done it correctly the first message box should show 2 4
and the second message box should show 2 5

someone correct me if i'm wrong










ahh dude snuck in while i was posting tongue.gif
User is offlineProfile CardPM
+Quote Post

milton7888
RE: Getting Incorrect Output
16 Oct, 2008 - 02:45 PM
Post #7

New D.I.C Head
*

Joined: 11 Sep, 2008
Posts: 18

ok, i understand this now, so i need to seclare quantity, but isnt that what im going in my getinputs procedure and it sayd .........=quantity?

This post has been edited by milton7888: 16 Oct, 2008 - 02:52 PM
User is offlineProfile CardPM
+Quote Post

milton7888
RE: Getting Incorrect Output
16 Oct, 2008 - 02:56 PM
Post #8

New D.I.C Head
*

Joined: 11 Sep, 2008
Posts: 18

QUOTE(milton7888 @ 16 Oct, 2008 - 03:45 PM) *

ok, i understand this now, so i need to seclare quantity, but isnt that what im going in my getinputs procedure and it sayd .........=quantity?


can u give me and example of what u r saying usigng a part of my code, like what values am i gonna want to pass, i know that i want to use byref, but i dont know what to use it for

User is offlineProfile CardPM
+Quote Post

milton7888
RE: Getting Incorrect Output
16 Oct, 2008 - 03:19 PM
Post #9

New D.I.C Head
*

Joined: 11 Sep, 2008
Posts: 18

i fixed part of it, but i still get 0 for alot of values?...ne suggestions


<code>
Public Class Frmbilling
Dim itemamount, tax, subtotal, total, quantity As Double

Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click


getitem()

calctotal()
calctax()
calcsubtotal()
displaytotal()
TxtQuantity.Text = quantity


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 String

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

End Sub

Private Function calcsubtotal() As Double
Dim sub1 As Double

subtotal = sub1 + itemamount

Return (subtotal)



End Function

Private Function calctax() As Double


Dim subtotal As Double
If chkTax.Checked Then
tax = subtotal * 0.08



End If

Return (tax)

End Function

Private Function calctotal() As Double


total = subtotal + tax

Return total

End Function
Sub displaytotal()

Txtsubtotal.Text = subtotal
txtTax.Text = tax
TxtTotal.Text = total


End Sub
End Class
</code>
User is offlineProfile CardPM
+Quote Post

Damage
RE: Getting Incorrect Output
16 Oct, 2008 - 03:52 PM
Post #10

D.I.C Addict
Group Icon

Joined: 5 Jun, 2008
Posts: 738



Thanked: 7 times
Dream Kudos: 75
My Contributions
the one thing i can see is this

CODE

Private Function calcsubtotal() As Double
Dim sub1 As Double

subtotal = sub1 + itemamount

Return (subtotal)



End Function


sub1 is 0(because you haven't assigned it a value yet), not a problem but itemamount is also 0 for the same reason. so 0 + 0 is always gonna give you

0
User is offlineProfile CardPM
+Quote Post

Damage
RE: Getting Incorrect Output
16 Oct, 2008 - 04:26 PM
Post #11

D.I.C Addict
Group Icon

Joined: 5 Jun, 2008
Posts: 738



Thanked: 7 times
Dream Kudos: 75
My Contributions
same thing here

CODE

Private Function calctax() As Double


Dim subtotal As Double         <--------------------0
If chkTax.Checked Then
tax = subtotal * 0.08             <------------0* by anything is always gonna be 0



End If

Return (tax)

End Function

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 12:43PM

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month