Solved

Translation of C# array to VB.NET

Posted on 2008-10-28
6
235 Views
Last Modified: 2008-10-28
Hi there.
I need some help translating the following small snippet from C# to VB.NET. Unfortunately I am totaly lost when it comes to C# and this time it is the array that is confusing.

Probably easy for you guys, but hard for me. ;)

Thanks in advance!
//Purchase list (catalog purchases)

if(PRP_CatalogPurchases != null)

{

   for(int i = 0;i < PRP_CatalogPurchases.Count;i++)

   {

   string[] Purchase = (string[])PRP_CatalogPurchases[i];

   PRP_XmlData += "<catalog_purchase>" + Environment.NewLine;

   PRP_XmlData += "<line_number>" +  PRP_htmlspecialchars((string)Purchase[0]) + "</line_number>" + Environment.NewLine;

   PRP_XmlData += "<id>" +  PRP_htmlspecialchars((string)Purchase[1]) + "</id>" + Environment.NewLine;

   PRP_XmlData += "<quantity>" +  PRP_htmlspecialchars((string)Purchase[2]) + "</quantity>" + Environment.NewLine;

   PRP_XmlData += "</catalog_purchase>" + Environment.NewLine;

   }

}

Open in new window

0
Comment
Question by:JohnModig
  • 3
  • 2
6 Comments
 
LVL 8

Expert Comment

by:jorgesv13
ID: 22824947
Try:

 

    * 'Purchase list (catalog purchases)

    * If PRP_CatalogPurchases IsNot Nothing Then

    *     For i As Integer = 0 To PRP_CatalogPurchases.Count - 1

    *         Dim Purchase As String() = DirectCast(PRP_CatalogPurchases(i), String())

    *         PRP_XmlData += "<catalog_purchase>" + Environment.NewLine

    *         PRP_XmlData += "<line_number>" + PRP_htmlspecialchars(DirectCast(Purchase(0), String)) + "</line_number>" + Environment.NewLine

    *         PRP_XmlData += "<id>" + PRP_htmlspecialchars(DirectCast(Purchase(1), String)) + "</id>" + Environment.NewLine

    *         PRP_XmlData += "<quantity>" + PRP_htmlspecialchars(DirectCast(Purchase(2), String)) + "</quantity>" + Environment.NewLine

    *         PRP_XmlData += "</catalog_purchase>" + Environment.NewLine

    *     Next

    * End If

Open in new window

0
 
LVL 48

Accepted Solution

by:
jpaulino earned 250 total points
ID: 22824948
Try this way using http://www.developerfusion.com/tools/convert/csharp-to-vb/
'Purchase list (catalog purchases) 

If PRP_CatalogPurchases IsNot Nothing Then 

    For i As Integer = 0 To PRP_CatalogPurchases.Count - 1 

        Dim Purchase As String() = DirectCast(PRP_CatalogPurchases(i), String()) 

        PRP_XmlData += "<catalog_purchase>" + Environment.NewLine 

        PRP_XmlData += "<line_number>" + PRP_htmlspecialchars(DirectCast(Purchase(0), String)) + "</line_number>" + Environment.NewLine 

        PRP_XmlData += "<id>" + PRP_htmlspecialchars(DirectCast(Purchase(1), String)) + "</id>" + Environment.NewLine 

        PRP_XmlData += "<quantity>" + PRP_htmlspecialchars(DirectCast(Purchase(2), String)) + "</quantity>" + Environment.NewLine 

        PRP_XmlData += "</catalog_purchase>" + Environment.NewLine 

    Next 

End If 

Open in new window

0
 
LVL 8

Assisted Solution

by:jorgesv13
jorgesv13 earned 250 total points
ID: 22824949
Sorry, here's formatted right:
'Purchase list (catalog purchases)

If PRP_CatalogPurchases IsNot Nothing Then

    For i As Integer = 0 To PRP_CatalogPurchases.Count - 1

        Dim Purchase As String() = DirectCast(PRP_CatalogPurchases(i), String())

        PRP_XmlData += "<catalog_purchase>" + Environment.NewLine

        PRP_XmlData += "<line_number>" + PRP_htmlspecialchars(DirectCast(Purchase(0), String)) + "</line_number>" + Environment.NewLine

        PRP_XmlData += "<id>" + PRP_htmlspecialchars(DirectCast(Purchase(1), String)) + "</id>" + Environment.NewLine

        PRP_XmlData += "<quantity>" + PRP_htmlspecialchars(DirectCast(Purchase(2), String)) + "</quantity>" + Environment.NewLine

        PRP_XmlData += "</catalog_purchase>" + Environment.NewLine

    Next

End If

Open in new window

0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 48

Expert Comment

by:jpaulino
ID: 22824952
Same tool jorgesv13 :)
0
 
LVL 8

Expert Comment

by:jorgesv13
ID: 22825049
Yep, that page rocks! :)
0
 
LVL 11

Author Comment

by:JohnModig
ID: 22825153
Oh, that was fast! Thank you guys. For the link as well. ;)
0

Featured Post

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem with Filesystemobject or .NET version 3 31
Angular JS Route 3 45
Allow user to hide and show datagridview columns 4 17
Entity Framework 7 27
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

929 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

17 Experts available now in Live!

Get 1:1 Help Now