|
-
Jan 6th, 2005, 08:07 PM
#1
Thread Starter
New Member
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.
-
Jan 6th, 2005, 08:22 PM
#2
Addicted Member
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.
-
Jan 6th, 2005, 08:39 PM
#3
Re: Timer Control Confusion
Try this.
VB Code:
Private Sub Command1_Click()
Timer1.Interval = 2000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Label1.Font.Size = Label1.Font.Size + 5
End Sub
-
Jan 6th, 2005, 08:41 PM
#4
Thread Starter
New Member
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
-
Jan 6th, 2005, 08:43 PM
#5
Re: Timer Control Confusion
Perhaps this sample will work for you:
VB Code:
Option Explicit
Dim blnIncrease As Boolean
Private Sub Command1_Click()
blnIncrease = True
Label1.AutoSize = True
Timer1.Enabled = True
Timer1.Interval = 2000 '2 seconds
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Label1.FontSize = 10
End Sub
Private Sub Timer1_Timer()
Static iFontSize%
If iFontSize = 0 Then iFontSize = Label1.FontSize
If blnIncrease Then
iFontSize = iFontSize + 5
Else
iFontSize = iFontSize - 5
End If
If iFontSize = 70 Then
blnIncrease = False
ElseIf iFontSize = 10 Then
blnIncrease = True
End If
Label1.FontSize = iFontSize
End Sub
-
Jan 6th, 2005, 09:45 PM
#6
Thread Starter
New Member
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.
-
Jan 6th, 2005, 09:58 PM
#7
Re: Timer Control Confusion
If you want to start timer when application strats - "move" code from command1_click event to Form_Load.
VB Code:
Private Sub Form_Load()
blnIncrease = True
Label1.FontSize = 10
Label1.AutoSize = True
Timer1.Enabled = True
Timer1.Interval = 2000 '2 seconds
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).
-
Jan 6th, 2005, 10:08 PM
#8
Re: Timer Control Confusion
But instead of Static iFontSize%, do Static iFontSize As String instead. % (which indicates a string) is old-fashioned and not as clear as String.
-
Jan 6th, 2005, 10:10 PM
#9
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|