调用子vb时不能使用括号

时间:2014-06-16 11:02:10

标签: vbscript parentheses

首先,我已经查看了网站上的类似问题,但无法发现我的错误。

我也是vb的新手,所以这也无济于事。

请帮助一个真正的新手...

由于

dim profileSize
dim oFS, oFolder
set oFS = WScript.CreateObject("Scripting.FileSystemObject")
Set wshShell = WScript.CreateObject( "WScript.Shell" )
strUserName = wshShell.ExpandEnvironmentStrings( "%USERNAME%" )
set oFolder = oFS.GetFolder("\\burns\Profiles\" + strUserName + ".V2")

ShowFolderDetails oFolder

sub ShowFolderDetails(oF)
dim F
    profileSize = of.Size
    if profileSize > 1006582400 Then    
    WriteFileText(profileSize, strUserName)
    End If
    if profileSize > 2516582400 Then    
    WriteFileText(profileSize, strUserName)
    wscript.echo "Your Windows user profile is too big! Please contact the IT Office"
    WScript.Quit
    End if

    for each F in oF.Subfolders
    'ShowFolderDetails(F)
    next
end sub


sub WriteFileText(sText, userID)
    Dim objFSO 'As FileSystemObject
    Dim objTextFile 'As Object
    strLogFilePath = "\\burns\Profiles\size_log.txt"
    strTime = FormatDateTime(Date(), 0)
    Const ForReading = 1
    Const ForWriting = 2
    Const ForAppending = 8

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.OpenTextFile(strLogFilePath, ForAppending, True)

    ' Write a line.
    objTextFile.WriteLine (strTime + "," + userID + "," + sText )

    objTextFile.Close
    'objTextFile.Close

End Sub

1 个答案:

答案 0 :(得分:5)

错误消息“调用Sub时不能使用括号”表示在调用sub时不能使用括号; - )。

在VBA中,如果符合以下条件,则使用括号进行函数调用:

  1. 函数调用具有对返回值的赋值。
  2. 您有一个参数列表并使用'call'关键字。
  3. 所以你应该能够像这样打电话给你的潜水员:

    WriteFileText x,y
    

    或者,如果你坚持使用括号:

    call WriteFileText (x, y)