Results 1 to 9 of 9

Thread: Timer Control Confusion

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2005
    Posts
    12

    Resolved Timer Control Confusion

    I have confused myself with timer controls. I am trying to display text in a label when the program runs, at a font size of 10 as set in that label property font option. Then every 2 seconds I want the text to increase by 5 points and the font size printout to show the font size in points as it changes. Once the font size gets to 70 I want it to decrease by 5 points every two seconds. Then repeat the process once it gets to 100 again.

    All that happens when I run this is the text jumps to 13.25 points at two seconds and nothing happens after that.

    Am I correct that with thetimer event it should run the code every two seconds until something forces it to stop??

    Any help would be appreciated.

    tyanx..........b.
    Last edited by bushmonkeys; Jan 7th, 2005 at 09:57 PM.

  2. #2
    Addicted Member
    Join Date
    Nov 2004
    Posts
    171

    Re: Timer Control Confusion

    Post the code. And the property settings on the timer. I should be able to help you then.
    Sherminator ~ I'll be back.

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: Timer Control Confusion

    Try this.

    VB Code:
    1. Private Sub Command1_Click()
    2. Timer1.Interval = 2000
    3. Timer1.Enabled = True
    4. End Sub
    5.  
    6.  
    7. Private Sub Timer1_Timer()
    8. Label1.Font.Size = Label1.Font.Size + 5
    9. End Sub

  4. #4

    Thread Starter
    New Member
    Join Date
    Jan 2005
    Posts
    12

    Re: Timer Control Confusion

    I can;t believe I forgot to paste the code.....duh!!

    Here it is

    Private Sub Form_Load()
    'define variables
    Dim strText1 As String
    Dim strText2 As String
    Dim strText3 As String


    'initialize variables to be displayed on form load
    strText1 = "This is string of text 1"
    strText2 = "This is string of text 2"
    strText3 = "This is string of text 3"


    'place the text on the screen at run time
    lblText1.Caption = strText1 & vbCrLf & _
    strText2 & vbCrLf & _
    strText3

    'display font height in points in lblText3 area on run
    'display text is set at font size of 10 in label area properties font value
    lblText3.Caption = "10"


    End Sub



    Private Sub tmrCount_Timer()
    If (lblText1.FontSize >= 10) Or (lblText1.FontSize <= 70) Then

    'change text size by 5 in text area 1 to the right of timer (not seen)every 2 seconds as set in timer properties interval
    lblText1.FontSize = FontSize + 5

    'change text size by 5 shown in text area 3 every 5 seconds
    lblText3.Caption = FontSize + 5

    Else
    If (lblText1.FontSize < 10) Or (lblText1.FontSize >= 70) Then

    'change text size by 5 in text area 1 to the right of timer (not seen)every 2 seconds as set in timer properties interval
    lblText1.FontSize = FontSize - 5

    'change text size by 5 shown in text area 3 every 5 seconds
    lblText3.Caption = FontSize - 5
    End If


    End If
    End Sub

  5. #5
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Timer Control Confusion

    Perhaps this sample will work for you:
    VB Code:
    1. Option Explicit
    2.  
    3. Dim blnIncrease As Boolean
    4.  
    5. Private Sub Command1_Click()
    6.     blnIncrease = True
    7.     Label1.AutoSize = True
    8.     Timer1.Enabled = True
    9.     Timer1.Interval = 2000 '2 seconds
    10. End Sub
    11.  
    12. Private Sub Form_Load()
    13.     Timer1.Enabled = False
    14.     Label1.FontSize = 10
    15. End Sub
    16.  
    17. Private Sub Timer1_Timer()
    18. Static iFontSize%
    19.  
    20.     If iFontSize = 0 Then iFontSize = Label1.FontSize
    21.     If blnIncrease Then
    22.         iFontSize = iFontSize + 5
    23.     Else
    24.         iFontSize = iFontSize - 5
    25.     End If
    26.     If iFontSize = 70 Then
    27.         blnIncrease = False
    28.     ElseIf iFontSize = 10 Then
    29.         blnIncrease = True
    30.     End If
    31.    
    32.     Label1.FontSize = iFontSize
    33.  
    34. End Sub

  6. #6

    Thread Starter
    New Member
    Join Date
    Jan 2005
    Posts
    12

    Re: Timer Control Confusion

    So I see that you are using a button to start the timer event. Do I need to do that ? I just wanted it to start when the app loads??

    Some of the code is more advanced than I have learned so far> can you explain the lines below:

    Option Explicit

    Static iFontSize%

    thanx.....b.

  7. #7
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Timer Control Confusion

    If you want to start timer when application strats - "move" code from command1_click event to Form_Load.
    VB Code:
    1. Private Sub Form_Load()
    2.     blnIncrease = True
    3.     Label1.FontSize = 10
    4.     Label1.AutoSize = True
    5.     Timer1.Enabled = True
    6.     Timer1.Interval = 2000 '2 seconds
    7. End Sub
    Option Explicit - could be found in Tool -> Options ... it means that every variable in a current module (form, standard module, class module, etc) must be explicitely declared

    Static iFontSize% - integer type variable declared as static (available only in local procedures) so it will previous value. Advantage: you don't have to declare variable as public (global).

  8. #8

  9. #9
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Timer Control Confusion

    NO NO NO

    % stands for INTEGER and that's what was needed.
    also
    $ - string type
    & - long ... and so on ...

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