Windows Media Encoder SDK banner art

AudioVBScript Variables

Local variables can be used to temporarily store values that are only needed by the logic in that function. Such a variable is not accessible outside the function, and it is cleared each time the function is called. Each instance of a called function will have its own instance of local variables, independent of other instances.

Dim statements cannot occur inside a Sub. This does not mean that all variables in an AudioVBScript file must be globally declared. It only means that local variables cannot be explicitly allocated by using Dim. Local variables can, however, be automatically allocated.

The following code is not allowed:

dim x
sub UseLocal
  dim y
  y = x + 1
end sub

But the following is permissible:

dim x
sub UseLocal
  y = x + 1
end sub

Here, y is automatically created when used and released when the subroutine exits.

Local variables are guaranteed to have an initial value of zero. You can also set a local variable's value using a standard assignment, as shown in the following example:

dim x   ' Global variable.
sub AddSomeValues
  local1 = 10   ' Variables are created and initialized.
  local2 = 20
  x = local1 + local2
end sub

An object returned by a function cannot be directly dereferenced. The following is not allowed:

LoadSegment("song.sgt").Download

However, the following is permitted:

set seg = LoadSegment("song.sgt")
seg.Download

© 2000-2001 Microsoft Corporation. All rights reserved.