Solved

Convert from VB.NET to C# HELP

Posted on 2007-11-27
8
2,093 Views
Last Modified: 2013-12-16
I have converted most of an application to C# with a conversion tool, but am running into a problem with the following function.
I am getting an erronr on the Label1.Text = Strings.FormatNumber(Row.Item("Qty"), 0, -2, -2, -2); and every else there is a Row.Item
What would I need to convert this to, in order for this to work properly?

Thank You,

Nurve

public void PopulateSummary()
            {
                  Object Row;
                  if (this.ProposalBuilderDataSet1.Tables["ProposalPrinters"].Rows.Count > 0)
                  {
                        Row = this.ProposalBuilderDataSet1.Tables["ProposalPrintersSummary"].Rows[0];
                if(Information.IsDBNull(Row.Item("Qty")) == true)
                        {
                              Label1.Text = " ";
                        }
                        else
                        {
                              Label1.Text = Strings.FormatNumber(Row.Item("Qty"), 0, -2, -2, -2);
                        }
                        
                        if (Information.IsDBNull(Row.Item("PPQ")) == true)
                        {
                              Label2.Text = " ";
                        }
                        else
                        {
                              Label2.Text = Strings.FormatNumber(Row.Item("PPQ"), 0, -2, -2, -2);
                        }
                        
                        if (Information.IsDBNull(Row.Item("prgCost")) == true || Information.IsDBNull(Row("HardCosts")) == true)
                        {
                              Label3.Text = " ";
                        }
                        else
                        {
                              Label3.Text = Strings.FormatPercent(1 - ((Row.Item("prgCost")) / (Row("HardCosts"))), -1, -2, -2, -2);
                        }
                        
                        if (Information.IsDBNull(Row.Item("HS$")) == true)
                        {
                              Label4.Text = " ";
                        }
                        else
                        {
                              Label4.Text = Strings.FormatCurrency(Row.Item("HS$"), -1, -2, -2, -2);
                        }
                        
                        if (Information.IsDBNull(Row.Item("prgCost")) == true || Information.IsDBNull(Row("TotalCosts")) == true)
                        {
                              Label5.Text = " ";
                        }
                        else
                        {
                              Label5.Text = Strings.FormatPercent(1 - ((Row.Item("prgCost")) / (Row("TotalCosts"))), -1, -2, -2, -2);
                        }
                        
                        if (Information.IsDBNull(Row.Item("TS$")) == true)
                        {
                              Label6.Text = " ";
                        }
                        else
                        {
                              Label6.Text = Strings.FormatCurrency(Row.Item("TS$"), -1, -2, -2, -2);
                        }
                        
                  }
                  else
                  {
                        Label1.Text = "";
                        Label2.Text = "";
                        Label3.Text = "";
                        Label4.Text = "";
                        Label5.Text = "";
                        Label6.Text = "";
                        
                  }
            }

Here is the functionin VB.NET

Sub PopulateSummary()
        Dim Row
        If Me.ProposalBuilderDataSet1.Tables("ProposalPrinters").Rows.Count > 0 Then
            Row = Me.ProposalBuilderDataSet1.Tables("ProposalPrintersSummary").Rows.Item(0)
            If IsDBNull((Row.Item("Qty"))) = True Then
                Label1.Text = " "
            Else
                Label1.Text = FormatNumber(Row.Item("Qty"), 0)
            End If

            If IsDBNull((Row.Item("PPQ"))) = True Then
                Label2.Text = " "
            Else
                Label2.Text = FormatNumber(Row.Item("PPQ"), 0)
            End If

            If IsDBNull(Row.Item("prgCost")) = True Or IsDBNull(Row.Item("HardCosts")) = True Then
                Label3.Text = " "
            Else
                Label3.Text = FormatPercent(1 - ((Row.Item("prgCost")) / (Row.Item("HardCosts"))))
            End If

            If IsDBNull((Row.Item("HS$"))) = True Then
                Label4.Text = " "
            Else
                Label4.Text = FormatCurrency(Row.Item("HS$"))
            End If

            If IsDBNull(Row.Item("prgCost")) = True Or IsDBNull(Row.Item("TotalCosts")) = True Then
                Label5.Text = " "
            Else
                Label5.Text = FormatPercent(1 - ((Row.Item("prgCost")) / (Row.Item("TotalCosts"))))
            End If

            If IsDBNull((Row.Item("TS$"))) = True Then
                Label6.Text = " "
            Else
                Label6.Text = FormatCurrency(Row.Item("TS$"))
            End If

        Else
            Label1.Text = ""
            Label2.Text = ""
            Label3.Text = ""
            Label4.Text = ""
            Label5.Text = ""
            Label6.Text = ""

        End If
    End Sub
