Solved

Translation of C# array to VB.NET

Posted on 2008-10-28
6
237 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
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 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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.
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

821 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