Click here to Skip to main content
Sign Up to vote bad
good
See more: VB9.0
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:09
rspercy6522.6K


3 solutions

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:41
Thank you very much...I was missing the "Select" statement.
Kuthuparakkal - 5 Sep '12 - 12:44
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/[^]
  Permalink  
Comments
rspercy65 - 5 Sep '12 - 20:44
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.
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:31
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:35
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
Your Filters
Interested
Ignored
     
0 OriginalGriff 216
1 Sergey Alexandrovich Kryukov 175
2 Tadit Dash 154
3 Richard MacCutchan 145
4 Santhosh G_ 125
0 Sergey Alexandrovich Kryukov 10,294
1 OriginalGriff 7,955
2 CPallini 4,201
3 Rohan Leuva 3,522
4 Maciej Los 3,159


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