VB Net:如何调用此公共共享函数?

时间:2014-09-04 13:44:49

标签: vb.net datagridview

有人可以帮我解决一些疑惑吗? 如何从按钮调用此公共共享功能?以及如何显示"结果" (数据网格视图中的(文件列表)? 感谢。

Imports System.Threading
Imports System.Threading.Tasks
Imports Google.Apis.Auth.OAuth2
Imports Google.Apis.Drive.v2
Imports Google.Apis.Drive.v2.Data
Imports Google.Apis.Services
Imports System.Net



Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
       '?
    End Sub
    Public Shared Function retrieveAllFiles(service As DriveService) As List(Of File)
    Dim Secrets = New ClientSecrets()
    Secrets.ClientId = "CLIENT ID"
    Secrets.ClientSecret = "CLIENT SECRET"

    Dim scope = New List(Of String)
    scope.Add(DriveService.Scope.Drive)
    Dim credential = GoogleWebAuthorizationBroker.AuthorizeAsync(Secrets, scope, "USER", CancellationToken.None).Result()
    Dim initializer = New BaseClientService.Initializer
    initializer.HttpClientInitializer = credential
    initializer.ApplicationName = "APPLICATION NAME"
    Dim service = New DriveService(initializer)
    Dim request As FilesResource.ListRequest = service.Files.List()
    Dim result As New List(Of File)()
    Dim request As FilesResource.ListRequest = service.Files.List()
    Do
        Try
            Dim files As FileList = request.Execute()
            result.AddRange(files.Items)
            request.PageToken = files.NextPageToken
        Catch e As Exception
            Console.WriteLine("An error occurred: " + e.Message)
            request.PageToken = Nothing
        End Try
    Loop While Not [String].IsNullOrEmpty(request.PageToken)
    Return result
End Function
End Class

1 个答案:

答案 0 :(得分:1)

如果它在同一个类中,您可以按名称调用它,与非共享函数相同:

lst = retrieveAllFiles(service)

如果它在另一个类中,则需要在其前面添加类名:

lst = className.retrieveAllFiles(service)

官方参考: