• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 201
  • Last Modified:

Subtracting numbers from two text boxes

I dynamically populate rows of data.  I need to get the amount due for a line item.  

Items from DB:
OriginalAmount = Dollar amount owed
totalPayment = How much has been paid so far.

Input items:
txtAmtPatientPaid = input box
txtAmtPaid = input box

The user fills out the form and I use Javascript to update the AmtDueTemp field which works correctly.  When the user hits the 'Save' button the validation is run on the .aspx.vb page.  If there is an error I want all populated fields to remain populated on postback.

If I only subtract the amount from the DB it works but now I need to subtract the two input box fields. How can I do the calculation below?  I believe I need to change the field type to a number but I don't know how.

Any suggestions?
dblAmtDueTemp = FormatNumber(rd("OriginalAmount") - rd("totalPayment") - Request.Form("txtAmtPatientPaid" & i) - Request.Form("txtAmtPaid" & i), 2)

Open in new window

0
huerita37
Asked:
huerita37
  • 5
  • 3
1 Solution
 
käµfm³d 👽Commented:
Try this:

Try
    dblAmtDueTemp = FormatNumber(rd("OriginalAmount") - rd("totalPayment") - Convert.ToDecimal(Request.Form("txtAmtPatientPaid" & i)) - Convert.ToDecimal(Request.Form("txtAmtPaid" & i)), 2)
Catch ex As System.FormatException
    ' Conversion failed
End Try

Open in new window

0
 
huerita37Author Commented:
I still get the same error:

Input string was not in a correct format
0
 
huerita37Author Commented:
I did not use the 'Try' or 'Catch'.  Would that make a difference?

I also used convert.ToDouble and got the same error.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
huerita37Author Commented:
Once I added the 'Try' and 'Catch' it worked.

What does that do?
0
 
käµfm³d 👽Commented:
It shouldn't make a difference--you just will have an unhandled exception if the values passed to Convert.ToDecimal (or ToDouble) do not represent valid numbers.

See if this works better:

Try
    dblAmtDueTemp = Convert.ToDouble(rd("OriginalAmount")) - Convert.ToDouble(rd("totalPayment")) - Convert.ToDouble(Request.Form("txtAmtPatientPaid" & i)) - Convert.ToDouble(Request.Form("txtAmtPaid" & i))
Catch ex As System.FormatException
    ' Conversion failed
End Try

Open in new window

0
 
huerita37Author Commented:
I thought it worked but it doesn't.  Because of the 'Try' and 'Catch' it gives a number and not an error but it doesn't calculate correctly and then all the rows get the same number.
0
 
käµfm³d 👽Commented:
With which version?
0
 
huerita37Author Commented:
Both.

I ended up doing the below:
If Request.Form("txtAmtPatientPaid" & i) = "" Then
                                                dblAmtPatientPaidtemp = 0
                                            Else
                                                dblAmtPatientPaidtemp = Request.Form("txtAmtPatientPaid" & i)
                                            End If
                                            If Request.Form("txtAmountPaid" & i) = "" Then
                                                dblAmtPaidtemp = 0
                                            Else
                                                dblAmtPaidtemp = Request.Form("txtAmountPaid" & i)
                                            End If
                                            dblAmtDueTemp = FormatNumber(rd("OriginalAmount") - rd("totalPayment") - (dblAmtPatientPaidtemp + dblAmtPaidtemp), 2)

Open in new window

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now