?
Solved

Convert from VB.NET to C# HELP

Posted on 2007-11-27
8
Medium Priority
?
2,108 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 2000 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Quick Start: DOCKER

Sometimes you just need a Quick Start on a topic in order to begin using it.. this is just what you need to know to get up and running with Docker!

Question has a verified solution.

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

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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

777 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