Herman the Fly

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.

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

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)

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

Here's some info on the 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 14:

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

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

Thread.Sleep(2)*

Read more details here.

 

* This statement may require that you include this line before any other lines of code in your program.

Imports System.Threading

 


Why do I keep getting the same random number for Herman and poison?
The Herman Hints above mention that you might need to "reseed" the random number generator to get a different number.  I included a line like         Thread.Sleep(4)     to reseed it, and the modified version also includes a static variable that tracks what the last random number was, and keeps regenerating numbers until it gets a different number.  I used a loop to handle that. 

Why aren't my labels for Herman and poison updated until after Herman dies?
That's an oddity that popped up in the .Net version of VB.  You can refresh the label if you need to with a statement like lblInitHerman.Refresh().  You'll need to do that for each label that you want to change.


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 modularizationMore on structure charts here.