Can you tell me where Im wrong..

Hospital Charges Form

  • (2 Pages)
  • +
  • 1
  • 2

22 Replies - 2041 Views - Last Post: 02 November 2009 - 06:25 PM Rate Topic: -----

#1 dee_dee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 15-October 09

Can you tell me where Im wrong..

Posted 17 October 2009 - 08:37 AM

Ok I have got it up and running it does ALMOST everything it should. My only problems are very small and probably an easy fix so can you tell me what I put wrong, well the problem is when I calculate instead of it giving me 350 for 1 day of stay it's giving me 3500, Also when I put in a negative to test it out it gives me my message box BUT after i clear the message box it still gives me a negative total...why? Here is my code

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

		Const decStay_Rate As Decimal = 350D	'Hospital charges per day


		'Declare variables for the following calculations
		Dim decStay As Decimal	 'Number of days stayed at Hospital
		Dim decMeds As Decimal		  'Medical Charges
		Dim decSurgery As Decimal	   'Surgery Charges
		Dim decLabFees As Decimal	   'Lab fees
		Dim decRehab As Decimal		 'Physical Rehab Fees
		Dim decTotalCost As Decimal	 'Total cost of stay
		Dim decMiscCharges As Decimal   'total of all misc charges


		'Copy the scores into the variables

		decMeds = CDec(CSng(txtMeds.Text))
		decSurgery = CDec(CSng(txtSurgery.Text))
		decLabFees = CDec(CSng(txtLabFees.Text))
		decRehab = CDec(CSng(txtRehab.Text))
		decStay = CDec(CSng(decStay_Rate * CSng(txtStay.Text)))

		decMiscCharges = CDec(decMeds.ToString() = decSurgery.ToString() + decLabFees.ToString() + decRehab.ToString())

		decTotalCost = CDec((decStay.ToString() + decMiscCharges.ToString()))

		If CSng(txtStay.Text) <= -1 Then
			MessageBox.Show("Number of days must be positve, please try again.", "Invalide entry")
		End If

		If CSng(txtMeds.Text) <= -1 Then
			MessageBox.Show("Number of days must be positve, please try again.", "Invalide entry")
		End If

		If CSng(txtSurgery.Text) <= -1 Then
			MessageBox.Show("Number of days must be positve, please try again.", "Invalide entry")
		End If

		If CSng(txtLabFees.Text) <= -1 Then
			MessageBox.Show("Number of days must be positve, please try again.", "Invalide entry")
		End If

		If CSng(txtRehab.Text) <= -1 Then
			MessageBox.Show("Number of days must be positve, please try again.", "Invalide entry")

		End If

		lblTotalCost.Text = decTotalCost.ToString()



	End Sub


Is This A Good Question/Topic? 0
  • +

Replies To: Can you tell me where Im wrong..

#2 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 428
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: Can you tell me where Im wrong..

Posted 17 October 2009 - 09:22 AM

The first problem is because of this:

decTotalCost = CDec((decStay.ToString() + decMiscCharges.ToString()))

You are adding strings together instead of the actual numbers. So if decStay = 350 and decMiscCharges = 0, you are adding: "350" + "0" which equals "3500" because it's string. So remove the .ToString() methods and just add decimals together.

The second problem occurs because you don't exit the method after showing the messagebox so it will simply run to the end of the method even though it displays the messagebox. So after each MessageBox.Show(), write Return or End Sub to exit the method after messagebox is shown.
Was This Post Helpful? 0
  • +
  • -

#3 dzone41  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 46
  • View blog
  • Posts: 216
  • Joined: 21-August 09

Re: Can you tell me where Im wrong..

Posted 17 October 2009 - 09:28 AM


		decMiscCharges = CDec(decMeds.ToString() = decSurgery.ToString() + decLabFees.ToString() + decRehab.ToString())

		decTotalCost = CDec((decStay.ToString() + decMiscCharges.ToString()))




your changing perfectly good decimal values to strings and doing mathmatical calculations, then turning them back into decimal values
Try:

decMiscCharges = (decMeds + decSurgery + decLabFees + decRehab)



The ToString() should be used only when you need a string value

Also:

 Const decStay_Rate As Decimal = 350D	



