Muokkaa

Jaa


How to: Call a Procedure that Does Not Return a Value (Visual Basic)

A Sub procedure does not return a value to the calling code. You call it explicitly with a stand-alone calling statement. You cannot call it by simply using its name within an expression.

To call a Sub procedure

  1. Specify the name of the Sub procedure.

  2. Follow the procedure name with parentheses to enclose the argument list. If there are no arguments, you can optionally omit the parentheses. However, using the parentheses makes your code easier to read.

  3. Place the arguments in the argument list within the parentheses, separated by commas. Be sure you supply the arguments in the same order that the Sub procedure defines the corresponding parameters.

    The following example calls the Visual Basic AppActivate function to activate an application window. AppActivate takes the window title as its sole argument. It does not return a value to the calling code. If a Notepad process is not running, the example throws an ArgumentException. The Shell procedure assumes the applications are in the paths specified.

    Dim notepadID As Integer
    ' Activate a running Notepad process.
    AppActivate("Untitled - Notepad")
    ' AppActivate can also use the return value of the Shell function.
    ' Shell runs a new instance of Notepad.
    notepadID = Shell("C:\WINNT\NOTEPAD.EXE", AppWinStyle.NormalFocus)
    ' Activate the new instance of Notepad.  
    AppActivate(notepadID)
    

See also