0
Comment
Question by:NurveTech
[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
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 20360748
use Row["Qty"] instead
0
 
LVL 18

Expert Comment

by:vbturbo
ID: 20360780
in my opinion this one is the best converter online

http://www.carlosag.net/Tools/CodeTranslator/Default.aspx

    void PopulateSummary() {
        object Row;
        if ((this.ProposalBuilderDataSet1.Tables("ProposalPrinters").Rows.Count > 0)) {
            Row = this.ProposalBuilderDataSet1.Tables("ProposalPrintersSummary").Rows.Item(0);
            if ((IsDBNull(Row.Item["Qty"]) == true)) {
                Label1.Text = " ";
            }
            else {
                Label1.Text = FormatNumber(Row.Item["Qty"], 0);
            }
            if ((IsDBNull(Row.Item["PPQ"]) == true)) {
                Label2.Text = " ";
            }
            else {
                Label2.Text = FormatNumber(Row.Item["PPQ"], 0);
            }
            if (((IsDBNull(Row.Item["prgCost"]) == true)
                        || (IsDBNull(Row.Item["HardCosts"]) == true))) {
                Label3.Text = " ";
            }
            else {
                Label3.Text = FormatPercent((1
                                - (Row.Item["prgCost"] / Row.Item["HardCosts"])));
            }
            if ((IsDBNull(Row.Item["HS$"]) == true)) {
                Label4.Text = " ";
            }
            else {
                Label4.Text = FormatCurrency(Row.Item["HS$"]);
            }
            if (((IsDBNull(Row.Item["prgCost"]) == true)
                        || (IsDBNull(Row.Item["TotalCosts"]) == true))) {
                Label5.Text = " ";
            }
            else {
                Label5.Text = FormatPercent((1
                                - (Row.Item["prgCost"] / Row.Item["TotalCosts"])));
            }
            if ((IsDBNull(Row.Item["TS$"]) == true)) {
                Label6.Text = " ";
            }
            else {
                Label6.Text = FormatCurrency(Row.Item["TS$"]);
            }
        }
        else {
            Label1.Text = "";
            Label2.Text = "";
            Label3.Text = "";
            Label4.Text = "";
            Label5.Text = "";
            Label6.Text = "";
        }
    }

vbturbo
0
 
LVL 6

Expert Comment

by:Roopesh_7
ID: 20360784
0
Industry Leaders: 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 6

Expert Comment

by:Roopesh_7
ID: 20360823
void PopulateSummary() {
        object Row;
        if ((this.ProposalBuilderDataSet1.Tables("ProposalPrinters").Rows.Count > 0)) {
            Row = this.ProposalBuilderDataSet1.Tables("ProposalPrintersSummary").Rows.Item(0);
            if ((IsDBNull(Row.Item["Qty"]) == true)) {
                Label1.Text = " ";
            }
            else {
                Label1.Text = FormatNumber(Row.Item["Qty"], 0);
            }
            if ((IsDBNull(Row.Item["PPQ"]) == true)) {
                Label2.Text = " ";
            }
            else {
                Label2.Text = FormatNumber(Row.Item["PPQ"], 0);
            }
            if (((IsDBNull(Row.Item["prgCost"]) == true)
                        || (IsDBNull(Row.Item["HardCosts"]) == true))) {
                Label3.Text = " ";
            }
            else {
                Label3.Text = FormatPercent((1
                                - (Row.Item["prgCost"] / Row.Item["HardCosts"])));
            }
            if ((IsDBNull(Row.Item["HS$"]) == true)) {
                Label4.Text = " ";
            }
            else {
                Label4.Text = FormatCurrency(Row.Item["HS$"]);
            }
            if (((IsDBNull(Row.Item["prgCost"]) == true)
                        || (IsDBNull(Row.Item["TotalCosts"]) == true))) {
                Label5.Text = " ";
            }
            else {
                Label5.Text = FormatPercent((1
                                - (Row.Item["prgCost"] / Row.Item["TotalCosts"])));
            }
            if ((IsDBNull(Row.Item["TS$"]) == true)) {
                Label6.Text = " ";
            }
            else {
                Label6.Text = FormatCurrency(Row.Item["TS$"]);
            }
        }
        else {
            Label1.Text = "";
            Label2.Text = "";
            Label3.Text = "";
            Label4.Text = "";
            Label5.Text = "";
            Label6.Text = "";
        }
    }

0
 
LVL 18

Expert Comment

by:vbturbo
ID: 20360850
jaime_olivares: sorry for bumping in....didn't see your post until after i submitted

NurveTech: you need though to add brace's [] around the dataset table name

this.ProposalBuilderDataSet1.Tables["ProposalPrinters"].Rows.Count

vbturbo
0
 

Author Comment

by:NurveTech
ID: 20366241
I have a new problem with my conversion of my code, I try to convert this function over and get the following error:

ProposalBuilder.Main' is a 'type' but is used like a 'variable'

How would I change this to work properly?

      private void Button1_Click(System.Object sender, System.EventArgs e)
            {
                  
                  // Dim frmEditPrintersinProposal As New COP(AccountID)
                  //frmEditPrintersinProposal.ShowDialog()
                  
                  COP formMain = new COP(AccountID, UserID, Main);
                  formMain.ShowDialog();
                  
            }

And here is the function that calls:

public COP(string AccountID2, string UserID2, Main formMain)
            {
                  //' This call is required by the Windows Form Designer. , ByRef Cop As COP
                  InitializeComponent();
                  AccountID = AccountID2;
                  
                  UserID = UserID2;
                  Main = formMain;
                  // Add any initialization after the InitializeComponent() call.
            }
            
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20366313
well, you translation is not equivalent:

                 // Dim frmEditPrintersinProposal As New COP(AccountID)
                  //frmEditPrintersinProposal.ShowDialog()
                 
                  COP formMain = new COP(AccountID, UserID, Main);
                  formMain.ShowDialog();
 
COP() constructor has more arguments now. The third should be an object of type Main, but you are trying to pass the classname Main. I am not sure what you really need to pass, but maybe, if your code is inside a Main class, could be:
                COP formMain = new COP(AccountID, UserID, this);
 
0
 

Author Comment

by:NurveTech
ID: 20366876
There was actually no reason for me to continue to pass the reference to the form any more, thank you though for the suggestion.
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
need to convert function to c# 5 40
Making exceptions for ValidationAttribute 2 23
Selenium and Xpath 4 29
Nested forach loop to linq 3 26
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

761 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