Results 1 to 4 of 4

Thread: Exit a sub problem

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    78

    Exclamation Exit a sub problem

    Hi again,

    i have a sub that every time it detects a motion a beep sounds. Because is a pixel to pixel comparison i didn`t find a way to stop the sub at the very first motion detection so i can prompt just one msgbox.

    If i type the msgbox just like that in the sub every time it detects motion it prompts a new msgbox filling the screen.

    Any suggestions?

    Thanks

  2. #2
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: Exit a sub problem

    You havent really given enough detail but can you not just do this when you find that a pixel has changed?
    vb Code:
    1. Exit Sub
    or if you are comparing the pixels in a FOR loop of some sort then:
    vb Code:
    1. Exit For

    If thats not helpful then you need to explain what exactly you are doing with this pixel by pixel comparison
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2009
    Posts
    78

    Re: Exit a sub problem

    Basically i`m comparing the three basic colors (RGB). Now i want for the first time of motion detection to exit this loop so i can prompt an msgbox!


    If FirstFrame.GetPixel(x, y).R >= SecondFrame.GetPixel(x, y).R - Sensitivity And FirstFrame.GetPixel(x, y).R <= SecondFrame.GetPixel(x, y).R + Sensitivity Then
    If FirstFrame.GetPixel(x, y).G >= SecondFrame.GetPixel(x, y).G - Sensitivity And FirstFrame.GetPixel(x, y).G <= SecondFrame.GetPixel(x, y).G + Sensitivity Then
    If FirstFrame.GetPixel(x, y).B >= SecondFrame.GetPixel(x, y).B - Sensitivity And FirstFrame.GetPixel(x, y).B <= SecondFrame.GetPixel(x, y).B + Sensitivity Then
    ' well erm do nothing
    Else
    are_identical = False

    End If

    Else
    are_identical = False

    End If

    Else

    are_identical = False

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Exit a sub problem

    The first thing to note is the inefficiency of that code. GetPixel is slow and you're calling GetPixel on the same two cootdinates six times each. That's not good. You should be calling GetPixel once for each frame. You then just need one If block, not three:
    vb.net Code:
    1. Dim firstColour As Color = firstFrame.GetPixel(x, y)
    2. Dim secondColour As Color = secondFrame.GetPixel(x, y)
    3.  
    4. If firstColour.R < secondColour.R - sensitivity OrElse _
    5.    firstColour.R > secondColour.R + sensitivity OrElse _
    6.    firstColour.G < secondColour.G - sensitivity OrElse _
    7.    firstColour.G > secondColour.G + sensitivity OrElse _
    8.    firstColour.B < secondColour.B - sensitivity OrElse _
    9.    firstColour.B > secondColour.B + sensitivity Then
    10.     areIdentical = False
    11. End If
    In fact, you don't need any If blocks at all:
    vb.net Code:
    1. Dim firstColour As Color = firstFrame.GetPixel(x, y)
    2. Dim secondColour As Color = secondFrame.GetPixel(x, y)
    3.  
    4. areIdentical = firstColour.R >= secondColour.R - sensitivity AndAlso _
    5.                firstColour.R <= secondColour.R + sensitivity AndAlso _
    6.                firstColour.G >= secondColour.G - sensitivity AndAlso _
    7.                firstColour.G <= secondColour.G + sensitivity AndAlso _
    8.                firstColour.B >= secondColour.B - sensitivity AndAlso _
    9.                firstColour.B <= secondColour.B + sensitivity
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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