Link to home
Start Free TrialLog in
Avatar of avi7
avi7

asked on

Conversion question

Hi, I'm new to c# and am trying to convert the following code:
Thanks!

Sub Validation()

If lblCount.Text = 0 Then
 If Label1.Text <> "" Then
    Amount1 = Label1.Text
 Else
    Amount1 = 0.0
 End If

 If Label2.Text <> "" Then
    Amount2 = Label2.Text
 Else
    Amount2 = 0.0
 End If

SumA = Amount1 + Amount2
SumB = Amount3 + Amount4

TotalSum = FormatNumber(SumA + SumB)
lblSum.Text = FormatNumber(TotalSum, 2)

Dim Price1 As Double
Dim Price2 As Double

If txtItemPrice1.Text = "" Then
   Price1 = 0.0
Else
  Price1 = txtItemPrice1.Text
End If

If txtItemPrice2.Text = "" Then
   Price2 = 0.0
Else
  Price2 = txtItemPrice2.Text
End If

If IsNumeric(txtTax.Text) = False Then
   txtTax.Text = 0.0
ElseIf txtTax.Text = "" Then
   txtTax.Text = 0.0
End If

PriceTotal = FormatNumber(Price1 + Price2 + CType(txtTax.Text, Double))
txtItemPriceAmt.Text = FormatNumber(PriceTotal, 2)
If txtItemPriceAmt.Text <> lblTotalSum.Text AND lblTotalSum.Text <> 0
Then
Validation = 1
Else
Validation = 0
End If
 End If
End Sub

SOLUTION
Avatar of Kalpesh Chhatrala
Kalpesh Chhatrala
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of avi7
avi7

ASKER

Thanks, I already tried this free online conversion sites but it's not working.
 void Validation() {
        if ((lblCount.Text == 0)) {
            if ((Label1.Text != "")) {
                Amount1 = Label1.Text;
            }
            else {
                Amount1 = 0;
            }
            if ((Label2.Text != "")) {
                Amount2 = Label2.Text;
            }
            else {
                Amount2 = 0;
            }
            SumA = (Amount1 + Amount2);
            SumB = (Amount3 + Amount4);
            TotalSum = FormatNumber((SumA + SumB));
            lblSum.Text = FormatNumber(TotalSum, 2);
            double Price1;
            double Price2;
            if ((txtItemPrice1.Text == "")) {
                Price1 = 0;
            }
            else {
                Price1 = txtItemPrice1.Text;
            }
            if ((txtItemPrice2.Text == "")) {
                Price2 = 0;
            }
            else {
                Price2 = txtItemPrice2.Text;
            }
            if ((IsNumeric(txtTax.Text) == false)) {
                txtTax.Text = 0;
            }
            else if ((txtTax.Text == "")) {
                txtTax.Text = 0;
            }
            PriceTotal = FormatNumber((Price1 
                            + (Price2 + ((double)(txtTax.Text)))));
            txtItemPriceAmt.Text = FormatNumber(PriceTotal, 2);
            if (((txtItemPriceAmt.Text != lblTotalSum.Text) 
                        && (lblTotalSum.Text != 0))) {
                Validation = 1;
            }
            else {
                Validation = 0;
            }
        }
    }

Open in new window

This is a duplicate question I guess. u have to use price1 = Convert.ToDouble(txt1.text)
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial