2016-05-13 10 views
0
Function FileDialog() 
    Dim oExec1: Set oExec1=CreateObject("WScript.Shell").Exec("mshta.exe ""about:" & "<" & "input type=file id=FILE" & ">" & "<" & "script>FILE.click();new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(FILE.value);close();resizeTo(0,0);" & "<" & "/script>""") 
    Dim sPathfile: sPathfile = oExec1.StdOut.ReadAll 
    sPathfile = Replace(sPathfile, vbCRLF, "") 
    FileDialog = sPathfile 
End Function 

変化: 機能のFileDialog(ファイルサイズ)VBS:特別なFileDialogでファイルサイズを取得するには?

ファイルサイズは、選択したファイルのバイト

答えて

0

読むFunction Statement (VBScript)文書の値を返し、次のように参照により引数を通過する。

option explicit 
On Error GoTo 0 
Dim strResult: strResult = Wscript.ScriptName 
Dim nFileSize: nFileSize = -1  ' for test that `byRef` declaration works 

strResult = strResult & vbNewLine & FileDialog(nFileSize) 
strResult = strResult & vbNewLine & nFileSize 

Wscript.Echo strResult 
Wscript.Quit 

Function FileDialog(byRef xSize) 
    Dim oExec1 
    Set oExec1=CreateObject("WScript.Shell").Exec("mshta.exe ""about:" & "<" & "input type=file id=FILE" & ">" & "<" & "script>FILE.click();new ActiveXObject('Scripting.FileSystemObject').GetStandardStream(1).WriteLine(FILE.value);close();resizeTo(0,0);" & "<" & "/script>""") 
    Dim sPathfile: sPathfile = oExec1.StdOut.ReadAll 
    sPathfile = Replace(sPathfile, vbCRLF, "") 
    If Len(sPathfile) > 0 Then 
    With CreateObject("Scripting.FileSystemObject").GetFile(sPathfile) 
     xSize = .Size     ' the size, in bytes, of the specified file 
    End With 
    Else 
    ' No file chosen: red "×" or Esc or Cancel pressed 
    xSize = 0 
    End If 
    FileDialog = sPathfile 
End Function 

ByRef and ByVal Parametersもご覧ください。

関連する問題