OK, that's better. Now let's get some new stuff done!
Today, we will explore creating our own SUB procedures. You've been using SUBS that VB automatically provides you: there's a SUB for form load, for a button click, etc etc.
BASICALLY, a SUB is kind of like a function, only it doesn't return a value; it just does something. We will create a sub that is started at form load, and is then called every 3 seconds using our old friend the Timer
We start by creating a new Project. Name it after yourself, plus the phrase "MySub"
On the Form, please add a label. You don't need to rename it, but let's set its font to a decent size, say about 35 or so.
In the form's code, you will be adding both a String array and an Integer variable, like so:
Dim OldAd( ) As String = {"On curves ahead", "remember sonny", "that rabbits foot", "didnt save the bunny", "BURMA SHAVE"} 'this is all one line
Dim PoemTick As Integer
Let's try to remember where this gets typed, OK?
OK, the next step is to create your very first sub. Really, all you have to do is type this:
Sub ReadPoem( )
This will automatically set up a place where you'll put in some code in a second
The next step is to add a control that will make this SUB called ReadPoem( ) happen at a regular interval. That's our old friend, the Timer. So drag one onto your form. Again, no need to rename it, just doubleclick on it and add this to it's code:
ReadPoem( ) This will make the sub happen at the interval you set in the Timer's property box (psssst, its at the lower right corner of the screen.) I set my interval at 3000 milliseconds
OK, so now let's add some actual code to your SUB:
If PoemTick < text =" OldAd(PoemTick)"> this will start you out at the beginning of the poem!
There, that ought to do it: run the program and see what you get!
Cheers,
Mr. L
Sunday, December 7, 2008
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment