Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - MsgBox help needed

Reply
 
Old 04-28-2009   #1 (permalink)
Vgolfmaster


 
 

MsgBox help needed

Hi again,

I have another script from Jerry Ford's book that I need some help on, please.

It is the luckylotterynumberpicker.vbs script, and the task is to modify the
script so that if more than 10 sets of numbers are requested by the user, the
MsgBox displays only 10 sets of numbers at a time, and repeats until the
entire collection is displayed in multiple Msgbox's. The script right now
shows an infinite number of results in one MsgBox.

I have a feeling that I need to handle this with a loop built in to the

Funtion 'ProcessRandomNumber()' section

but just want to make sure before I start hacking away at this. The variable
'intNumberOfPlays' holds the user input for how many sets of results to
produce (consisting of 6 random numbers per set). The variable
'strLotteryList' holds the string for 1 set of random numbers. Is it as
simple as:
__________________________________________________________________
Function ProcessRandomNumber()
For I = 1 to intNumberOfPlays
count = 0
Do until Count = 10
Select Case intRandomNo
Case aint...(0)
:
:
Case aint...(10)
Case Else
strLotteryList = strLotteryList & " " & intRandomNo & vbTab
intNoOfValidPicks = intNoOfValidPicks + 1
aintLotteryArray(intNumberCount) = intRandomNo
intNumberCount = intNumberCount + 1
End Select
count = count + 1
Loop
Next
End Function
_________________________________________________________________

Here is the entire script in case you need to see all of the variables,
functions, etc etc etc........

--------------------------------------------------------------------------------------------


'Initialization Section

Option Explicit

Dim aintLotteryArray(10) 'Stores randomly generated lottery numbers

Dim blnAllNumbersPicked 'Determines when a set of #s has been created
Dim blnInputValidated 'Set to True when the player enters a valid number
Dim intNumberCount 'Tracks the number of picks for a given play
Dim intNoOfValidPicks 'Tracks the # of valid selections for a given set
Dim intNoOfPlays 'Determines the # of sets of lottery #s to create
Dim intSetCount 'Used to track how many sets have been generated
Dim intRandomNo 'Used to store randomly generated lottery #s
Dim intNoOfPicksToSelect 'Specifies how many #s to generate for each set
Dim intRangeOfNumbers 'Specifies range to use when generating random #s
Dim strLotteryList 'Displays a string showing 1 set of lottery #s
Dim strDisplayString 'Used to display the list of selected lottery #s
Dim strDisplayType 'Specifies whether to show full or summary data
Dim strTitleBarMsg 'Specifies title bar message in pop-up dialogs

'Main Processing Section -------------------------------------------------

SetVariableDefaults()

ProcessScriptIniFile()

CollectPlayerInput()

For intSetCount = 1 to intNoOfPlays

Do Until blnAllNumbersPicked = "True"

GetRandomNumber()

ProcessRandomNumber()

DetermineIfSetIsComplete()

Loop

BuildDisplayString()

ResetVariableDefaults()

Next

DisplayFinalResults()

DisplaySplashScreen()


'Procedure Section -------------------------------------------------------


Function SetVariableDefaults() 'Establish default variable settings

blnAllNumbersPicked = "False"
blnInputValidated = "False"

intNumberCount = 0
intNoOfValidPicks = 0

End Function


Function ProcessScriptIniFile()

Dim FsoObject 'Sets up a reference to the FileSystemObject
Dim OpenFile 'Sets up a reference to the script's .ini file

Set FsoObject = WScript.CreateObject("Scripting.FileSystemObject")

Dim intEquals 'Used to parse .ini file data

Dim strKeyName 'Represents a key in the script's .ini file
Dim strSourceFile 'Specifies the name of the script's .ini file
Dim strInput 'Represents a line in the script's .ini file

strSourceFile = "LuckyLotteryNumberPicker.ini" 'Identify script's .ini file

If (FsoObject.FileExists(strSourceFile)) Then

Set OpenFile = FsoObject.OpenTextFile(strSourceFile, 1)

Do Until Mid(strInput, 1, 15) = "[GameControls]"
strInput = OpenFile.ReadLine
Loop

Do Until OpenFile.AtEndOfStream = "True"
strInput = OpenFile.ReadLine

If Mid(strInput, 1, 1) = "[" Then
Exit do
End If

If Len(strInput) <> 0 Then

intEquals = Instr(strInput, "=")

strKeyName = Mid(strInput, 1, intEquals - 1)

Select Case strKeyName
Case "Greeting"
strTitleBarMsg = Mid(strInput, intEquals + 1, Len(strInput))
Case "DisplayFormat"
strDisplayType = Mid(strInput, intEquals + 1, Len(strInput))
Case "NoOfPicks"
intNoOfPicksToSelect = Cint(Mid(strInput, intEquals + 1, _
Len(strInput)))
Case "RangeOfNumbers"
intRangeOfNumbers = Cint(Mid(strInput, intEquals + 1, _
Len(strInput)))

End Select

End If

Loop

OpenFile.Close()

Else

MsgBox "The .ini file is missing. Unable to execute."
WScript.Quit()

End If

End Function


Function CollectPlayerInput() 'Ask player how many sets of #s to create

Do Until blnInputValidated = "True"

intNoOfPlays = InputBox("How many sets of numbers do " & _
"you want?", strTitleBarMsg)

If IsNumeric(intNoOfPlays) <> True Then
MsgBox "Sorry. You must enter a numeric value. Please " & _
"try again.", ,strTitleBarMsg
Else
If Len(intNoOfPlays) = 0 Then
MsgBox "Sorry. You must enter a numeric value. Please " & _
"try again.", ,strTitleBarMsg
Else
If intNoOfPlays = 0 then
MsgBox "Sorry. Zero is not a valid selection. Please " & _
"try again.", ,strTitleBarMsg
Else
blnInputValidated = "True"
End If
End If
End If

Loop

End Function


Function GetRandomNumber() 'Generate a random number

Randomize

intRandomNo = cInt(FormatNumber(Int((intRangeOfNumbers * Rnd) + 1)))

End Function


Function ProcessRandomNumber() 'Prevent the selection of duplicate #

Select Case intRandomNo
Case aintLotteryArray(0)
Case aintLotteryArray(1)
Case aintLotteryArray(2)
Case aintLotteryArray(3)
Case aintLotteryArray(4)
Case aintLotteryArray(5)
Case aintLotteryArray(6)
Case aintLotteryArray(7)
Case aintLotteryArray(8)
Case aintLotteryArray(9)
Case aintLotteryArray(10)
Case Else
strLotteryList = strLotteryList & " " & intRandomNo & vbTab
intNoOfValidPicks = intNoOfValidPicks + 1
aintLotteryArray(intNumberCount) = intRandomNo
intNumberCount = intNumberCount + 1
End Select

End Function


Function DetermineIfSetIsComplete 'Determine if we have a full set of #s

If intNoOfValidPicks = intNoOfPicksToSelect Then
blnAllNumbersPicked = "True"
End If

End Function


Function BuildDisplayString() 'Assemble a string to display lottery #s

strLotteryList = intSetCount & ")" & vbTab & strLotteryList

strDisplayString = strDisplayString & strLotteryList & _
vbCrLf & vbCrLf & vbCrLf

End Function


Function ResetVariableDefaults() 'Reset variables in order to prepare
'for the selection of the next set of #s

blnAllNumbersPicked = "False"
intNoOfValidPicks = 0
intNumberCount = 0
strLotteryList = ""

End Function


Function DisplayFinalResults() 'Display game's randomly generated #s

If strDisplayType = "Full" Then

MsgBox vbCrLf & _
"L U C K Y L O T T E R Y N U M B E R P I C K E R" & _
vbCrLf & vbCrLf & _
"-----------------------------------------------------" & _
"-----------------------------" & vbCrLf & vbCrLf & _
"Number of plays: " & intNoOfPlays & vbCrLf &vbCrLf & _
"Number of picks per play: " & intNoOfPicksToSelect & _
vbCrLf & vbCrLf & _
"-----------------------------------------------------" & _
"-----------------------------" & vbCrLf & vbCrLf & vbCrLf & _
"Your lottery numbers are: " & vbCrLf & vbCrLf & vbCrLf & _
strDisplayString, , strTitleBarMsg

