how can i simplify this code

code works but it seems to much

Page 1 of 1

1 Replies - 817 Views - Last Post: 07 April 2008 - 05:00 PM Rate Topic: -----

#1 sherrill  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 27-March 08

how can i simplify this code

Posted 07 April 2008 - 11:15 AM

how can i simplify this code and clean it up?
this is a loop to calculate which numbers match

' Calculate the numbers that match.
        Dim intCount As Integer                 ' Loop counter
        Dim intWin As Integer = 0               ' Digits match counter
        Dim intMatching As Integer = -1         ' All numbers match counter

        'Sets the Booleans and initializes.
        Dim intMatch1 As Boolean = False
        Dim intMatch2 As Boolean = False
        Dim intMatch3 As Boolean = False
        Dim intMatch4 As Boolean = False
        Dim intMatch5 As Boolean = False

        ' Looks for matching numbers
        For intCount = 0 To intMAX_VALUES
            If intDigits(0) = intNumber(intCount) And intMatch1 = False And intMatching <> intCount Then
                intWin = intWin + 1
                intMatch1 = True
                intMatching = intCount
            End If
            If intDigits(1) = intNumber(intCount) And intMatch2 = False And intMatching <> intCount Then
                intWin = intWin + 1
                intMatch2 = True
                intMatching = intCount
            End If
            If intDigits(2) = intNumber(intCount) And intMatch3 = False And intMatching <> intCount Then
                intWin = intWin + 1
                intMatch3 = True
                intMatching = intCount
            End If
            If intDigits(3) = intNumber(intCount) And intMatch4 = False And intMatching <> intCount Then
                intWin = intWin + 1
                intMatch4 = True
                intMatching = intCount

            End If
            If intDigits(4) = intNumber(intCount) And intMatch5 = False And intMatching <> intCount Then
                intWin = intWin + 1
                intMatch5 = True
                intMatching = intCount
            End If
        Next


*edit: Please use code tags in the future, thanks! :code:

This post has been edited by Martyr2: 07 April 2008 - 11:29 AM


Is This A Good Question/Topic? 0
  • +

Replies To: how can i simplify this code

#2 jeronimo0d0a  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 146
  • Joined: 03-March 08

Re: how can i simplify this code

Posted 07 April 2008 - 05:00 PM

This would look cleaner as a "select case" or nested for loops with intMatch(5)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1