(view source code of rndcomp.vbs as plain text)
Option Explicit' This should work okTestRandomComp 10' This should generate an errorTestRandomComp 0Sub TestRandomComp( myReq )
' This is a test subroutine for my RANDOM.WSC component Dim arrResult, i, intAvg, objFSO, objRnd, strWSCOn Error Resume Next
' First let's see if the component is registeredSet objRnd = CreateObject( "robvanderwoude.Random" )
If Err Then
' If not, check if it exists in the current directory ' and use an alternative method to reference the componentSet objFSO = CreateObject( "Scripting.FileSystemObject" )
With objFSOstrWSC = .BuildPath( .GetParentFolderName( WScript.ScriptFullName ), "Random.wsc" )
If .FileExists( strWSC ) Then
strWSC = "script:" & strWSC
Set objRnd = GetObject( strWSC )
ElseWScript.Echo "Random.wsc not registered, " _
& "nor found in current directory"
End If
End With
Set objFSO = Nothing
End If
On Error Goto 0
' Abort if we couldn't instantiate the objectIf Not IsObject( objRnd ) Then WScript.Quit 1
' Set the required properties and query random.orgobjRnd.LowerLimit = 1
objRnd.UpperLimit = 6
objRnd.NumRequests = myReq
objRnd.Query
WScript.Echo vbCrLf _
& "Random.wsc, version " & objRnd.Version & vbCrLf _
& "Lower limit = " & objRnd.LowerLimit & vbCrLf _
& "Upper limit = " & objRnd.UpperLimit & vbCrLf _
& "NumRequests = " & myReq & vbCrLf
If objRnd.Error Then
WScript.Echo vbCrLf _
& "An error occurred, check the Debugging Info!" & vbCrLf
ElseWScript.Echo vbCrLf & "Results:" & vbCrLf & "========" & vbCrLf
arrResult = objRnd.Result
intAvg = 0
For i = 0 To objRnd.NumRequests - 1
WScript.Echo "Result[" & i & "] = " & arrResult(i)
intAvg = intAvg + arrResult(i)
NextWScript.Echo "Average = " & ( intAvg / 10 )
End If
WScript.Echo vbCrLf & vbCrLf & "Debugging Info:" & vbCrLf & "==============="
WScript.Echo objRnd.Debug & vbCrLf
Set objRnd = Nothing
End Sub
page last modified: 2025-10-11; loaded in 0.0069 seconds