Results 1 to 2 of 2

Thread: help with a counter please!

  1. #1

    Thread Starter
    Member ibowlwell's Avatar
    Join Date
    Mar 2002
    Location
    RI
    Posts
    56

    help with a counter please!

    can someone tell me why my memorycounter is increasing by itself?? ***********'s indicate where they increase

    VB Code:
    1. Dim lastcolor As String
    2. Dim memoryStack() As String
    3. Dim gameMemoryStack() As String   'make a connection with the memorycounters thats i
    4. Dim firstColor As String
    5. Dim memoryCounter As Integer
    6. Dim roundNumber As Integer
    7. Dim arrTemp() As String
    8. Private Function pop() As String
    9.     Debug.Print "memcountbeg pop " & memoryCounter
    10.     Dim arrTemp() As String
    11.     ReDim arrTemp(UBound(memoryStack))
    12.     arrTemp() = reverseOrder(memoryStack)
    13.    
    14.     pop = arrTemp(UBound(arrTemp))
    15.     ReDim Preserve arrTemp(UBound(arrTemp) - 1)
    16.    
    17.     If UBound(arrTemp) = 0 Then
    18.        roundNumber = roundNumber + 1
    19.        Call nextRound   'gets the next round
    20.     End If
    21.     Debug.Print "memcountend pop " & memoryCounter  ********
    22. End Function                                                    'memorycounter = 0
    23.  
    24. Private Sub Form_Load()
    25. 'sets default values to the two arrays used to hold values of the letters pushed
    26.     Dim i As Integer
    27.     Dim randomNumber As Integer
    28.     Dim gameColor As String
    29.     ReDim memoryStack(0)
    30.     ReDim gameMemoryStack(24)
    31.     roundNumber = 1
    32.    
    33.     Randomize
    34.     'decides what the colors are going to be for the whole game
    35.     'fills an array with random colors of red,yellow,blue, and green
    36.     For i = 0 To 24
    37.         randomNumber = Int(4 * Rnd)
    38.         Select Case randomNumber
    39.             Case 0
    40.                 gameColor = "Yellow"
    41.             Case 1
    42.                 gameColor = "Red"
    43.             Case 2
    44.                 gameColor = "Blue"
    45.             Case 3
    46.                 gameColor = "Green"
    47.         End Select
    48.         gameMemoryStack(i) = gameColor
    49.     Next i
    50.     firstColor = gameMemoryStack(0)
    51.     Call nextRound
    52.    
    53.  
    54. End Sub
    55. Private Sub lblYellowbutton_click()
    56.     Dim begColor As String
    57.     Dim colorPush As String
    58.     colorPush = "Yellow"
    59.     Debug.Print UBound(memoryStack)
    60.     If (colorPush = memoryStack(memoryCounter)) Then
    61.        lastcolor = pop
    62.        memoryCounter = memoryCounter + 1
    63.        If UBound(arrTemp) = 0 Then
    64.           roundNumber = roundNumber + 1
    65.           Call nextRound
    66.        End If
    67.     Else
    68.         End
    69.     End If
    70. End Sub
    71. Private Sub lblBluebutton_click()
    72.     Dim begColor As String
    73.     Dim colorPush As String
    74.     colorPush = "Blue"
    75.     Debug.Print UBound(memoryStack)
    76.     If (colorPush = memoryStack(memoryCounter)) Then
    77.        lastcolor = pop
    78.        memoryCounter = memoryCounter + 1
    79.        If UBound(arrTemp) = 0 Then    'changes memory stack to arrtemp
    80.           roundNumber = roundNumber + 1
    81.           Call nextRound
    82.        End If
    83.     Else
    84.        End
    85.     End If
    86. End Sub
    87. Private Sub lblGreenbutton_click()
    88.     Dim begColor As String
    89.     Dim colorPush As String
    90.     colorPush = "Green"
    91.     Debug.Print UBound(memoryStack)
    92.     If (colorPush = memoryStack(memoryCounter)) Then
    93.        lastcolor = pop
    94.        memoryCounter = memoryCounter + 1
    95.        Debug.Print UBound(memoryStack)
    96.        If UBound(arrTemp) = 0 Then
    97.           roundNumber = roundNumber + 1
    98.           Call nextRound
    99.        End If
    100.     Else
    101.        End
    102.     End If
    103. End Sub
    104. Private Sub lblRedbutton_click()
    105.     Dim begColor As String
    106.     Dim colorPush As String
    107.     colorPush = "Red"
    108.      Debug.Print UBound(memoryStack)
    109.     If (colorPush = memoryStack(memoryCounter)) Then
    110.        lastcolor = pop
    111.        memoryCounter = memoryCounter + 1
    112.        If UBound(arrTemp) = 0 Then       '***********************************
    113.           roundNumber = roundNumber + 1 'this may be a problem ??????????????
    114.           Call nextRound        '***********************************
    115.        End If
    116.     Else
    117.        End
    118.     End If
    119. End Sub
    120.  
    121.  
    122. Private Sub TMRBLINK_Timer()
    123.      'this procedure makes the buttons blink
    124.      Dim i As Integer, j As Integer
    125.      Static blinkNumber As Integer
    126.      Debug.Print "memcountbeg tmr " & memoryCounter********
    127.         If blinkNumber < UBound(memoryStack) Then      
    128.                                                           'NOw memorycounter = 1????
    129.             Debug.Print memoryStack(blinkNumber)
    130.             firstColor = memoryStack(blinkNumber)
    131.             Call colorSelect
    132.             tmrblink.Enabled = False
    133.             tmrColorBlinked.Enabled = True
    134.             blinkNumber = blinkNumber + 1
    135.         Else
    136.             blinkNumber = 0
    137.             tmrblink.Enabled = False
    138.         End If
    139.        
    140.      
    141.     Debug.Print "memcountend tmr " & memoryCounter
    142. End Sub
    143.  
    144.  
    145. Private Function reverseOrder(arrName() As String) As String()
    146.     'this function reverses the order of the array so that we can
    147.     'pull from the bottom
    148.     Debug.Print "memcountbeg revord " & memoryCounter
    149.     Dim i As Integer
    150.     Dim tempArr() As String
    151.     ReDim tempArr(UBound(arrName))
    152.     For i = 0 To UBound(arrName)
    153.         tempArr(i) = arrName(UBound(arrName) - 1)
    154.     Next i
    155.     reverseOrder = tempArr
    156.     Debug.Print "memcountend revord " & memoryCounter
    157. End Function
    158.  
    159. Private Sub tmrColorBlinked_Timer()
    160.     'sets the colors back to the original backcolor
    161.     lblYellowButton.BackColor = &HC0C0&
    162.     lblRedButton.BackColor = &HC0&
    163.     lblGreenButton.BackColor = &H8000&
    164.     lblBlueButton.BackColor = &H800000
    165.     tmrColorBlinked.Enabled = False
    166.     tmrblink.Enabled = True
    167. End Sub
    168.  
    169. Private Sub nextRound()
    170.     'this sub procedure starts a new round of the game
    171.     'it pulls a new number out of the gameMemoryStack array
    172.     'and adds it to the memorystack
    173.     Dim i As Integer
    174.     memoryCounter = 0   'intitializes the memory counter
    175.     ReDim memoryStack(roundNumber)
    176.     MsgBox "Round " & roundNumber
    177.     For i = 0 To roundNumber - 1
    178.         memoryStack(i) = gameMemoryStack(i)            'fills the array to be tested
    179.     Next i
    180.     ReDim arrTemp(UBound(memoryStack))
    181.     'arrTemp() = reverseOrder(memoryStack)
    182.     tmrblink.Enabled = True                            'tells the color button to flash
    183.     Debug.Print "memcountend nxtrnd " & memoryCounter
    184. End Sub
    185. Private Sub MessageBox()
    186.     'Just a simple message box
    187.     Dim mbox As Integer
    188.     Dim title As String
    189.     Dim message As String
    190.     title = "Game Over"
    191.     message = "You got " & roundNumber & " correct"
    192.     mbox = MsgBox(message, , title)
    193. End Sub
    194.  
    195.  
    196. Private Sub colorSelect()
    197.     Select Case firstColor
    198.         Case "Yellow"
    199.             lblYellowButton.BackColor = vbYellow
    200.         Case "Red"
    201.             lblRedButton.BackColor = vbRed
    202.         Case "Blue"
    203.             lblBlueButton.BackColor = vbBlue
    204.         Case "Green"
    205.             lblGreenButton.BackColor = vbGreen
    206.     End Select
    207. End Sub
    [vbcode]
    Me as single
    myAttidude As Variant
    myPiece As Long
    woman As Object
    meAndHer As Date
    myBed As Double
    insideHer As Project
    [/vbcode]

  2. #2
    jim mcnamara
    Guest
    Code:
    Private Sub lblYellowbutton_click()
        Dim begColor As String
        Dim colorPush As String
        colorPush = "Yellow"
        Debug.Print UBound(memoryStack)
        If (colorPush = memoryStack(memoryCounter)) Then
           lastcolor = pop
           memoryCounter = memoryCounter + 1
           If UBound(arrTemp) = 0 Then
              roundNumber = roundNumber + 1
              Call nextRound
           End If
        Else
            End
        End If
    End Sub
    For pop should be memorycounter=memorycounter - 1

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