Solved

Convert from VB.NET to C# HELP

Posted on 2007-11-27
8
2,087 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
  • 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
 
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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