Not sure what the "D" is on there for. In the tutorials section, there is a tutorial on debugging.
Good luck





oops.....I see someone else has already responded

This post has been edited by dzone41: 17 October 2009 - 09:30 AM

Was This Post Helpful? 0
  • +
  • -

#4 sharpy  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 35
  • View blog
  • Posts: 394
  • Joined: 02-June 07

Re: Can you tell me where Im wrong..

Posted 17 October 2009 - 09:45 AM

Hi

instead of telling people they have entered a negative value you can stop them entering a negative value to your text boxes, Have a look at this snippet.

http://www.dreaminco...snippet1453.htm

Hope this helps
Was This Post Helpful? 0
  • +
  • -

#5 dee_dee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 15-October 09

Re: Can you tell me where Im wrong..

Posted 17 October 2009 - 11:04 AM

Thanks a ton!!! Decimal issue fixed like a charm!
Was This Post Helpful? 0
  • +
  • -

#6 dee_dee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 15-October 09

Re: Can you tell me where Im wrong..

Posted 29 October 2009 - 08:22 AM

OK I did this project and it worked great however now I need to edit it and add functions. As much as I would LOVE for the answer just to be given to me I wont learn that way so can someone give me a better explination on functions and how to incorporate them into this code (see above) The book SUCKS on explaining!!!
Was This Post Helpful? 0
  • +
  • -

#7 higgsch  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 109
  • Joined: 26-October 09

Re: Can you tell me where Im wrong..

Posted 29 October 2009 - 08:35 AM

The error with the messageboxs occur when you said:
If CSng(txtStay.Text) <= -1 Then
			MessageBox.Show("Number of days must be positve, please try again.", "Invalide entry")
		End If

		If CSng(txtMeds.Text) <= -1 Then
			MessageBox.Show("Number of days must be positve, please try again.", "Invalide entry")
		End If

		If CSng(txtSurgery.Text) <= -1 Then
			MessageBox.Show("Number of days must be positve, please try again.", "Invalide entry")
		End If

		If CSng(txtLabFees.Text) <= -1 Then
			MessageBox.Show("Number of days must be positve, please try again.", "Invalide entry")
		End If

		If CSng(txtRehab.Text) <= -1 Then
			MessageBox.Show("Number of days must be positve, please try again.", "Invalide entry")

		End If

		lblTotalCost.Text = decTotalCost.ToString()

Try using elseif statements on your CSng(...) <= -1. Except on the first one, leave that as an if, then after your:
If CSng(txtRehab.Text) <= -1 Then
			MessageBox.Show("Number of days must be positve, please try again.", "Invalide entry")

		End If


Use an Else statement.

This tells the computer not to do (lblTotalCost.text = decTotalCost.ToString()) if any of the if or elseif statements are true.

If you need more info, let me know I can explain more if you want.
Was This Post Helpful? 0
  • +
  • -

#8 dee_dee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 15-October 09

Re: Can you tell me where Im wrong..

Posted 29 October 2009 - 08:43 AM

higgsch, I got that all figured out my thing is now using functions on this I have to add them but the book thats required for the class sucks big time and is very vague in explaining how to. I need to know more about funcitons so I add them to that code. I tried using the samples to help me figure it out but they don't help either! blah!
Was This Post Helpful? 0
  • +
  • -

#9 higgsch  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 109
  • Joined: 26-October 09

Re: Can you tell me where Im wrong..

Posted 29 October 2009 - 09:01 AM

in a nutshell:
functions are used by "calling"
you call a function by stating the function name (like: AddText()) making sure to have the "()"
to create a function you have to set it up as:
Private Shared Function AddText()

End Function


Then you need to decide if the function needs any variables from the program if it does then you need to input the variable like this:
Private Shared Function AddText(ByVal strVariable1 as String, ByVal intPeople as integer)

End Function


Then you write whatever you need the function to do.
Private Shared Function AddText(ByVal strVariable1 as String, ByVal intPeople as integer)

lblResult.text = strVariable1 & " " & intPeople

End Function



Then you need to go back to the calling function (where you put the: AddText()), and put the variables you listed after the ByVal's into the () in AddText()
Like this:
Private Sub btnHitMe.Click()

