Solved

Conversion question

Posted on 2011-02-24
6
410 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

759 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

21 Experts available now in Live!

Get 1:1 Help Now