2011-05-12 168 views
0

我想將谷歌網站上提供的C#.NET的日曆代碼轉換爲VB.NET,並面臨一些轉換問題。請幫幫我。谷歌日曆vb.net

代碼在C#.net:

static void RetrieveAcls(CalendarService service) 
      { 
       FeedQuery query = new FeedQuery(); 
       query.Uri = new Uri("http://www.google.com/calendar/feeds/[email protected]"); 
       AtomFeed calFeed = service.Query(query); 

       Console.WriteLine(); 
       Console.WriteLine("Sharing permissions for your calendars:"); 

       // Retrieve the meta-feed of all calendars. 
       foreach (AtomEntry calendarEntry in calFeed.Entries) 
       { 
        Console.WriteLine("Calendar: {0}", calendarEntry.Title.Text); 
        AtomLink link = calendarEntry.Links.FindService(
         AclNameTable.LINK_REL_ACCESS_CONTROL_LIST, null); 

        // For each calendar, retrieve its ACL feed. 
        if (link != null) 
        { 
         AclFeed feed = service.Query(new AclQuery(link.HRef.ToString())); 
         foreach (AclEntry aclEntry in feed.Entries) 
         { 
          Console.WriteLine("\tScope: Type={0} ({1})", aclEntry.Scope.Type, 
           aclEntry.Scope.Value); 
          Console.WriteLine("\tRole: {0}", aclEntry.Role.Value); 
         } 
        } 
       } 
      } 

我在VB.NET代碼:

Public Sub RetrieveAcls(ByVal service As CalendarService) 

     Dim query As New FeedQuery 
     query.Uri = New Uri("http://www.google.com/calendar/feeds/[email protected]") 

     Dim calFeed As New AtomFeed(service.Query(query)) 

     Console.WriteLine() 
     Console.WriteLine("Sharing permissions for your calendars:") 

     Dim calendarEntry As New AtomEntry 
     Dim link As New AtomLink 
     Dim aclEntry As New AclEntry 
     For Each calendarEntry In calFeed.Entries 
      Console.WriteLine("Calendar: {0}", calendarEntry.Title.Text) 

      link = calendarEntry.Links.FindService(AclNameTable.LINK_REL_ACCESS_CONTROL_LIST, "") 

      If (link Is Nothing) Then 
       Dim feed As AclFeed() 

       feed = New AclFeed(query, service) 

       feed = service.Query(New AclQuery(link.HRef.ToString())) 



       For Each aclEntry In feed.Entries 
        Console.WriteLine("\tScope: Type={0} ({1})", aclEntry.Scope.Type, aclEntry.Scope.Value) 
        Console.WriteLine("\tRole: {0}", aclEntry.Role.Value) 
       Next 
      End If 

     Next 


    End Sub 

上午在 「查詢」 面對錯誤 「飼料=新AclFeed(查詢服務)」其中說Google.GData.Client.FeedQuery類型的值不能轉換爲'System.Uri'...此問題已解決...最後一個問題是根據以下...

Dim myQuery As New EventQuery(feedURI) 

Dim myResultsFeed As New EventFeed(service.Query(myQuery)) 

我收到「myResultsFeed」的錯誤爲「未爲'Public Sub New(uriBase As System.Uri,iService As Google.GData.Client.IService)'的參數'iService'指定的參數'」。並在另一個錯誤「service.Query(更改爲MyQuery))作爲‘類型的值‘Google.GData.Calendar.EventFeed’不能轉換爲‘的System.Uri’。’

static void DateRangeQuery(CalendarService service, DateTime startTime, DateTime endTime) 
      { 
       EventQuery myQuery = new EventQuery(feedUri); 
       myQuery.StartTime = startTime; 
       myQuery.EndTime = endTime; 

       EventFeed myResultsFeed = service.Query(myQuery) as EventFeed; 

       Console.WriteLine("Matching events from {0} to {1}:", 
            startTime.ToShortDateString(), 
            endTime.ToShortDateString()); 
       Console.WriteLine(); 
       for (int i = 0; i < myResultsFeed.Entries.Count; i++) 
       { 
        Console.WriteLine(myResultsFeed.Entries[i].Title.Text); 
       } 
       Console.WriteLine(); 
      } 
+0

那麼你沒有向我們展示原始的C#,但基本上你沒有通過正確的參數,通過它的外觀。看看你正在轉換的C#更仔細。 – 2011-05-12 20:14:00

+0

這是好嗎? 「Dim myResultsFeed As EventFeed = service.Query(New EventQuery(feedURI))」 – user688175 2011-05-12 20:15:57

+0

我將發佈原始C#代碼1分鐘 – user688175 2011-05-12 20:16:10

回答

1

,那麼您已經轉換這個:

AclFeed feed = service.Query(new AclQuery(link.HRef.ToString())); 

這樣:!

Dim feed As AclFeed() 
feed = New AclFeed(query, service) 
feed = service.Query(New AclQuery(link.HRef.ToString())) 

他們是不一樣的,在所有你的第二行是調用沒有明顯的理由構造

只是這將是罰款:

Dim feed As AclFeed = service.Query(New AclQuery(link.HRef.ToString())) 

它也不清楚爲什麼你有這樣的臺詞:

Dim calendarEntry As New AtomEntry 

你爲什麼要呼籲AtomEntry參數的構造函數?爲什麼你在ForEach循環之外聲明變量?只需使用:

For Each calendarEntry As AtomEntry In calFeed.Entries 

編輯:對於其他的問題,我認爲你只需要:

Dim myEventFeed As CType(service.Query(myQuery), EventFeed) 

如果你能提供完整的方法,這將有助於。

+0

很酷的工作...非常感謝... – user688175 2011-05-12 20:08:20

+0

我有一個更多的最後一個錯誤...我在上面發佈代碼...請幫助... – user688175 2011-05-12 20:09:06

+0

嘿,我試過這個第二個錯誤。它是否正確? 「Dim myResultsFeed As EventFeed = service.Query(New EventQuery(feedURI))」我沒有得到這個錯誤。 – user688175 2011-05-12 20:15:30

0

我不確定它是否有效,但這是直接c#->VB.Net-從developerfusion翻譯,語法似乎是正確的。只是作爲你的下一個問題的提示;)

Shared Sub RetrieveAcls(ByVal service As CalendarService) 
    Dim query As New FeedQuery() 
    query.Uri = New Uri("http://www.google.com/calendar/feeds/[email protected]") 
    Dim calFeed As AtomFeed = service.Query(query) 

    Console.WriteLine() 
    Console.WriteLine("Sharing permissions for your calendars:") 

    ' Retrieve the meta-feed of all calendars. 
    For Each calendarEntry As AtomEntry In calFeed.Entries 
     Console.WriteLine("Calendar: {0}", calendarEntry.Title.Text) 
     Dim link As AtomLink = calendarEntry.Links.FindService(AclNameTable.LINK_REL_ACCESS_CONTROL_LIST, Nothing) 

     ' For each calendar, retrieve its ACL feed. 
     If Not link Is Nothing Then 
      Dim feed As AclFeed = service.Query(New AclQuery(link.HRef.ToString())) 
      For Each aclEntry As AclEntry In feed.Entries 
       Console.WriteLine(vbTab & "Scope: Type={0} ({1})", aclEntry.Scope.Type, aclEntry.Scope.Value) 
       Console.WriteLine(vbTab & "Role: {0}", aclEntry.Role.Value) 
      Next 
     End If 
    Next 
End Sub