why won't this work!!

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Jon (Jon_at_discussions.microsoft.com)
Date: 08/18/04


Date: Tue, 17 Aug 2004 20:55:01 -0700

This program is supposed to let you input variables and then click a flip
button to see whether a coin will land heads or tails. All the variables such
as height, speed and the number of flips are updated every second until the
coin lands. After the coin lands the program determines whether it is heads
or tails, then displays the answers in a label. The only thing that updates
however is the caption showing heads or tails, which changes every second to
add a slot machine type effect to the program. Why does the height, speed and
# of flips not update? The equations seem to work at least once, even though
the caption changes from heads to tails every second, so i know the program
runs through this code every 1000 intervals.

Speed, Distance, RSpeed(rotational speed) are text boxes
speed = 20
distance = 50
rspeed = 10
Heads and Tails are option buttons used to select the coin's starting position
vHeight, vSpeed and Flips are labels.

Private Sub Flip_Click()

Mainform.Flipping.Enabled = True
'interval 100 = 1 second
Mainform.Flipping.Interval = 1000

Heads.Enabled = False
Tails.Enabled = False
Speed.Enabled = False
Distance.Enabled = False
rSpeed.Enabled = False

End Sub

Private Sub Flipping_Timer()
Dim airTime As Integer
Dim nFlips As Integer
Dim Even As Boolean
Dim counter As Integer

If counter = 0 Then
    nDistance = Distance.Text
    nSpeed = Speed.Text
    nRSpeed = rSpeed.Text
    counter = counter + 1
End If

vHeight.Caption = nDistance
vSpeed.Caption = nSpeed
Flips.Caption = nFlips

If nDistance > 0 Then
    nDistance = nDistance + nSpeed
    nSpeed = nSpeed - 9.8
    airTime = airTime + 1
    nFlips = nRSpeed * airTime
End If

'Change captions while coin is in air
If Land.Caption = "Heads" Then
    Land.Caption = "Tails"
Else
    Land.Caption = "Heads"
End If

If nDistance <= 0 Then

    nDistance = 0
    vHeight.Caption = nDistance
    vSpeed.Caption = nSpeed
    Flips.Caption = nFlips
    
        If nFlips Mod 2 = 0 Then Even = True
        If nFlips Mod 2 <> 0 Then Even = False
        
        If Even = True And Heads.Enabled = True Then Land.Caption = "Heads!"
        If Even = True And Heads.Enabled = False Then Land.Caption = "Tails!"
        If Even = False And Heads.Enabled = True Then Land.Caption = "Tails!"
        If Even = False And Heads.Enabled = False Then Land.Caption = "Heads!"
          
    nFlips = 0
    airTime = 0
    Heads.Enabled = True
    Tails.Enabled = True
    Speed.Enabled = True
    Distance.Enabled = True
    rSpeed.Enabled = True
    Mainform.Flipping.Enabled = False
    
End If

End Sub

Private Sub Heads_Click()

If Heads.Value = True Then
    Head.Visible = True
    Tail.Visible = False
End If

End Sub

Private Sub Tails_Click()

If Tails.Value = True Then
    Head.Visible = False
    Tail.Visible = True
End If

End Sub



Relevant Pages

  • Re: Krigman article about sevens due
    ... You are tossing a fair coin. ... The probability is .5 for heads and .5 for tails. ...
    (rec.gambling.craps)
  • Re: Call to make WAR on Darwinists
    ... A flipped coin, OTOH, does not 'choose' to come up heads or tails ... predict which way the coin will land (in honest flips) for any given ...
    (talk.origins)
  • Re: Math Midget seeks help with odds
    ... outcome of coin tosses (heads or tails) and the colors of unseen ... of tosses, and consistently tosses a head/tail ratio of 2:1. ... Maybe it is a biassed coin! ...
    (sci.math)
  • Re: Krigman article about sevens due
    ... You are tossing a fair coin. ... What are the chances of getting exactly what probability ... tails and half heads for this to be true. ...
    (rec.gambling.craps)
  • Re: Good binary PRNG
    ... You could get all heads (or tails) with an unbiased coin. ... but the probability of all heads is ...
    (comp.lang.c)