Else

MsgBox vbCrLf & _
"L U C K Y L O T T E R Y N U M B E R P I C K E R" & _
vbCrLf & vbCrLf & _
"-----------------------------------------------------" & _
"-----------------------------" & vbCrLf & vbCrLf & _
"Your lottery numbers are: " & vbCrLf & vbCrLf & vbCrLf & _
strDisplayString, , strTitleBarMsg

End If

End Function


Function DisplaySplashScreen() 'Display splash screen and terminate game

MsgBox "Thank you for using the Lucky Lottery Number Picker " & _
"© Jerry Ford 2004." & vbCrLf & vbCrLf & "Please play again " & _
"soon!", 4144, strTitleBarMsg

WScript.Quit()

End Function



My System SpecsSystem Spec
Old 04-28-2009   #2 (permalink)
Vgolfmaster


 
 

RE: MsgBox help needed

Hi,

Disregard this topic, please - I got it working. I had the right idea, but
was attacking it in the wrong area of the script. By concentrating in the
'main processing section' I was able to restructure the portions of the
script handling the text string creation and the output by modifying it to:

---------------------------------------------------------------------------------------

For intSetCount = 1 to intNoOfPlays

Do Until blnAllNumbersPicked = "True"

GetRandomNumber()

ProcessRandomNumber()

DetermineIfSetIsComplete()

Loop

BuildDisplayString()

ResetVariableDefaults()

displaycount = displaycount + 1

If displaycount = 10 Then

DisplayFinalResults()

displaycount = 0

strLotteryList = ""

strDisplayString = ""

End If

Next

DisplayFinalResults()

DisplaySplashScreen()
_______________________________________________________________

"Vgolfmaster" wrote:
Quote:

> Hi again,
>
> I have another script from Jerry Ford's book that I need some help on, please.
>
> It is the luckylotterynumberpicker.vbs script, and the task is to modify the
> script so that if more than 10 sets of numbers are requested by the user, the
> MsgBox displays only 10 sets of numbers at a time, and repeats until the
> entire collection is displayed in multiple Msgbox's. The script right now
> shows an infinite number of results in one MsgBox.
>
> I have a feeling that I need to handle this with a loop built in to the
>
> Funtion 'ProcessRandomNumber()' section
>
> but just want to make sure before I start hacking away at this. The variable
> 'intNumberOfPlays' holds the user input for how many sets of results to
> produce (consisting of 6 random numbers per set). The variable
> 'strLotteryList' holds the string for 1 set of random numbers. Is it as
> simple as:
> __________________________________________________________________
> Function ProcessRandomNumber()
> For I = 1 to intNumberOfPlays
> count = 0
> Do until Count = 10
> Select Case intRandomNo
> Case aint...(0)
> :
> :
> Case aint...(10)
> Case Else
> strLotteryList = strLotteryList & " " & intRandomNo & vbTab
> intNoOfValidPicks = intNoOfValidPicks + 1
> aintLotteryArray(intNumberCount) = intRandomNo
> intNumberCount = intNumberCount + 1
> End Select
> count = count + 1
> Loop
> Next
> End Function
> _________________________________________________________________
>
> Here is the entire script in case you need to see all of the variables,
> functions, etc etc etc........
>
> --------------------------------------------------------------------------------------------
>
>
> 'Initialization Section
>
> Option Explicit
>
> Dim aintLotteryArray(10) 'Stores randomly generated lottery numbers
>
> Dim blnAllNumbersPicked 'Determines when a set of #s has been created
> Dim blnInputValidated 'Set to True when the player enters a valid number
> Dim intNumberCount 'Tracks the number of picks for a given play
> Dim intNoOfValidPicks 'Tracks the # of valid selections for a given set
> Dim intNoOfPlays 'Determines the # of sets of lottery #s to create
> Dim intSetCount 'Used to track how many sets have been generated
> Dim intRandomNo 'Used to store randomly generated lottery #s
> Dim intNoOfPicksToSelect 'Specifies how many #s to generate for each set
> Dim intRangeOfNumbers 'Specifies range to use when generating random #s
> Dim strLotteryList 'Displays a string showing 1 set of lottery #s
> Dim strDisplayString 'Used to display the list of selected lottery #s
> Dim strDisplayType 'Specifies whether to show full or summary data
> Dim strTitleBarMsg 'Specifies title bar message in pop-up dialogs
>
> 'Main Processing Section -------------------------------------------------
>
> SetVariableDefaults()
>
> ProcessScriptIniFile()
>
> CollectPlayerInput()
>
> For intSetCount = 1 to intNoOfPlays
>
> Do Until blnAllNumbersPicked = "True"
>
> GetRandomNumber()
>
> ProcessRandomNumber()
>
> DetermineIfSetIsComplete()
>
> Loop
>
> BuildDisplayString()
>
> ResetVariableDefaults()
>
> Next
>
> DisplayFinalResults()
>
> DisplaySplashScreen()
>
>
> 'Procedure Section -------------------------------------------------------
>
>
> Function SetVariableDefaults() 'Establish default variable settings
>
> blnAllNumbersPicked = "False"
> blnInputValidated = "False"
>
> intNumberCount = 0
> intNoOfValidPicks = 0
>
> End Function
>
>
> Function ProcessScriptIniFile()
>
> Dim FsoObject 'Sets up a reference to the FileSystemObject
> Dim OpenFile 'Sets up a reference to the script's .ini file
>
> Set FsoObject = WScript.CreateObject("Scripting.FileSystemObject")
>
> Dim intEquals 'Used to parse .ini file data
>
> Dim strKeyName 'Represents a key in the script's .ini file
> Dim strSourceFile 'Specifies the name of the script's .ini file
> Dim strInput 'Represents a line in the script's .ini file
>
> strSourceFile = "LuckyLotteryNumberPicker.ini" 'Identify script's .ini file
>
> If (FsoObject.FileExists(strSourceFile)) Then
>
> Set OpenFile = FsoObject.OpenTextFile(strSourceFile, 1)
>
> Do Until Mid(strInput, 1, 15) = "[GameControls]"
> strInput = OpenFile.ReadLine
> Loop
>
> Do Until OpenFile.AtEndOfStream = "True"
> strInput = OpenFile.ReadLine
>
> If Mid(strInput, 1, 1) = "[" Then
> Exit do
> End If
>
> If Len(strInput) <> 0 Then
>
> intEquals = Instr(strInput, "=")
>
> strKeyName = Mid(strInput, 1, intEquals - 1)
>
> Select Case strKeyName
> Case "Greeting"
> strTitleBarMsg = Mid(strInput, intEquals + 1, Len(strInput))
> Case "DisplayFormat"
> strDisplayType = Mid(strInput, intEquals + 1, Len(strInput))
> Case "NoOfPicks"
> intNoOfPicksToSelect = Cint(Mid(strInput, intEquals + 1, _
> Len(strInput)))
> Case "RangeOfNumbers"
> intRangeOfNumbers = Cint(Mid(strInput, intEquals + 1, _
> Len(strInput)))
>
> End Select
>
> End If
>
> Loop
>
> OpenFile.Close()
>
> Else
>
> MsgBox "The .ini file is missing. Unable to execute."
> WScript.Quit()
>
> End If
>
> End Function
>
>
> Function CollectPlayerInput() 'Ask player how many sets of #s to create
>
> Do Until blnInputValidated = "True"
>
> intNoOfPlays = InputBox("How many sets of numbers do " & _
> "you want?", strTitleBarMsg)
>
> If IsNumeric(intNoOfPlays) <> True Then
> MsgBox "Sorry. You must enter a numeric value. Please " & _
> "try again.", ,strTitleBarMsg
> Else
> If Len(intNoOfPlays) = 0 Then
> MsgBox "Sorry. You must enter a numeric value. Please " & _
> "try again.", ,strTitleBarMsg
> Else
> If intNoOfPlays = 0 then
> MsgBox "Sorry. Zero is not a valid selection. Please " & _
> "try again.", ,strTitleBarMsg
> Else
> blnInputValidated = "True"
> End If
> End If
> End If
>
> Loop
>
> End Function
>
>
> Function GetRandomNumber() 'Generate a random number
>
> Randomize
>
> intRandomNo = cInt(FormatNumber(Int((intRangeOfNumbers * Rnd) + 1)))
>
> End Function
>
>
> Function ProcessRandomNumber() 'Prevent the selection of duplicate #
>
> Select Case intRandomNo
> Case aintLotteryArray(0)
> Case aintLotteryArray(1)
> Case aintLotteryArray(2)
> Case aintLotteryArray(3)
> Case aintLotteryArray(4)
> Case aintLotteryArray(5)
> Case aintLotteryArray(6)
> Case aintLotteryArray(7)
> Case aintLotteryArray(8)
> Case aintLotteryArray(9)
> Case aintLotteryArray(10)
> Case Else
> strLotteryList = strLotteryList & " " & intRandomNo & vbTab
> intNoOfValidPicks = intNoOfValidPicks + 1
> aintLotteryArray(intNumberCount) = intRandomNo
> intNumberCount = intNumberCount + 1
> End Select
>
> End Function
>
>
> Function DetermineIfSetIsComplete 'Determine if we have a full set of #s
>
> If intNoOfValidPicks = intNoOfPicksToSelect Then
> blnAllNumbersPicked = "True"
> End If
>
> End Function
>
>
> Function BuildDisplayString() 'Assemble a string to display lottery #s
>
> strLotteryList = intSetCount & ")" & vbTab & strLotteryList
>
> strDisplayString = strDisplayString & strLotteryList & _
> vbCrLf & vbCrLf & vbCrLf
>
> End Function
>
>
> Function ResetVariableDefaults() 'Reset variables in order to prepare
> 'for the selection of the next set of #s
>
> blnAllNumbersPicked = "False"
> intNoOfValidPicks = 0
> intNumberCount = 0
> strLotteryList = ""
>
> End Function
>
>
> Function DisplayFinalResults() 'Display game's randomly generated #s
>
> If strDisplayType = "Full" Then
>
> MsgBox vbCrLf & _
> "L U C K Y L O T T E R Y N U M B E R P I C K E R" & _
> vbCrLf & vbCrLf & _
> "-----------------------------------------------------" & _
> "-----------------------------" & vbCrLf & vbCrLf & _
> "Number of plays: " & intNoOfPlays & vbCrLf &vbCrLf & _
> "Number of picks per play: " & intNoOfPicksToSelect & _
> vbCrLf & vbCrLf & _
> "-----------------------------------------------------" & _
> "-----------------------------" & vbCrLf & vbCrLf & vbCrLf & _
> "Your lottery numbers are: " & vbCrLf & vbCrLf & vbCrLf & _
> strDisplayString, , strTitleBarMsg
>
> Else
>
> MsgBox vbCrLf & _
> "L U C K Y L O T T E R Y N U M B E R P I C K E R" & _
> vbCrLf & vbCrLf & _
> "-----------------------------------------------------" & _
> "-----------------------------" & vbCrLf & vbCrLf & _
> "Your lottery numbers are: " & vbCrLf & vbCrLf & vbCrLf & _
> strDisplayString, , strTitleBarMsg
>
> End If
>
> End Function
>
My System SpecsSystem Spec
Old 05-02-2009   #3 (permalink)
Al Dunbar


 
 

Re: MsgBox help needed

You mentioned in an earlier post that "This is actually a scripting
assignment for me". I am just curious to know if all of your posts relate to
assignments in a scripting course of some kind, or if these are exercises
you have assigned yourself in order to learn vbscripting. Or, looking at it
another way, for what purpose do you personally intend to make use of
scripting?

If this is all for a course of some kind, it is interesting to note that you
have somehow managed to escape the fate of others asking for homework help.
Sometimes this is refused outright, and sometimes the poster has been asked
to supply teacher's email address so the group could submit the work
directly ;-)

Of course, participating in newsgroups such as this is a recognized way of
learning skills such as scripting, so it can be difficult to call it
cheating...


/Al

"Vgolfmaster" <Vgolfmaster@xxxxxx> wrote in message
news:0D6F7BA0-2CF5-4956-9599-2428A132B9B7@xxxxxx
Quote:

> Hi,
>
> Disregard this topic, please - I got it working. I had the right idea, but
> was attacking it in the wrong area of the script. By concentrating in the
> 'main processing section' I was able to restructure the portions of the
> script handling the text string creation and the output by modifying it
> to:
>
> ---------------------------------------------------------------------------------------
>
> For intSetCount = 1 to intNoOfPlays
>
> Do Until blnAllNumbersPicked = "True"
>
> GetRandomNumber()
>
> ProcessRandomNumber()
>
> DetermineIfSetIsComplete()
>
> Loop
>
> BuildDisplayString()
>
> ResetVariableDefaults()
>
> displaycount = displaycount + 1
>
> If displaycount = 10 Then
>
> DisplayFinalResults()
>
> displaycount = 0
>
> strLotteryList = ""
>
> strDisplayString = ""
>
> End If
>
> Next
>
> DisplayFinalResults()
>
> DisplaySplashScreen()
> _______________________________________________________________
>
> "Vgolfmaster" wrote:
>
Quote:

