2013-10-03 68 views
0

我使用的是功能選擇幾個文件:計數量選擇

Module OpenFileMod 
Public Function OpenFile() As String() 
    'declare a string, this is will contain the filename that we return 
    Dim strFileNames As String() 
    'declare a new open file dialog 
    Dim fileDialogBox As New OpenFileDialog() 

    fileDialogBox.Filter = "Excel Files (*.xls)|*.xls" 
    fileDialogBox.Multiselect = True 

    'this line tells the file dialog box what folder it should start off in first 
    'I selected the users my document folder 
    fileDialogBox.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal) 

    'Check to see if the user clicked the open button 
    If (fileDialogBox.ShowDialog() = DialogResult.OK) Then 
     strFileNames = fileDialogBox.FileNames 
    Else 
     MsgBox("You did not select a file!") 
    End If 

    'return the name of the file 
    Return strFileNames 
End Function 
End Module 

我想知道有多少文件,用戶選擇。

我該怎麼做?

回答

2

fileDialogBox.FileNames是一個數組,所以你可以簡單地檢查其Length財產

strFileNames.Length