To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
MSDN Subscribers: Download the VS 2010 Release Candidate
MSDN Subscribers: Download the VS 2010 Release Candidate
Sell Your Code and Make Money?
Creating your own Tetris game using VB.NET
Article :: Improving Software Economics, Part 4 of 7: Top 10 Principles of Iterative Software Management



Go Back   VBForums > Visual Basic > Visual Basic .NET

Reply Post New Thread
 
Thread Tools Search this Thread Display Modes
Old Mar 28th, 2007, 11:15 AM   #1
Abrium
Addicted Member
 
Abrium's Avatar
 
Join Date: Feb 07
Location: The Great State of Texas
Posts: 160
Abrium is an unknown quantity at this point (<10)
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.
Abrium is offline   Reply With Quote
Old Mar 28th, 2007, 11:23 AM   #2
Kimmy4
Fanatic Member
 
Join Date: Aug 06
Posts: 734
Kimmy4 is on a distinguished road (20+)
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
Kimmy4 is offline   Reply With Quote
Old Mar 28th, 2007, 11:59 AM   #3
Abrium
Addicted Member
 
Abrium's Avatar
 
Join Date: Feb 07
Location: The Great State of Texas
Posts: 160
Abrium is an unknown quantity at this point (<10)
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.
Abrium is offline   Reply With Quote
Old Mar 28th, 2007, 12:14 PM   #4
Kimmy4
Fanatic Member
 
Join Date: Aug 06
Posts: 734
Kimmy4 is on a distinguished road (20+)
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
Kimmy4 is offline   Reply With Quote
Old Mar 28th, 2007, 12:16 PM   #5
Kimmy4
Fanatic Member
 
Join Date: Aug 06
Posts: 734
Kimmy4 is on a distinguished road (20+)
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
Kimmy4 is offline   Reply With Quote
Old Mar 28th, 2007, 12:56 PM   #6
Abrium
Addicted Member
 
Abrium's Avatar
 
Join Date: Feb 07
Location: The Great State of Texas
Posts: 160
Abrium is an unknown quantity at this point (<10)
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.
Abrium is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Visual Basic .NET


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 11:40 AM.




To view more projects, click here

Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.