Windows Script Host  

getResource Method

Returns the value of a resource defined with the <resource> element.

getResource(resourceID) 

Arguments

resourceID
A string that uniquely identifies the resource information contained within a set of resource tags in a *.WSF script file.

Remarks

The getResource method returns a string. Use the <resource> element to isolate strings or numbers that are within the .wsf file and that you want to reference. This feature makes it easy to maintain a set of strings that are localized into several languages. A WSH script file (*.wsf) can contain several different pieces of resource information — each one with a unique resource identifier.

Example

The following WSH script defines a resource called errNonNumeric. The value of errNonNumeric is displayed if the parameter upperBound is not a number.

<package>
<job id="JS">
<resource id="errNonNumeric">Error: A non-numeric value was entered where a number was expected.</resource>
<script language="JScript">

function getRandomNumber(upperBound)
{
   var realUpperBound = parseInt(upperBound);
   if (!isNaN(realUpperBound))
      return (realUpperBound * Math.random) + 1
   else
   {
      WScript.Echo(getResource("errNonNumeric"));
      WScript.Quit(-1);
   }
}

NewValue = getRandomNumber("Bad Value");

</script>
</job>

<job id="VBS">
<resource id="errNonNumeric">Error: A non-numeric value was entered where a number was expected.</resource>
<script language="VBScript">

Function getRandomNumber(upperBound)
   If IsNumeric(upperBound) Then
      getRandomNumber = CInt(upperBound * Rnd + 1)
   Else
      WScript.Echo getResource("errNonNumeric")
      WScript.Quit -1
   End If
End Function

NewValue = getRandomNumber("Bad Value")

</script>
</job>
</package>

See Also

<resource> Element