Solved

Convert from VB.NET to C# HELP

Posted on 2007-11-27
8
2,092 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

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…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!

856 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