CIS 220 - Clues
Hank the Roach


You don't need to use arrays in this program.


In order to add an entry to a list box during runtime, simply use the Items.Add method.  For example, to add the value 15 to the list box lstFred, use the statement lstFred.Items.Add(15)

To force the most recent addition to a list box to be displayed, you need the index of the last item added.  You can obtain this from the value returned by Items.Add.  For example,

Dim newIndex As Integer
newIndex = lstFred.Items.Add(15)

To highlight that most recent addition, use the setSelected method.  For example,

lstFred.SetSelected(newIndex, True)

For more details on the list box, go here or here.


Delay Routine

Here is the delay routine:

Private Sub getDelay(ByVal delayInSec As Double)
     Threading.Thread.Sleep(delayInSec)
End Sub

You can call it using the statement Call getDelay(400)

 

This approach may require that you include the following line before any other lines of code in your program.  That means it will be the VERY FIRST line in your program!!!!

Imports System.Threading


Random Number Generator

Random numbers

  • Random numbers may be generated in the .NET Framework by making use of the Random class. This class may be instantiated using the following code:

    'Create a new Random class in VB.NET
    Dim RandomClass As New Random()

    In most coding situations, it is more desirable to create a random number within a certain size range. In this case, the Next method should be called with two arguments: the minimum value and the maximum value. For example, the following assigns RandomNumber to a value that is greater or equal to 0 and less than 8:

    Dim RandomNumber As Integer
    RandomNumber = RandomClass.Next(0, 8)

    Note that an ArgumentOutOfRangeException will be raised if the minimum value is larger than the maximum value.

    It is also possible to specify just the maximum value using a different constructor. The following will return a return a random integer that is greater or equal to 0 and less than 8:

    Dim RandomNumber As Integer
    RandomNumber = RandomClass.Next(8)

You may need to reseed the random number generator by including a line like

Threading.Thread.Sleep(2)*

For example,

           Threading.Thread.Sleep(2)
           Dim RandomNumber As Integer
           RandomNumber = RandomClass.Next(8)

Look at this code segment (near the bottom) for an example.

Read more details here.

 

* This statement may require that you include the following line before any other lines of code in your program. That means it will be the VERY FIRST line in your program!!!!

Imports System.Threading

 

 

Dr. Beard's structure chart for the program can be found here....You do not have to follow it directly, but it will give you a good idea about modularization.