Click here to Skip to main content
12,400,183 members (54,784 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB9.0 VB
How would I change this C# code to VB.Net
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...
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 5-Sep-12 6:09am
rspercy6529.3K
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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)
  Permalink  
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.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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/[^]
  Permalink  
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.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 5 Sep 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100