Greetings, O keepers of the Microsoft code!
Today, we are going to accomplish three great and wonderful goals:
A) Learn the basics of using the TIMER control, and apply it to something useful
B) See if you can apply the techniques you've learned to make something else happen at a regular interval, guided by a timer.
MAKE A DISCUSSION POST ON OUR GROUP STATING WHAT YOU DID HERE
C) work on your individual projects -- and be sure to UPLOAD both of todays projects to the "VBDEPOT" folder at BOX.net
Right then, let's start with the first one. Here's what you have to do
1) start up a new project and name it after yourself plus the phrase "TimingX"
2) Add a label to Form1. You DON'T have to rename it, but you DO have to change the text and the font size. Make the size at least "42"; make the text say basically whatever you want, as long as its school appropriate
3) Set the Label's "visible" property to FALSE
4) Add a TIMER control to your form by dragging it from the toolbox onto to the Form. Set its "Interval" property to 1000, which means the same as one second
5) get into the TIMER code by doubleclicking on it. Add this code snippet:
' this calls a function named "secret word" thats stored in a module
SecretWord( )
6) OK, so now you need a function and a module to put it in. So, first things first, add a Module -- if you don't know how, ask your buddy, not me -- we've already done this several times now!
7) In the module, you are going to create a function that will make the Label appear and disappear according to what interval is set in the timer. Like any good function, it will need to return a variable. Since we're dealing with a "visible/hidden" situation, we will only need two states, ON and OFF. so your variable will be a boolean.
8) Here is the way I set up this function. Try it my way; or if you feel daring, try another way of doing this same thing:
Public Function SecretWord( ) As String
'the on or off variable
Dim OnOff As Boolean = False
'if the Label is hidden, then show it!
If Form1.Label1.Visible = False Then
Form1.Label1.Visible = True
OnOff = True
'if you can see the Label then HIDE it!
Else
Form1.Label1.Visible = False
OnOff = False
End If
'return the value of the variable
Return OnOff
End Function
9) Finally, get back into Form1, and this to its LOAD statement:
Timer1.Enabled = True 'make sure the timer is turned on
SecretWord( ) 'call the function the first time
OK, let's see if we can get that to work! I will come around to see if you've got it right. Once you've mastered that, I want to see you make a timer do something different: your choice as to what different will mean.
The rest of the class will be yours
Cheers,
Mr. L
Wednesday, November 19, 2008
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment