Results 1 to 3 of 3

Thread: HELP!!!! With VB coding ..shiny pennies as reward!!!

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2002
    Posts
    15

    HELP!!!! With VB coding ..shiny pennies as reward!!!

    I have a prject in VB...and i need to incorporate a simple timer into it...

    Basically when i click a button, something a little black frame should change into a vbblue color....it should STAY blue as so dictated by the timer.interval

    Now when the timer is called when it is near the end of the button.click subroutine, everything is fine...but when i put it this little event in a loop (displaying other colors that are in an array per timer interval) then the timer goes freaky. Basically I can't even see the COLOR because it flashed on so fast and the vbblack kicked in...

    help!

    i have attached my tiny program and the form...if u just run it and click on the next in series button, u can see that the color doesn't even light UP(the NEXT color in the array lights up, but not the first one, which is supposed to repeat the first color that showed up when start button was pushed..)...but if u do step by step, my logic works! (it's just that my timing is off and the light flashed on and off so fast u couldn't see the color...)

    HELP!!! someone...i will mail them shiny new pennies in the mail if u help out a college bound novice programmer...

    It's due by midnight tonight!!!!
    Attached Files Attached Files

  2. #2
    Fanatic Member Mushroom Realm's Avatar
    Join Date
    Mar 2002
    Location
    Murrieta, California
    Posts
    650
    first of all u dont have to if...then the index, just use box(index)

    and ummmmm, nothings wrong for me

  3. #3
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    VB Code:
    1. Dim BoxArray(20) As Integer
    2. Dim UserArray(20) As Integer
    3. Dim GlobalMax As Integer
    4. Dim GlobalUserMax
    5. Dim GlobalOldColor
    6. Dim NextGo As Boolean
    7.  
    8.  
    9. Private Sub Box_Click(Index As Integer)
    10. Dim Count
    11.  
    12. For Count = 1 To GlobalMax
    13.     If Index = 0 Then
    14.         Box(0).BackColor = vbRed
    15.        
    16.     End If
    17.     If Index = 1 Then
    18.         Box(1).BackColor = vbBlue
    19.     End If
    20.     If Index = 2 Then
    21.         Box(2).BackColor = vbYellow
    22.     End If
    23. Next Count
    24.  
    25. End Sub
    26.  
    27. Private Sub Form_Load()
    28. Box(0).BackColor = vbBlack
    29. Box(1).BackColor = vbBlack
    30. Box(2).BackColor = vbBlack
    31. Min.Caption = HScroll1.Min / 10
    32. Max.Caption = HScroll1.Max / 10
    33. End Sub
    34.  
    35. Private Sub GuessCommand_Click()
    36. Dim Count
    37. For Count = 1 To GlobalMax
    38. Next Count
    39.    
    40. End Sub
    41.  
    42. Private Sub HScroll1_Change()
    43. Time.Caption = HScroll1.Value / 10
    44. TimerBlack.Interval = HScroll1.Value * 100
    45.  
    46. End Sub
    47.  
    48. Private Sub StartCommand_Click()
    49. TimerBlack.Interval = Val(HScroll1.Value * 100)
    50. Dim BoxColor As Integer
    51. Randomize
    52. GlobalMax = 0
    53. GlobalUserUserMax = 0
    54. BoxColor = Fix(3 * Rnd)
    55. BoxArray(GlobalMax) = BoxColor
    56. ColorTheBox BoxColor
    57.  
    58. End Sub
    59.  
    60. Private Sub NextCommand_Click()
    61. TimerBlack.Interval = Val(HScroll1.Value * 100)
    62. Dim Count As Integer
    63. Dim BoxColor As Integer
    64.  
    65.     Randomize
    66.  
    67.     For Count = 0 To GlobalMax
    68.        
    69.         BoxColor = BoxArray(Count)
    70.         ColorTheBox BoxColor
    71.        
    72.         Do: DoEvents: Loop Until NextGo = True
    73.         NextGo = False
    74.    
    75.     Next Count
    76.  
    77. Call TimerBlack_Timer
    78. GlobalMax = GlobalMax + 1
    79. BoxColor = Fix(3 * Rnd)
    80. BoxArray(GlobalMax) = BoxColor
    81. ColorTheBox BoxColor
    82.    
    83.  
    84. End Sub
    85.  
    86. Public Function ColorTheBox(WhichBox) As Integer
    87.  
    88.  
    89. Select Case WhichBox
    90.  
    91. Case Is = 0
    92.  
    93. Box(0).BackColor = vbRed
    94. TimerBlack.Enabled = True
    95.  
    96.  
    97. Case Is = 1
    98.  
    99. Box(1).BackColor = vbBlue
    100. TimerBlack.Enabled = True
    101.  
    102.  
    103. Case Is = 2
    104.  
    105. Box(2).BackColor = vbYellow
    106. TimerBlack.Enabled = True
    107.  
    108.  
    109. End Select
    110.  
    111. End Function
    112.  
    113.  
    114. Private Sub TimerBlack_Timer()
    115. Box(0).BackColor = vbBlack
    116. Box(1).BackColor = vbBlack
    117. Box(2).BackColor = vbBlack
    118. TimerBlack.Enabled = False
    119. TimerDelay.Enabled = True
    120. End Sub
    121.  
    122. Private Sub TimerDelay_Timer()
    123.     NextGo = True
    124.     TimerDelay.Enabled = False
    125. End Sub
    Augment your code like that. Then, you'll need to fix the "my guess function yourself, I don't know where you were going with that. But your original problem has been solved, just add a timer called TimerDelay, Disable it, and set its interval to something like 250ms.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width