?
Solved

Conversion question

Posted on 2011-02-24
6
Medium Priority
?
424 Views
Last Modified: 2012-05-11
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

0
Comment
Question by:avi7
6 Comments
 
LVL 16

Assisted Solution

by:Kalpesh Chhatrala
Kalpesh Chhatrala earned 400 total points
ID: 34976671
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 400 total points
ID: 34976672
First, here is an online conversion web site:

Convert VB.NET to C#
http://www.developerfusion.com/tools/convert/vb-to-csharp/

Second, straight conversion may not take advantage of some of the language constructs, or handle some of the syntax differences between VB.NET and C#.
0
 

Author Comment

by:avi7
ID: 34976776
Thanks, I already tried this free online conversion sites but it's not working.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:Kalpesh Chhatrala
ID: 34976821
 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

0
 
LVL 20

Expert Comment

by:informaniac
ID: 34977203
This is a duplicate question I guess. u have to use price1 = Convert.ToDouble(txt1.text)
0
 
LVL 10

Accepted Solution

by:
John Claes earned 1200 total points
ID: 34977411
kalpesh2804:
The conversion gives faults  : the String to Int cast of the variables is not done.

informaniac:
it indeed looks
http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_26846820.html

I thinck the Code From kalpesh2804 is used to create that Question ;-)


avi7:
Very short answering on both of the Case:

When converting Code look for folowing generated issues

Automaticaly VB. Casts are not supported in c#
so
       if  lblCount.Text = 0
should be translated into some of next
       if ( lblCount.Text = "0")
OR
       if ( (int)lblCount.Text = 0)
OR
       int count;
       if (int.TryParse(lblCount.Text, out count) && count==0)


Returnvalues !

Sub Validation()
{
        Validation=1;
}

must be translated in

int Validation ()
{
       return 1;
}

There are more issues after conversion because of defaulted casts and syntaxing

regards

poor beggar
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question