.Sleep - VBScript


.Sleep

Overview

The .Sleep command in VB Script executes a time delay or pause in the script’s execution. It is primarily used to control the flow of the script and introduce pauses between tasks or operations.

Syntax

.Sleep duration

Required Arguments:

  • duration: (Required) Specifies the duration of the pause in milliseconds.

Options/Flags

None.

Examples

Simple Example:

.Sleep 1000

This command introduces a 1-second (1000 milliseconds) pause in the script’s execution.

Complex Example:

Dim waitTime = 10000
' Sleep for 10 seconds
.Sleep waitTime

This example defines a variable waitTime and uses its value to introduce a pause of 10 seconds.

Common Issues

  • Negative durations: Using negative durations will result in an error.
  • Unintended pauses: Ensure the .Sleep command is placed in the correct location to avoid unexpected delays.

Integration

The .Sleep command can be integrated with other VB Script commands or tools for advanced tasks, such as:

  • Time-based loops: Controlling the frequency of loop iterations by introducing pauses.
  • Asynchronous operations: Managing the flow of asynchronous tasks by introducing pauses between them.

Related Commands

  • .Wait: Waits for an event or condition to occur.
  • .Timeout: Sets a maximum time limit for an operation or event.