Option Explicit ' This should work ok TestRandomComp 10 ' This should generate an error TestRandomComp 0 Sub TestRandomComp( myReq ) ' This is a test subroutine for my RANDOM.WSC component Dim arrResult, i, intAvg, objFSO, objRnd, strWSC On Error Resume Next ' First let's see if the component is registered Set 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 component Set objFSO = CreateObject( "Scripting.FileSystemObject" ) With objFSO strWSC = .BuildPath( .GetParentFolderName( WScript.ScriptFullName ), "Random.wsc" ) If .FileExists( strWSC ) Then strWSC = "script:" & strWSC Set objRnd = GetObject( strWSC ) Else WScript.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 object If Not IsObject( objRnd ) Then WScript.Quit 1 ' Set the required properties and query random.org objRnd.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 Else WScript.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) Next WScript.Echo "Average = " & ( intAvg / 10 ) End If WScript.Echo vbCrLf & vbCrLf & "Debugging Info:" & vbCrLf & "===============" WScript.Echo objRnd.Debug & vbCrLf Set objRnd = Nothing End Sub