locked
C# To VB.NET This Code RRS feed

  • Question

  • User1356714375 posted

    Hello all, I am having a problem with this code.  I am trying to convert this C# code to VB.NET.  I have tried it on developerfusion's converter and have

    SharpDevelop 4 as a conversion tool as well.  When I load the converted code into VS2010 it errors.

     

    I know the problem is in the

    "Dim results = From result In response.Web.Results New SearchResult() With { _
                    Key .SearchResultTitle = result.Title, _
                    Key .SearchResultUri = result.Url, _
                    Key .SearchResultDescription = result.Description _
                }"

    section. This should be adding to the SearchResult class.

    If anyon can help I would greatly appreciate it.

    Unmodified and working C# code.

     

     void soapClient_SearchCompleted(object sender, SearchCompletedEventArgs e)
            {
                SearchResponse response = e.Result;
                if (response.Web.Results.Count() > 0)
                {
                    var results = from result in response.Web.Results
                                  select new SearchResult
                                  {
                                      SearchResultTitle = result.Title,
                                      SearchResultUri = result.Url,
                                      SearchResultDescription = result.Description
                                  };
                    ResultListBox.ItemsSource = results.ToList();
                }
            }

     

    The Class. I have converted it but here is the code for reference.

     

     

    namespace SLBing
    {
        public class SearchResult
        {
            public string SearchResultTitle { get; set; }
            public string SearchResultDescription { get; set; }
            public string SearchResultUri { get; set; }
        }
    }
    

    Thanks a million, Dave
    Saturday, April 16, 2011 3:00 PM

Answers

  • User1508394307 posted

    Hi Dave,

    I think it should be similar to

    Dim results = From result In response.Web.Results _
    	Select New SearchResult With _
    	{ .SearchResultTitle = result.Title, _
    	  .SearchResultUri = result.Url, _
    	  .SearchResultDescription = result.Description}
        
    --- class ---
    
    Namespace SLBing
    
    Public Class SearchResult
        Public Property SearchResultTitle As String
        Public Property SearchResultDescription As String
        Public Property SearchResultUri As String
    End Class
    
    End Namespace

    Hope this helps.

    P.S.

    Note, that auto-implemented properties exist since VB2010. For earlier versions, you would need to change SearchResult class...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 16, 2011 4:43 PM

All replies

  • User1508394307 posted

    Hi Dave,

    I think it should be similar to

    Dim results = From result In response.Web.Results _
    	Select New SearchResult With _
    	{ .SearchResultTitle = result.Title, _
    	  .SearchResultUri = result.Url, _
    	  .SearchResultDescription = result.Description}
        
    --- class ---
    
    Namespace SLBing
    
    Public Class SearchResult
        Public Property SearchResultTitle As String
        Public Property SearchResultDescription As String
        Public Property SearchResultUri As String
    End Class
    
    End Namespace

    Hope this helps.

    P.S.

    Note, that auto-implemented properties exist since VB2010. For earlier versions, you would need to change SearchResult class...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 16, 2011 4:43 PM
  • User1356714375 posted

    Thank You smirnov,

     

    That worked out for me.  I used your example and only had to make a slight change.

     Dim results = From result In e.Result.Web.Results _
            Select New SearchResult With _
            {.SearchResultTitle = result.Title, _
              .SearchResultUri = result.Url, _
              .SearchResultDescription = result.Description}
    Thanks again for the conversion and link.

    Saturday, April 16, 2011 5:12 PM