Solved

Conversion question

Posted on 2011-02-24
6
413 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 100 total points
ID: 34976671
0
 
LVL 96

Assisted Solution

by:Bob Learned
Bob Learned earned 100 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 300 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

929 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now