why won't this work!!
From: Jon (Jon_at_discussions.microsoft.com)
Date: 08/18/04
- Next message: Hyo-Han Kim: "Is good idea to build P2P Server with VB 6?."
- Previous message: Jeff Johnson: "Re: Creating .rtf document in VB"
- Next in thread: Rick Rothstein: "Re: why won't this work!!"
- Reply: Rick Rothstein: "Re: why won't this work!!"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: Hyo-Han Kim: "Is good idea to build P2P Server with VB 6?."
- Previous message: Jeff Johnson: "Re: Creating .rtf document in VB"
- Next in thread: Rick Rothstein: "Re: why won't this work!!"
- Reply: Rick Rothstein: "Re: why won't this work!!"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|