Err.HelpContext (property)

Syntax

Err.HelpContext [= contextid]

Description

Sets or retrieves the help context ID that identifies the help topic for information on the error.

Comments

The Err.HelpContext property, together with the Err.HelpFile property, contain sufficient information to display help for the error.

When BasicScript generates an error, the Err.HelpContext property is set to 0 and the and the Err.HelpFile property is set to ""; the value of the Err.Number property is sufficient for displaying help in this case. The exception is with errors generated by an OLE automation server; both the Err.HelpFile and Err.HelpContext properties are set by the server to values appropriate for the generated error.

When generating your own user-define errors, you should set the Err.HelpContext property and the Err.HelpFile property appropriately for your error. If these are not set, then BasicScript displays its own help at an appropriate place.

Example

'This example defines a replacement for InputBox that deals

'specifically with Integer values. If an error occurs, the

'function generates a user-defined error that can be trapped

'by the caller.

Function InputInteger(Prompt,Optional Title,Optional Def)

On Error Resume Next

  Dim x As Integer

  x = InputBox(Prompt,Title,Def)

  If Err.Number Then

    Err.HelpFile ="AZ.HLP"

    Err.HelpContext = 2

    Err.Description = "Integer value expected"

    InputInteger = Null

    Err.Raise 3000

  End If

 InputInteger = x

End Function

Sub Main

  Dim x As Integer

  Do

    On Error Resume Next

    x = InputInteger("Enter a number:")

    If Err.Number = 3000 Then

      Msgbox "Invalid number, press ""F1"" to invoke help" _

      ,,,Err.HelpFile,Err.HelpContext

    End If

  Loop Until Err.Number <> 3000

End Sub

See Also

Error Handling (topic), Err.Clear (method), Err.Description (property), Err.HelpFile (property), Err.LastDLLError (property), Err.Number (property), Err.Source (property)

More information

E