...
AddText(strVariable, intPeople)

...
End Sub


Then it should work!



That's Functions in a nutshell!
Was This Post Helpful? 0
  • +
  • -

#10 dee_dee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 15-October 09

Re: Can you tell me where Im wrong..

Posted 29 October 2009 - 09:20 AM

Thanks!!! When I get home from work I am gonna see how well my brain grasped that lol you explained it really well. I will post again if I have issues....
Was This Post Helpful? 0
  • +
  • -

#11 dee_dee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 15-October 09

Re: Can you tell me where Im wrong..

Posted 29 October 2009 - 04:05 PM

Oh here we go I put in the functions but, still have errors. Here is what I have

	Const decStay_Rate As Decimal = 350   'Hospital charges per day

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

		''Declare variables for the following calculations
		Dim decStay As Decimal	 'Number of days stayed at Hospital
		Dim decMeds As Decimal		  'Medical Charges
		Dim decSurgery As Decimal	   'Surgery Charges
		Dim decLabFees As Decimal	   'Lab fees
		Dim decRehab As Decimal		 'Physical Rehab Fees
		Dim decTotalCost As Decimal	 'Total cost of stay
		Dim decMiscCharges As Decimal   'total of all misc charges


		'Copy the scores into the variables

		decMeds = CDec(CSng(txtMeds.Text))
		decSurgery = CDec(CSng(txtSurgery.Text))
		decLabFees = CDec(CSng(txtLabFees.Text))
		decRehab = CDec(CSng(txtRehab.Text))
		decStay = CDec(CSng(decStay_Rate * CSng(txtStay.Text)))
		decMiscCharges = (decMeds + decSurgery + decLabFees + decRehab)
		decTotalCost = CDec((decStay + decMiscCharges))


	End Sub
	Function CalcMiscCharges(ByVal decMeds As Decimal, ByVal decSurgery As Decimal, ByVal decLabFees As Decimal, ByVal decRehab As Decimal) As Decimal

		'this function calculates the misc charges for a hospital stay.
		Return Convert.ToDecimal(decMeds + decSurgery + decLabFees + decRehab)
	End Function

	Function CalcStay(ByVal decStay_Rate)
		'this function calculates the cost of a hospital stay.
		Return Convert.ToDecimal(decStay_Rate)
	End Function

	Function CalcTotalCost(ByVal decStay_Rate As Decimal, ByVal decMeds As Decimal, ByVal decSurgery As Decimal, ByVal decRehab As Decimal, ByVal decLabFees As Decimal) As Decimal
		'this function calculates the total cost.
		Return Convert.ToDecimal(decStay_Rate, decMeds, decSurgery, decRehab, decLabFees)
	End Function

	Private Sub lblMessage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblMessage.Click
		'Display the total cost.
		lblTotalCost.Text = FormatNumber(lblTotalCost.Text)

	End Sub


End Class



Im getting string errors and an Overload resolution failed because no accessible 'ToDecimal' accepts this number of arguments. Where did I mess up??
Was This Post Helpful? 0
  • +
  • -

#12 dee_dee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 15-October 09

Re: Can you tell me where Im wrong..

Posted 29 October 2009 - 04:25 PM

YAY I got rid of the overload error I changed this

Function CalcTotalCost(ByVal decStay_Rate As Decimal, ByVal decMeds As Decimal, ByVal decSurgery As Decimal, ByVal decRehab As Decimal, ByVal decLabFees As Decimal) As Decimal
		'this function calculates the total cost.
		Return Convert.ToDecimal(decStay_Rate, decMeds, decSurgery, decRehab, decLabFees)
	End Function



to this
Function CalcTotalCost(ByVal decStay_Rate As Decimal, ByVal decMeds As Decimal, ByVal decSurgery As Decimal, ByVal decRehab As Decimal, ByVal decLabFees As Decimal) As Decimal
		'this function calculates the total cost.
		Return Convert.ToDecimal(decStay_Rate, decMiscCharges)
	End Function


still have other errors tho :crazy:

This post has been edited by dee_dee: 29 October 2009 - 04:26 PM

Was This Post Helpful? 0
  • +
  • -

