All pastes #342354 Raw Edit

Unnamed

public text v1 · immutable
·published 2007-02-06 07:17 UTC
rendered paste body
''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Random Number Generator
'	VBScripting homework for Craig Gibbons
'
' @author		Dean Newman <webmaster@auscoder.com>
' @copyright	Copyright 2007, Dean Newman
' @licence		GNU/General Public Licence v2
' @package		rng_homework.vbs
' @created		06/02/2007, 6.00pm
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''

' Declare some variables that are used
Dim Nums
Dim Count
Dim useMsgbox

' Get a random number between 0 and 100.
Function Rnd_to_100()
	' Apparently VBScript has a keyword called "rnd"
	' that randomly generates a float between 0 and 1
	' so, we take that float, times it by 100 and
	' Typecast it to an Integer.
	Rnd_to_100 = Int(rnd * 100)
End Function

' Here I wanted to display the size of the array dynamically
' however after a little research I found out that VBScript
' did not have such built-in functionality, so I wrote a small
' count function to determine amount of items in the array.
Function ArrLen(Array)
	ArrLen = 0
	For Each x In Array
		ArrLen = (ArrLen + 1)
	Next
End Function

' The following will show a simple message box with a
' "yes" or "no" selection asking you if you wish to continue
' could be useful for such tasks that may slow system permormance
' for a minute or two.
If ( MsgBox("Are you sure you want to run this Script?", vbYesNo, "Confirmation") = vbNo ) Then
	' This is the basic method to stopping script execution.
	WScript.Quit
End If

' Here I was just filling some default values, just a habbit from
' just incase I needed to use these variables being they had values
Count = 0
useMsgbox = False
Nums = Array ( Rnd_to_100(), Rnd_to_100(), Rnd_to_100(), Rnd_to_100(), Rnd_to_100() )

' I wanted to use both methods of popup boxes, so this selection box
' will ask you which you would like to see the output in, the selections
' are Call MsgBox (Call keyword must be used when not being used in a condition or declaration)
' or the basic WScript.Echo function.
If ( MsgBox("Please select from the following output options: Yes = 'Call Msgbox', No = 'WScript.Echo'", vbYesNo, "Output Type") = vbYes ) Then
	useMsgbox = True
End If

' A simple "For Each" loop to go through each value
' of the array, also has a Count variable for numbering
' the output.
For Each intNum In Nums
	' Increase counter
	Count = ( Count + 1 )

	' Output the generated number
	If ( useMsgBox = True ) Then
		' Use titled MsgBox with Information template
		Call MsgBox("Integer Output - " & intNum, vbInformation, "Message - " & Count & " of " & ArrLen(Nums) )
	Else
		' Basic WScript.Echo
		WScript.Echo "Integer Output - " & intNum & ", Message - " & Count & " of " & ArrLen(Nums)
	End If
Next

' As in all my scripts, I thought I would add a simple credit line.
Call MsgBox("Thanks for using this Script, It was created by Dean Newman.", vbInformation, "Created by: Dean Newman")