Results 1 to 8 of 8

Thread: [RESOLVED] Timer problem

  1. #1

    Thread Starter
    Junior Member
    Join Date
    May 2009
    Posts
    16

    Resolved [RESOLVED] Timer problem

    This code countdown from 10 seconds to 0 second,then capture image and save to the specific folder,and than countdown to -1,-2,-3 etc,but I don't wont thet count to -1,-2,-3 etc...
    I would like to do that when it comes to 0 seconds,that the timer countdown again from 10 second countdown to 0 and overvrite the image

    Can somebody explain me how to do it?Thanks for any help

    this is code

    Code:
    Public Class Form1
    
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            Dim SC As String = 0
            Label1.Text -= SC + 1
            If Label1.Text = 0 Then
            End If
            If Label1.Text = 0 Then
                Try
                    Dim scr As Size = New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
                    Dim screenGrab As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
                    Dim G As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(screenGrab)
                    G.CopyFromScreen(New Point(0, 0), New Point(0, 0), scr)
                    screenGrab.Save("C:\test.jpeg")
                Catch ex As Exception
                End Try
            End If
        End Sub
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Label1.Enabled = True
            Timer1.Start()
        End Sub
    
        Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
            Label1.Enabled = False
        End Sub
    End Class

  2. #2
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    Re: Timer problem

    Please turn option strict on first and fix all of the issues.

    When you take the screenshot, why not just set the label value back to 10, so it basically starts over after the screenshot is taken.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    May 2009
    Posts
    16

    Re: Timer problem

    Quote Originally Posted by Negative0 View Post

    When you take the screenshot, why not just set the label value back to 10, so it basically starts over after the screenshot is taken.
    Thaks for repay How should I set the value back to 10 after the screenshot is taken?
    Quote Originally Posted by Negative0 View Post
    Please turn option strict
    I am a beginer in vb net and I like to know what do you mean with "turn option strict"
    Thanks again

    I found this what do you mean an I tun on this option.
    Last edited by tony013; Oct 29th, 2009 at 03:33 AM.

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: Timer problem

    Option strict will dissallow implicit conversions, for one thing. This line, for instance, implicitly converts a number to a string:

    Label1.Text -= SC + 1

    It will work, but it is quite inefficient. Other implicit conversions, especially where you are working with strings and the + operator, may do something totally different from what you expect (because + can either concatenate two strings, or add two numbers, so you are hoping that it chooses what you want). Therefore, option strict will prevent some subtle bugs, as well as making the code run faster (though in this case you won't notice it).

    You can set Option Strict ON by going to the Compile tab on Project|Properties. Once you do this, you will get LOTS of errors in your code. Kind of a pain, but now is the time to learn good habits, and this is a VERY good habit.
    My usual boring signature: Nothing

  5. #5
    Addicted Member
    Join Date
    Oct 2009
    Location
    Clive, IA in America!!!!
    Posts
    204

    Re: Timer problem

    Try this:

    Code:
                Try
                    Dim scr As Size = New Size(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
                    Dim screenGrab As New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height)
                    Dim G As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(screenGrab)
                    G.CopyFromScreen(New Point(0, 0), New Point(0, 0), scr)
                    screenGrab.Save("C:\test.jpeg")
                    Me.Label1.Text = 10
                Catch ex As Exception
                End Try

  6. #6

    Thread Starter
    Junior Member
    Join Date
    May 2009
    Posts
    16

    Re: Timer problem

    Thanks,this is working good.Thanks again for help

  7. #7
    Hyperactive Member
    Join Date
    Jun 2007
    Posts
    280

    Re: Timer problem

    Quote Originally Posted by Shaggy Hiker View Post
    Once you do this, you will get LOTS of errors in your code. Kind of a pain, but now is the time to learn good habits, and this is a VERY good habit.
    Nothing like the pain of trying to hunt down that very elusive bug. Learn to do it now. Some kinds of pain you can get over. Others will haunt you for life.
    Last edited by AsmIscool; Nov 2nd, 2009 at 04:41 AM.
    Slower than a crippled Vista
    More buggy than a fresh XP install
    Look! Down the road, some 50 miles behind the drunken snail.
    It's Ubuntu!

  8. #8

    Thread Starter
    Junior Member
    Join Date
    May 2009
    Posts
    16

    Re: Timer problem

    Quote Originally Posted by AsmIscool View Post
    Nothing like the pain of trying to hunt down that very elusive bug. Learn to do it now. Some kinds of pain you can get over. Others will haunt you for life.
    Thaks for advice

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