5

これは不可能だという印象を受けていますが、これまでのところ、これが私が得たものです。

Sub Main()        
    On Error GoTo ErrorHandler        
    If Command$ = "" Then
        LogAction "Begin document lockdown"
        LockdownDocs
        LogAction "Lockdown complete"
    Else
        LogAction "Begin document enabling"
        EnableDocs
        LogAction "Documents have be enabled"
    End If
Exit Sub
ErrorHandler:
    LogAction "DocLock Error " & Err.Number & "::" & Err.Description
End Sub

私はそれを次のように見せたい:

Function Main() As Boolean
    On Error GoTo ErrorHandler        
    If Command$ = "" Then
        LogAction "Begin document lockdown"
        LockdownDocs
        LogAction "Lockdown complete"
    Else
        LogAction "Begin document enabling"
        EnableDocs
        LogAction "Documents have be enabled"
    End If
    Return True
Exit Function
ErrorHandler:
    LogAction "Error " & Err.Number & "::" & Err.Description
    Return False
End Function

私が見た中で最も近いのはFunction Main() As IntegerVisualStudio2005ですが、私はVB6を使用しています。

4

1 に答える 1

9

Win32 API呼び出しを使用することにより、ここで可能な解決策があります。本質的に:

Private Declare Sub ExitProcess Lib "kernel32" (ByVal uExitCode As Long)

' Exit with ErrorLevel set to 9
ExitProcess 9

これはEndVBランタイムと同等であるため、を呼び出す前に、クリーンアップ、接続、ファイル、デバイス、フォームなどのクローズを実行する必要があることに注意してくださいExitProcess

于 2012-07-16T20:54:22.730 に答える