Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
How would I change this C# code to VB.Net
C#
public static List<YouTubeInfo> LoadVideosKey(string keyWord)
        {
            try
            {
                var xraw = XElement.Load(string.Format(SEARCH,keyWord));
                var xroot = XElement.Parse(xraw.ToString());
                var links = (from item in xroot.Element("channel").Descendants("item")
                             select new YouTubeInfo
                             {
                                 LinkUrl = item.Element("link").Value,
                                 EmbedUrl = GetEmbedUrlFromLink(item.Element("link").Value),
                                 ThumbNailUrl = GetThumbNailUrlFromLink(item),
                             }).Take(20);

                return links.ToList<YouTubeInfo>();
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.Message, "ERROR");
            }
            return null;
        }


I have used 4 different code converters plus mine and I still get the same thing back... Here is the code from mine...
VB
Public Shared Function LoadVideosKey(keyWord As String) As List(Of YouTubeInfo)
    Try
      Dim xraw As Object = XElement.Load(String.Format(SEARCH, keyWord))
      Dim xroot As Object = XElement.Parse(xraw.ToString())
      Dim links As Object = (From item In xroot.Element("channel").Descendants("item")New YouTubeInfo() With { _
        Key .LinkUrl = item.Element("link").Value, _
        Key .EmbedUrl = GetEmbedUrlFromLink(item.Element("link").Value), _
        Key .ThumbNailUrl = GetThumbNailUrlFromLink(item) _
      }).Take(20)

      Return links.ToList(Of YouTubeInfo)()
    Catch e As Exception
      Trace.WriteLine(e.Message, "ERROR")
    End Try

    Return Nothing
  End Function


This is code from Sasha's YouTube Viewer which was coded in WPF. I am changing this over to a WinForms app and this is the only piece of code that I cant get to work.

I know that the word "Key" is not suppose to be in there after conversion, still does not work after removal. The main area of code that I am having the problem with is the ( "Dim links As Object = ......." )

Thanks for the help in advance...
Posted

VB
Dim links As Object = (From item In xroot.Element("channel").Descendants("item")
       Select New YouTubeInfo() With { _
       .LinkUrl = item.Element("link").Value, _
       .EmbedUrl = GetEmbedUrlFromLink(item.Element("link").Value), _
       .ThumbNailUrl = GetThumbNailUrlFromLink(item) _
     }).Take(20)
 
Share this answer
 
Comments
rspercy65 5-Sep-12 12:41pm    
Thank you very much...I was missing the "Select" statement.
Kuthuparakkal 5-Sep-12 12:44pm    
yes, that was the simple issue.
You can just use this webiste for conversions if you are not wanting to do it by hand.

http://www.developerfusion.com/tools/convert/csharp-to-vb/[^]
 
Share this answer
 
Comments
rspercy65 5-Sep-12 20:44pm    
I used my converter to covert the code(Mash-Up Code Converter) here on CP. I will be changing a few things in my converter now and re-posting it.
VB
Public Shared Function LoadVideosKey(keyWord As String) As List(Of YouTubeInfo)
    Try
        Dim xraw = XElement.Load(String.Format(SEARCH, keyWord))
        Dim xroot = XElement.Parse(xraw.ToString())
        Dim links = (From item In xroot.Element("channel").Descendants("item")New YouTubeInfo() With { _
            Key .LinkUrl = item.Element("link").Value, _
            Key .EmbedUrl = GetEmbedUrlFromLink(item.Element("link").Value), _
            Key .ThumbNailUrl = GetThumbNailUrlFromLink(item) _
        }).Take(20)

        Return links.ToList(Of YouTubeInfo)()
    Catch e As Exception
        Trace.WriteLine(e.Message, "ERROR")
    End Try
    Return Nothing
End Function
 
Share this answer
 
Comments
rspercy65 5-Sep-12 12:31pm    
That is basically the same code I have posted...It does not work...The word "Key" does not go before .LinkUrl, or .EmbedUrl or .ThumbnailUrl
Kuthuparakkal 5-Sep-12 12:35pm    
Plz look at my soln...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900