#13 higgsch  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 109
  • Joined: 26-October 09

Re: Can you tell me where Im wrong..

Posted 29 October 2009 - 04:25 PM

One problem is: you aren't calling your CalcMiscCharges, CalcStay, or CalcTotalCost functions.
Also the function ToDecimal() can only convert 1 variable at a time.
You would have to run the ToDecimal() function multiple times (setting the result as a variable and sending it back to the program.
Additionally, your button_click event doesn't show to the label.
Add:
lblResult.text = "Whatever you want the text to show"

to your button_click event to show this.
Also, you can set a variable to it's value in the dim statement.
If you do this for your set of variables it will make your code easier to work with.
like this:
Dim decStay as Decimal = CDec(CSng(decStay_Rate * CSng(txtStay.Text)))

for all of your variables.

This post has been edited by higgsch: 29 October 2009 - 04:32 PM

Was This Post Helpful? 0
  • +
  • -

#14 dee_dee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 15-October 09

Re: Can you tell me where Im wrong..

Posted 29 October 2009 - 04:28 PM

So I have to do the ToDecimal for each? So it would be a seperat function for each correct?? How do I go about calling the funciton...I know probably a very dumb question feel free to laugh! Thanks for the help and bearing with me!
Was This Post Helpful? 0
  • +
  • -

#15 dee_dee  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 15-October 09

Re: Can you tell me where Im wrong..

Posted 29 October 2009 - 04:34 PM

Ok this is with the last edits...

Public Class Form1

	Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
		'Close the application
		Me.Close()

	End Sub

	Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click

		'this function resets the form
		txtStay.Clear()
		txtMeds.Clear()
		txtSurgery.Clear()
		txtLabFees.Clear()
		txtRehab.Clear()
		lblTotalCost.ResetText()

	End Sub

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

	End Sub
	Const decStay_Rate As Decimal = 350   'Hospital charges per day

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

		''Declare variables for the following calculations
		Dim decStay As Decimal	 'Number of days stayed at Hospital
		Dim decMeds As Decimal		  'Medical Charges
		Dim decSurgery As Decimal	   'Surgery Charges
		Dim decLabFees As Decimal	   'Lab fees
		Dim decRehab As Decimal		 'Physical Rehab Fees
		Dim decTotalCost As Decimal	 'Total cost of stay
		Dim decMiscCharges As Decimal   'total of all misc charges


		'Copy the scores into the variables

		decMeds = CDec(CSng(txtMeds.Text))
		decSurgery = CDec(CSng(txtSurgery.Text))
		decLabFees = CDec(CSng(txtLabFees.Text))
		decRehab = CDec(CSng(txtRehab.Text))
		decStay = CDec(CSng(decStay_Rate * CSng(txtStay.Text)))
		decMiscCharges = (decMeds + decSurgery + decLabFees + decRehab)
		decTotalCost = CDec((decStay + decMiscCharges))


	End Sub
	Function CalcMiscCharges(ByVal decMeds As Decimal, ByVal decSurgery As Decimal, ByVal decLabFees As Decimal, ByVal decRehab As Decimal) As Decimal

		'this function calculates the misc charges for a hospital stay.
		Return Convert.ToDecimal(decMeds + decSurgery + decLabFees + decRehab)
	End Function

	Function CalcStay(ByVal decStay_Rate As Decimal) As Decimal
		'this function calculates the cost of a hospital stay.
		Return Convert.ToDecimal(decStay_Rate)
	End Function

	Function CalcTotalCost(ByVal decStay_Rate As Decimal, ByVal decMeds As Decimal, ByVal decSurgery As Decimal, ByVal decRehab As Decimal, ByVal decLabFees As Decimal) As Decimal
		'this function calculates the total cost.
		Return Convert.ToDecimal(decStay_Rate)
	End Function

	Private Sub lblMessage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblMessage.Click
		'Display the total cost.
		lblTotalCost.Text = FormatNumber(lblTotalCost.Text)

	End Sub


End Class



The ONLY error I am getting is last handle for the lblMessage now looking I know that shouldn't be click but what is the correct handle to use?

nuts I didn't see those code helps before running off and fixing errors...blah
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2