?
Solved

Conversion question

Posted on 2011-02-24
6
Medium Priority
?
422 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: 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!

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

770 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