Results 1 to 2 of 2

Thread: [RESOLVED] Weird loop...

  1. #1

    Thread Starter
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Resolved [RESOLVED] Weird loop...

    Hi there,

    I've written the following code and it works fine till 'y' hits 9. There it seems to skip the if statements and continue the loop.

    Given data:
    - b_x and b_y are '4'
    - v_x and v_y are declared
    - x and y are also looped, but in another sub

    Code:
        '// Define sample area
        For v_x = (x - b_x) To (x + b_x)
        
            For v_y = (y - b_y) To (x + b_y)
                
                '// If current pixel coordinate is not negative get the colorvalue
                If v_x > -1 And v_y > -1 Then
                    
                    If v_x = x And v_y = y Then
                    
                    Else
                    
                        currHex = GetPixel(picOriginal.hdc, v_x, v_y)
                        currRGB = Hex2RGB(currHex)
                        
                        currSample.Average_Red = currSample.Average_Red + currRGB.Red
                        currSample.Average_Green = currSample.Average_Green + currRGB.Green
                        currSample.Average_Blue = currSample.Average_Blue + currRGB.Blue
                        currSample.SampleCount = currSample.SampleCount + 1
                        pb2.Value = pb2.Value + 1
                        DoEvents
                    
                    End If
                    
                End If
                
            Next v_y
            
        Next v_x
    I'd appreciate some help on this
    Delete it. They just clutter threads anyway.

  2. #2

    Thread Starter
    Frenzied Member TheBigB's Avatar
    Join Date
    Mar 2006
    Location
    *Stack Trace*
    Posts
    1,511

    Re: Weird loop...

    Forget it...

    I forgot to change an x to a y.
    That's the problem with copying and pasting...

    Code:
        '// Define sample area
        For v_x = (x - b_x) To (x + b_x)
        
            For v_y = (y - b_y) To (y + b_y)
                
                '// If current pixel coordinate is not negative get the colorvalue
                If v_x > -1 And v_y > -1 Then
                    
                    If v_x = x And v_y = y Then
                    
                    Else
                    
                        currHex = GetPixel(picOriginal.hdc, v_x, v_y)
                        currRGB = Hex2RGB(currHex)
                        
                        currSample.Average_Red = currSample.Average_Red + currRGB.Red
                        currSample.Average_Green = currSample.Average_Green + currRGB.Green
                        currSample.Average_Blue = currSample.Average_Blue + currRGB.Blue
                        currSample.SampleCount = currSample.SampleCount + 1
                        pb2.Value = pb2.Value + 1
                        DoEvents
                    
                    End If
                    
                End If
                
            Next v_y
            
        Next v_x
    Delete it. They just clutter threads anyway.

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