Solved

Convert from VB.NET to C# HELP

Posted on 2007-11-27
8
2,091 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can my static class become undefined?? 8 47
ASP.NET MVC 2 31
Help with error when uploading excel file 3 26
VB.NET - Error - Object not set in Module 4 33
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

776 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