Results 1 to 6 of 6

Thread: [2005] Help with calling functions

  1. #1

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Exclamation [2005] Help with calling functions

    I need someone to explain to me why this code constantly returns a 0 value when I attmept to run this program. I'm about at my witts end and ready to jump out of a window of a very tall building!

    HTML Code:
    Public Class FrmTravel
        'Define all variables to be used within the application
        'both locally and form wide.
        Dim decDays As Decimal
        Dim decAirfare As Decimal
        Dim decCarRentals As Decimal
        Dim sngMiles As Single
        Dim decParkingFees As Decimal
        Dim decTaxi As Decimal
        Dim decSeminar As Decimal
        Dim decLodging As Decimal
        Dim decTotalCost As Decimal
        Dim decAmountExempt As Decimal
        Dim decEndCost As Decimal
        Dim decMeals As Decimal             'price put in by user
        Dim decMealIncurred As Decimal      'price going in incurred txtbox
        Dim decMealTotal As Decimal
        Dim decMealExempt As Decimal        'going into the exempt txtbox
    
    
    
        'All constants listed.  Each value is the maximum 
        'amount that is reimbursable by the company.
        Const conMEALS As Decimal = 37D
        Const conPARKINGFEES As Decimal = 10D
        Const conTAXI As Decimal = 20D
        Const conLODGING As Decimal = 95D
        Const conPRIVATE As Decimal = 0.27D
    
        'Submit the calcMeals sub to determine the cost of food
        'and what is reimbursable.
        Function calcMeals() As Decimal
            decDays = CDec(cboDays.SelectedItem().ToString)
            decMeals = CDec(txtMeals.Text.ToString)
            decMealTotal = decMeals / decDays
            Return decMealTotal
        End Function
     
    
    
        Private Sub btnCalcCost_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalcCost.Click
            'process to begin reimbursement of money if any is due.
            If calcMeals() > conMEALS Then
                lblTotalCost.Text = FormatCurrency(CDec(calcMeals()))
            End If
    I only have two subs posted here. I am continually getting a 0 when I hit the calc button. I believe the function is being called correctly and I have it in a logical statement correctly. Just looking for some incite.

    Thanks,
    Abe
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

  2. #2
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: [2005] Help with calling functions

    Have you tried doing some messageboxes or debug statements to see what is being returned. A good place to start would be to see whether the values returned by cboDays and txtMeals are what you expect them to be.

    Hope this helps
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  3. #3

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Re: [2005] Help with calling functions

    Yeah I have been using a lbl on the form to test the inputs to the mathematics that I'm performing. Those come out completely correct. I know the problem is involved with the click event on the calc button... at least I am pretty sure, been looking at this problem for about 12 hours now and I think I'm doing more harm then good.
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

  4. #4
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: [2005] Help with calling functions

    Well put a messagebox before the return line in the function and see what value decMealTotal is and then in another messagebox in the button click function say
    messagebox.show(calcMeals().tostring)

    What do they say?
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  5. #5
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Re: [2005] Help with calling functions

    Also just as an observation....i dont think you need to do CDec(calcMeals()) in the button click event because you are already returning a decimal.
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  6. #6

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Question Re: [2005] Help with calling functions

    Now I have it working but it seems that its making me put a lot of redunant code as you can see with the section I posted below. I have class wide variables declared but yet it makes me declare them per subroutine. Good news is the math started working, although I really hate to swap one problem for another one.

    Code:
      Dim decMeals As Decimal             'price put in by user
        Dim decMealExempt As Decimal        'going into the exempt txtbox
        Dim decTotalfood As Decimal         'total cost of food on trip
    
    
        'All constants listed.  Each value is the maximum 
        'amount that is reimbursable by the company.
        Const conMEALS As Decimal = 37D
        Const conPARKINGFEES As Decimal = 10D
        Const conTAXI As Decimal = 20D
        Const conLODGING As Decimal = 95D
        Const conPRIVATE As Decimal = 0.27D
    
        'Submit the calcMeals sub to determine the cost of food
        'and what is reimbursable.
        Function calcMeals(ByVal decMealTotal As Decimal) As Decimal
            decDays = CDec(cboDays.SelectedItem().ToString)
            decMeals = CDec(txtMeals.Text.ToString)
            decMealTotal = decMeals / decDays
            Return decMealTotal
        End Function
    
     
    
    
        Private Sub btnCalcCost_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalcCost.Click
            'process to begin reimbursement of money if any is due.
            Dim decMealTotal As Decimal
            Dim decMealExempt As Decimal
            'MessageBox.Show(CDec(calcMeals(decMealTotal)).ToString)
            If (calcMeals(decMealTotal)) > conMEALS Then
                decMealExempt = 0
                lblTotalCost.Text = (CStr((calcMeals(decMealTotal))))
    
            End If
    I really have no clue at all. I wouldn't think I would have to double declare like that which only tells me that something is wrong that I can't see.
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

Posting Permissions

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



Click Here to Expand Forum to Full Width