>> Hi again,
>>
>> I have another script from Jerry Ford's book that I need some help on,
>> please.
>>
>> It is the luckylotterynumberpicker.vbs script, and the task is to modify
>> the
>> script so that if more than 10 sets of numbers are requested by the user,
>> the
>> MsgBox displays only 10 sets of numbers at a time, and repeats until the
>> entire collection is displayed in multiple Msgbox's. The script right now
>> shows an infinite number of results in one MsgBox.
>>
>> I have a feeling that I need to handle this with a loop built in to the
>>
>> Funtion 'ProcessRandomNumber()' section
>>
>> but just want to make sure before I start hacking away at this. The
>> variable
>> 'intNumberOfPlays' holds the user input for how many sets of results to
>> produce (consisting of 6 random numbers per set). The variable
>> 'strLotteryList' holds the string for 1 set of random numbers. Is it as
>> simple as:
>> __________________________________________________________________
>> Function ProcessRandomNumber()
>> For I = 1 to intNumberOfPlays
>> count = 0
>> Do until Count = 10
>> Select Case intRandomNo
>> Case aint...(0)
>> :
>> :
>> Case aint...(10)
>> Case Else
>> strLotteryList = strLotteryList & " " & intRandomNo & vbTab
>> intNoOfValidPicks = intNoOfValidPicks + 1
>> aintLotteryArray(intNumberCount) = intRandomNo
>> intNumberCount = intNumberCount + 1
>> End Select
>> count = count + 1
>> Loop
>> Next
>> End Function
>> _________________________________________________________________
>>
>> Here is the entire script in case you need to see all of the variables,
>> functions, etc etc etc........
>>
>> --------------------------------------------------------------------------------------------
>>
>>
>> 'Initialization Section
>>
>> Option Explicit
>>
>> Dim aintLotteryArray(10) 'Stores randomly generated lottery numbers
>>
>> Dim blnAllNumbersPicked 'Determines when a set of #s has been created
>> Dim blnInputValidated 'Set to True when the player enters a valid
>> number
>> Dim intNumberCount 'Tracks the number of picks for a given play
>> Dim intNoOfValidPicks 'Tracks the # of valid selections for a given
>> set
>> Dim intNoOfPlays 'Determines the # of sets of lottery #s to
>> create
>> Dim intSetCount 'Used to track how many sets have been generated
>> Dim intRandomNo 'Used to store randomly generated lottery #s
>> Dim intNoOfPicksToSelect 'Specifies how many #s to generate for each set
>> Dim intRangeOfNumbers 'Specifies range to use when generating random
>> #s
>> Dim strLotteryList 'Displays a string showing 1 set of lottery #s
>> Dim strDisplayString 'Used to display the list of selected lottery #s
>> Dim strDisplayType 'Specifies whether to show full or summary data
>> Dim strTitleBarMsg 'Specifies title bar message in pop-up dialogs
>>
>> 'Main Processing
>> Section -------------------------------------------------
>>
>> SetVariableDefaults()
>>
>> ProcessScriptIniFile()
>>
>> CollectPlayerInput()
>>
>> For intSetCount = 1 to intNoOfPlays
>>
>> Do Until blnAllNumbersPicked = "True"
>>
>> GetRandomNumber()
>>
>> ProcessRandomNumber()
>>
>> DetermineIfSetIsComplete()
>>
>> Loop
>>
>> BuildDisplayString()
>>
>> ResetVariableDefaults()
>>
>> Next
>>
>> DisplayFinalResults()
>>
>> DisplaySplashScreen()
>>
>>
>> 'Procedure
>> Section -------------------------------------------------------
>>
>>
>> Function SetVariableDefaults() 'Establish default variable settings
>>
>> blnAllNumbersPicked = "False"
>> blnInputValidated = "False"
>>
>> intNumberCount = 0
>> intNoOfValidPicks = 0
>>
>> End Function
>>
>>
>> Function ProcessScriptIniFile()
>>
>> Dim FsoObject 'Sets up a reference to the FileSystemObject
>> Dim OpenFile 'Sets up a reference to the script's .ini file
>>
>> Set FsoObject = WScript.CreateObject("Scripting.FileSystemObject")
>>
>> Dim intEquals 'Used to parse .ini file data
>>
>> Dim strKeyName 'Represents a key in the script's .ini file
>> Dim strSourceFile 'Specifies the name of the script's .ini file
>> Dim strInput 'Represents a line in the script's .ini file
>>
>> strSourceFile = "LuckyLotteryNumberPicker.ini" 'Identify script's .ini
>> file
>>
>> If (FsoObject.FileExists(strSourceFile)) Then
>>
>> Set OpenFile = FsoObject.OpenTextFile(strSourceFile, 1)
>>
>> Do Until Mid(strInput, 1, 15) = "[GameControls]"
>> strInput = OpenFile.ReadLine
>> Loop
>>
>> Do Until OpenFile.AtEndOfStream = "True"
>> strInput = OpenFile.ReadLine
>>
>> If Mid(strInput, 1, 1) = "[" Then
>> Exit do
>> End If
>>
>> If Len(strInput) <> 0 Then
>>
>> intEquals = Instr(strInput, "=")
>>
>> strKeyName = Mid(strInput, 1, intEquals - 1)
>>
>> Select Case strKeyName
>> Case "Greeting"
>> strTitleBarMsg = Mid(strInput, intEquals + 1,
>> Len(strInput))
>> Case "DisplayFormat"
>> strDisplayType = Mid(strInput, intEquals + 1,
>> Len(strInput))
>> Case "NoOfPicks"
>> intNoOfPicksToSelect = Cint(Mid(strInput, intEquals + 1, _
>> Len(strInput)))
>> Case "RangeOfNumbers"
>> intRangeOfNumbers = Cint(Mid(strInput, intEquals + 1, _
>> Len(strInput)))
>>
>> End Select
>>
>> End If
>>
>> Loop
>>
>> OpenFile.Close()
>>
>> Else
>>
>> MsgBox "The .ini file is missing. Unable to execute."
>> WScript.Quit()
>>
>> End If
>>
>> End Function
>>
>>
>> Function CollectPlayerInput() 'Ask player how many sets of #s to create
>>
>> Do Until blnInputValidated = "True"
>>
>> intNoOfPlays = InputBox("How many sets of numbers do " & _
>> "you want?", strTitleBarMsg)
>>
>> If IsNumeric(intNoOfPlays) <> True Then
>> MsgBox "Sorry. You must enter a numeric value. Please " & _
>> "try again.", ,strTitleBarMsg
>> Else
>> If Len(intNoOfPlays) = 0 Then
>> MsgBox "Sorry. You must enter a numeric value. Please " & _
>> "try again.", ,strTitleBarMsg
>> Else
>> If intNoOfPlays = 0 then
>> MsgBox "Sorry. Zero is not a valid selection. Please " & _
>> "try again.", ,strTitleBarMsg
>> Else
>> blnInputValidated = "True"
>> End If
>> End If
>> End If
>>
>> Loop
>>
>> End Function
>>
>>
>> Function GetRandomNumber() 'Generate a random number
>>
>> Randomize
>>
>> intRandomNo = cInt(FormatNumber(Int((intRangeOfNumbers * Rnd) + 1)))
>>
>> End Function
>>
>>
>> Function ProcessRandomNumber() 'Prevent the selection of duplicate #
>>
>> Select Case intRandomNo
>> Case aintLotteryArray(0)
>> Case aintLotteryArray(1)
>> Case aintLotteryArray(2)
>> Case aintLotteryArray(3)
>> Case aintLotteryArray(4)
>> Case aintLotteryArray(5)
>> Case aintLotteryArray(6)
>> Case aintLotteryArray(7)
>> Case aintLotteryArray(8)
>> Case aintLotteryArray(9)
>> Case aintLotteryArray(10)
>> Case Else
>> strLotteryList = strLotteryList & " " & intRandomNo & vbTab
>> intNoOfValidPicks = intNoOfValidPicks + 1
>> aintLotteryArray(intNumberCount) = intRandomNo
>> intNumberCount = intNumberCount + 1
>> End Select
>>
>> End Function
>>
>>
>> Function DetermineIfSetIsComplete 'Determine if we have a full set of
>> #s
>>
>> If intNoOfValidPicks = intNoOfPicksToSelect Then
>> blnAllNumbersPicked = "True"
>> End If
>>
>> End Function
>>
>>
>> Function BuildDisplayString() 'Assemble a string to display lottery #s
>>
>> strLotteryList = intSetCount & ")" & vbTab & strLotteryList
>>
>> strDisplayString = strDisplayString & strLotteryList & _
>> vbCrLf & vbCrLf & vbCrLf
>>
>> End Function
>>
>>
>> Function ResetVariableDefaults() 'Reset variables in order to prepare
>> 'for the selection of the next set of
>> #s
>>
>> blnAllNumbersPicked = "False"
>> intNoOfValidPicks = 0
>> intNumberCount = 0
>> strLotteryList = ""
>>
>> End Function
>>
>>
>> Function DisplayFinalResults() 'Display game's randomly generated #s
>>
>> If strDisplayType = "Full" Then
>>
>> MsgBox vbCrLf & _
>> "L U C K Y L O T T E R Y N U M B E R P I C K E R" & _
>> vbCrLf & vbCrLf & _
>> "-----------------------------------------------------" & _
>> "-----------------------------" & vbCrLf & vbCrLf & _
>> "Number of plays: " & intNoOfPlays & vbCrLf &vbCrLf & _
>> "Number of picks per play: " & intNoOfPicksToSelect & _
>> vbCrLf & vbCrLf & _
>> "-----------------------------------------------------" & _
>> "-----------------------------" & vbCrLf & vbCrLf & vbCrLf & _
>> "Your lottery numbers are: " & vbCrLf & vbCrLf & vbCrLf & _
>> strDisplayString, , strTitleBarMsg
>>
>> Else
>>
>> MsgBox vbCrLf & _
>> "L U C K Y L O T T E R Y N U M B E R P I C K E R" & _
>> vbCrLf & vbCrLf & _
>> "-----------------------------------------------------" & _
>> "-----------------------------" & vbCrLf & vbCrLf & _
>> "Your lottery numbers are: " & vbCrLf & vbCrLf & vbCrLf & _
>> strDisplayString, , strTitleBarMsg
>>
>> End If
>>
>> End Function
>>

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
MsgBox "Hi", 6858 VB Script
MsgBox Question VB Script
Script to launch a MSGBOX listing PST file locations for a logged onuser VB Script
HELP NEEDED... Vista mail
Using msgbox PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46