Gentlemen: there's nothing left to do today except to upload ALL the projects that you have completed, so that I may do some honest grading during the vacation. I DO have to enter in your grades during the vacation -- happy happy, joy joy!!-- so make sure to give me EVERYTHING, including your personal project, which better be marked as such. Additionally, your zip file better have your first and last name on it before you upload.
Other than that,
WE AIN'T DOING JACK SQUAT!
Tuesday, December 23, 2008
Wednesday, December 17, 2008
Thursday December 18, part THREE
OK, one last thing, and then you get to play on your own with your Classes. This time, we are going to use a control created by a class to make an object out of another class, and put that object on our form. In other words, we can create objects whenever we want!
Here is how you do it:
A) Make a new Class called "BlueTextBox". Please name it correctly!!!
B) add the proper "inherits" statement for a TextBox -- see if you can figure out to do this by looking at inherit statements you've done before
C) Using the same proces I JUST SHOWEED YOU, set up a "Layout" SUB for this new Class. Here is what I want you to put inside that:
Text = "This is my new TextBox"
BackColor = Color.Blue
ForeColor = Color.Yellow
D) In the "PopItUp" SUB that you created earlier, you will add some code to make an object from this new Class, and then place that object on your Form
Dim myTextBox As New BlueTextBox( )
myTextBox.Location = New Point(200, 100)
myTextBox.Size = New Size(400, 55)
Form1.Controls.Add(myTextBox)
E) Run your program, and see if you can get that new custom built TextBox to appear when you click on your Label!
Once you have all of that going, do some exploration of your own, and see what else you can find out. MAKE SURE YOU POST A DISCUSSION ON WHAT YOU FIND!
Also, make sure to upload this new version of our project
Cheers,
Mr. L
Here is how you do it:
A) Make a new Class called "BlueTextBox". Please name it correctly!!!
B) add the proper "inherits" statement for a TextBox -- see if you can figure out to do this by looking at inherit statements you've done before
C) Using the same proces I JUST SHOWEED YOU, set up a "Layout" SUB for this new Class. Here is what I want you to put inside that:
Text = "This is my new TextBox"
BackColor = Color.Blue
ForeColor = Color.Yellow
D) In the "PopItUp" SUB that you created earlier, you will add some code to make an object from this new Class, and then place that object on your Form
Dim myTextBox As New BlueTextBox( )
myTextBox.Location = New Point(200, 100)
myTextBox.Size = New Size(400, 55)
Form1.Controls.Add(myTextBox)
E) Run your program, and see if you can get that new custom built TextBox to appear when you click on your Label!
Once you have all of that going, do some exploration of your own, and see what else you can find out. MAKE SURE YOU POST A DISCUSSION ON WHAT YOU FIND!
Also, make sure to upload this new version of our project
Cheers,
Mr. L
Thursday Dec 18, PART TWO
OK, now that we've made a MsgBox show up, let's see if we can add to that SUB:
A) Add a TextBox to your form the way you've always done: just drag it on there!
B) rename it "HardWired"
C) In the SUB procedure that you just created in your module, add this line of code:
Form1.HardWired.Text = "TASTE THE RAINBOW!!"
D) Run the program again, and see if the message shows up in your textbox
OK, that was pretty simple, so let's get right to PART THREE!
Cheers,
Mr. L
A) Add a TextBox to your form the way you've always done: just drag it on there!
B) rename it "HardWired"
C) In the SUB procedure that you just created in your module, add this line of code:
Form1.HardWired.Text = "TASTE THE RAINBOW!!"
D) Run the program again, and see if the message shows up in your textbox
OK, that was pretty simple, so let's get right to PART THREE!
Cheers,
Mr. L
Thursday December 18: Building on what we've already done PART ONE
Hey there hi there ho there!
Today, we will continue with our work with classes. We will build on the project we worked on yesterday, adding several modifications to it. After we have done that, I will ask you to do some exploration of what we have learned on your own. Here is what we will be adding:
A) You will make your label -- which is based on the Class called "RainBowLabel" -- do something by calling a SUB inside of a module. Then, I will show you how to do something else from within that same SUB procedure, and apply it to a control --in this case a textbox-- that you place on your form the way you've always done it: by just dragging it on to the form!
B) You will make a second Class, and use the "Layout" event to make that Class look a certain way
C) You will will use the Class that you made yesterday to create an object from the Class you just made in B), and then put that new object into your form.
HERE IS HOW YOU DO ALL THAT:
1) Re-open the project from yesterday
2) Add a new Class and name it "RainBowCalling"
3) Set up a SUB procedure in that module called
Public Sub PopItUp( )
4) Inisde that SUB, just put this one line of code:
MsgBox("You dont taste one bit like skittles!!")
5) make sure that you "CALL" that SUB from inside the Class "RainBowLabel" by
getting back into the code for the RainBowLabel class, getting into its event list from the left hand pulldown, then look for the "Click" event in the right hand pulldown
6) inside the new SUB that jumps up out of nowhere, put in this line of code"
MsgBox("You dont taste one bit like skittles!!")
7) Run the program, and click on your label to see if it works
When everybody has that done, we'll go onto Part Two
Cheers,
Mr. L
Today, we will continue with our work with classes. We will build on the project we worked on yesterday, adding several modifications to it. After we have done that, I will ask you to do some exploration of what we have learned on your own. Here is what we will be adding:
A) You will make your label -- which is based on the Class called "RainBowLabel" -- do something by calling a SUB inside of a module. Then, I will show you how to do something else from within that same SUB procedure, and apply it to a control --in this case a textbox-- that you place on your form the way you've always done it: by just dragging it on to the form!
B) You will make a second Class, and use the "Layout" event to make that Class look a certain way
C) You will will use the Class that you made yesterday to create an object from the Class you just made in B), and then put that new object into your form.
HERE IS HOW YOU DO ALL THAT:
1) Re-open the project from yesterday
2) Add a new Class and name it "RainBowCalling"
3) Set up a SUB procedure in that module called
Public Sub PopItUp( )
4) Inisde that SUB, just put this one line of code:
MsgBox("You dont taste one bit like skittles!!")
5) make sure that you "CALL" that SUB from inside the Class "RainBowLabel" by
getting back into the code for the RainBowLabel class, getting into its event list from the left hand pulldown, then look for the "Click" event in the right hand pulldown
6) inside the new SUB that jumps up out of nowhere, put in this line of code"
MsgBox("You dont taste one bit like skittles!!")
7) Run the program, and click on your label to see if it works
When everybody has that done, we'll go onto Part Two
Cheers,
Mr. L
Tuesday, December 16, 2008
Wed December 17: a more in-depth examination of classes
Greetings, exalted coders!
Today we will continue with our examination of classes, what they are and how they work. Let's start with the basic theory, since it seems to be a bit difficult to master, then we will move on to an example that proceeds bit by bit.
A) The Theory: ALL of Vb.net is based on Classes. Everything you see in your program starts out as a Class, EVERYTHING. That's all your Forms, all the controls you put on a form, every last bit.
Classes INHERIT from other classes. That is, they get features that other classes already have because they "derive" from those other classes. Kind of like the way I get my blue eyes & love for building things from my dad, and my love of reading and knack from gardening from my mom
You can create your own class, and give it features that the original class never dreamed of. My dad is a builder, but he never dreamed of building in code. My mom likes to garden, but HER gardens are like something from Martha Stewart. Mine look a lot more like "Little Shop of Horrors"
Classes are like blueprints: you use them to build objects, which are things you can actually see and use in your program. I'm already planning for next year's gardens; and next year, my "garden object" gets instantiated starting April 1st.
Classes can include functions, sub routines and calls to other functions and sub-routines that are inside separate modules. Because these modules are outside both your class, and whatever form you put your new object in, that new object can call those functions and subs, and DO stuff with them
OK, enough theory. Here's what I want you to do today:
A) create a new project called BasicallyClasses plus your name
B) Drag a Label onto Form1, and then lets look at its properties. A Label has lots and lots of them, including stuff like:
Text
BackColor
ForeColor
Name
Width
Height
and many many others. Some of these properties are "read only" meaning its pretty darned difficult to set them inside a Class -- but you can certainly try!
C) A label also has a lot of methods: things that a label can DO. You can see a great big honking list of them by getting into the code for your form, and setting the pulldown menu at the top left to "Label1", then opening the pulldown menu at the top right. Yup, there's craploads of stuff in there!
D) OK, now let's add a new class. Name this one "RainBowLabel" (Don't worry, you'll get to repeat this process later, and use your own name. Just humor me, m'Kay?)
E) Just below the "Public Class...." line, add an inherits line of code like so:
Inherits Windows.Forms.Label
F) Now lets look at the pulldown menus for this new class. The one at the left has an entry for "RainBowLabel events" Choose that. The one at the right will then list a bunch of stuff, including one for "Layout" Choose that one: it allows you to set some basic stuff for your label INSIDE the class.
G) Notice that when you do this, the program creates a new "Sub" for you. That's where today's code will go. Remember those properties you saw in the first Label you just drgged onto the form? Let's set some of those, like so:
Text = "Chlorophyllllll"
BackColor = Color.Green
ForeColor = Color.Blue
Name = "Green"
Width = "149"
Height = "20"
Please note that for some properties, you will get a message that it's "read only". This means you cannot set it here in the class. Or can you?
H) Get into the form load event for your Form, and add this:
Dim LabelOne As New RainBowLabel( ) 'create an object from the class
Me.Controls.Add(LabelOne) 'add the object to the Form
I) run the program and oh crap.....! Now what? Well, we forgot to tell the program how big your Label is and where we want it. So its basically got NO SIZE AT ALL, and its located NOWHERE on the form! Here's what I did to fix that:
Add this to the code inside your class:
Location = New Point(200, 200)
Size = New Size(400, 55)
This says that our Class recognizes that these two things exist, but notice we don't specify how big our label will be here in the class, although we could have.
Add this code to your "form load" (see if you can reason out where it should go exactly)
LabelOne.Location = New Point(200, 200)
LabelOne.Size = New Size(400, 55)
Now let's run it again and see what we get!
OK, that's enough for this part. Now what I want you to do is to repeat the process, and make a class that will create some other custom control for your form. Use the same steps that I showed you, and also, see what additional things you can do with it.
Cheers,
Mr. L
Today we will continue with our examination of classes, what they are and how they work. Let's start with the basic theory, since it seems to be a bit difficult to master, then we will move on to an example that proceeds bit by bit.
A) The Theory: ALL of Vb.net is based on Classes. Everything you see in your program starts out as a Class, EVERYTHING. That's all your Forms, all the controls you put on a form, every last bit.
Classes INHERIT from other classes. That is, they get features that other classes already have because they "derive" from those other classes. Kind of like the way I get my blue eyes & love for building things from my dad, and my love of reading and knack from gardening from my mom
You can create your own class, and give it features that the original class never dreamed of. My dad is a builder, but he never dreamed of building in code. My mom likes to garden, but HER gardens are like something from Martha Stewart. Mine look a lot more like "Little Shop of Horrors"
Classes are like blueprints: you use them to build objects, which are things you can actually see and use in your program. I'm already planning for next year's gardens; and next year, my "garden object" gets instantiated starting April 1st.
Classes can include functions, sub routines and calls to other functions and sub-routines that are inside separate modules. Because these modules are outside both your class, and whatever form you put your new object in, that new object can call those functions and subs, and DO stuff with them
OK, enough theory. Here's what I want you to do today:
A) create a new project called BasicallyClasses plus your name
B) Drag a Label onto Form1, and then lets look at its properties. A Label has lots and lots of them, including stuff like:
Text
BackColor
ForeColor
Name
Width
Height
and many many others. Some of these properties are "read only" meaning its pretty darned difficult to set them inside a Class -- but you can certainly try!
C) A label also has a lot of methods: things that a label can DO. You can see a great big honking list of them by getting into the code for your form, and setting the pulldown menu at the top left to "Label1", then opening the pulldown menu at the top right. Yup, there's craploads of stuff in there!
D) OK, now let's add a new class. Name this one "RainBowLabel" (Don't worry, you'll get to repeat this process later, and use your own name. Just humor me, m'Kay?)
E) Just below the "Public Class...." line, add an inherits line of code like so:
Inherits Windows.Forms.Label
F) Now lets look at the pulldown menus for this new class. The one at the left has an entry for "RainBowLabel events" Choose that. The one at the right will then list a bunch of stuff, including one for "Layout" Choose that one: it allows you to set some basic stuff for your label INSIDE the class.
G) Notice that when you do this, the program creates a new "Sub" for you. That's where today's code will go. Remember those properties you saw in the first Label you just drgged onto the form? Let's set some of those, like so:
Text = "Chlorophyllllll"
BackColor = Color.Green
ForeColor = Color.Blue
Name = "Green"
Width = "149"
Height = "20"
Please note that for some properties, you will get a message that it's "read only". This means you cannot set it here in the class. Or can you?
H) Get into the form load event for your Form, and add this:
Dim LabelOne As New RainBowLabel( ) 'create an object from the class
Me.Controls.Add(LabelOne) 'add the object to the Form
I) run the program and oh crap.....! Now what? Well, we forgot to tell the program how big your Label is and where we want it. So its basically got NO SIZE AT ALL, and its located NOWHERE on the form! Here's what I did to fix that:
Add this to the code inside your class:
Location = New Point(200, 200)
Size = New Size(400, 55)
This says that our Class recognizes that these two things exist, but notice we don't specify how big our label will be here in the class, although we could have.
Add this code to your "form load" (see if you can reason out where it should go exactly)
LabelOne.Location = New Point(200, 200)
LabelOne.Size = New Size(400, 55)
Now let's run it again and see what we get!
OK, that's enough for this part. Now what I want you to do is to repeat the process, and make a class that will create some other custom control for your form. Use the same steps that I showed you, and also, see what additional things you can do with it.
Cheers,
Mr. L
Sunday, December 14, 2008
Monday December 15: More fun with classes
Greetings, chattering code monkeys!
Today, you will be expected to do at least two separate yet equally important things:
A) Create a project that contains at least one form and three classes. Make darned sure that its named after yourself, plus the word "Three Classes". Each class must represent something that is unique, ands each one must DO something. At least one of the classes must contain at least two or more controls -- you can use a Panel to hold them all together if you wish
Each one of these classes must be instantiated somewhere on your form. In other words, you gotta use all the stuff you create! Once you're done with that, upload the project, and then....
B) Work on your personal project.
Happy coding!
Mr. L
Today, you will be expected to do at least two separate yet equally important things:
A) Create a project that contains at least one form and three classes. Make darned sure that its named after yourself, plus the word "Three Classes". Each class must represent something that is unique, ands each one must DO something. At least one of the classes must contain at least two or more controls -- you can use a Panel to hold them all together if you wish
Each one of these classes must be instantiated somewhere on your form. In other words, you gotta use all the stuff you create! Once you're done with that, upload the project, and then....
B) Work on your personal project.
Happy coding!
Mr. L
Thursday, December 11, 2008
Friday December 12: Coding with Class, PART TWO
OK, now I will show you something else I've done with my button: it calls a function inside a module, and then assigns the result to that TextBox on our form. Here's how I did it:
A) I made a new Module and called it "GoGetIt"
B) I added a Function to it that returns a String thtas random plucked from an array (sound familar?)
Module GoGetIt
Public Function RandomEvil( ) As String
Dim Letters() As String = {"an EVIL petting zoo?", "I want chicken, I want liver", "Meow mix, meow mix, please deliver", "I will call him...mini me", "Silence!", "I will not tolerate your insolence"}
Dim whichQuote As Integer = 0
Dim SayIt As String
Dim A As New Random 'set a random seed
whichQuote = A.Next(0, Letters.Length - 1) 'number of elements in the Letters array
SayIt = Letters(whichQuote)
Return SayIt
End Function
End Module
C) Then, in my code for the "redButton" class, I called that function by placing this line of code:
under the code that changes the buttons text and back color
Then, I sent the results of that Function to the TextBox on the Form:
Form1.TextBox1.Text = RandomEvil( )
A) I made a new Module and called it "GoGetIt"
B) I added a Function to it that returns a String thtas random plucked from an array (sound familar?)
Module GoGetIt
Public Function RandomEvil( ) As String
Dim Letters() As String = {"an EVIL petting zoo?", "I want chicken, I want liver", "Meow mix, meow mix, please deliver", "I will call him...mini me", "Silence!", "I will not tolerate your insolence"}
Dim whichQuote As Integer = 0
Dim SayIt As String
Dim A As New Random 'set a random seed
whichQuote = A.Next(0, Letters.Length - 1) 'number of elements in the Letters array
SayIt = Letters(whichQuote)
Return SayIt
End Function
End Module
C) Then, in my code for the "redButton" class, I called that function by placing this line of code:
RandomEvil( )
under the code that changes the buttons text and back color
Then, I sent the results of that Function to the TextBox on the Form:
Form1.TextBox1.Text = RandomEvil( )
So OK, show me something you can do with your button class. Or maybe make another class of your own. Your choice.
Cheers,
Mr. L
Friday December 12: Coding with Class, PART ONE
Greetings, chattering code monkeys!
Today we are less than a month's worth of classes away from programming in Java. In celebration of this upcoming event --and just because its Friday-- we are going to look at a concept that Visual Basic has more or less copied from Java in the first place: the Class.
Inherits Windows.Forms.Button
Private Sub redButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click 'this stuff is all on one line
'create a new button from your class
Dim myNewButton As New redButton( )
'what text does this button have?
myNewButton.Text = "Deep Thought"
'add the Button that is created from the class to the form
Me.Controls.Add(myNewButton)
Today we are less than a month's worth of classes away from programming in Java. In celebration of this upcoming event --and just because its Friday-- we are going to look at a concept that Visual Basic has more or less copied from Java in the first place: the Class.
In Java, everything is a class; the whole darned language is Class-based. And, ever since VB went to .NET framework, Visual Basic has classes too. A Class is kind of like a blueprint: you use them to create actual objects. You've been using them all along: if you create a new Project and get into the code for your form, the very first line of code is
"Public Class Form1"
Today we will create our own classes. You will start out simply, then branch off into your own creations. Here's how we will start:
A) Create a new Project named after yourself plus the phrase "Legos"
B) on the Form1 that you get, create a TextBox
C) We are going to create a new type of control that can go on your form, so the first step will be to create a Class. You do this by Clicking on the Project menu, then clicking on the menuitem "Add Class". I named mine redButton, since our new class will be based on the Button class that already exists in VB
D) You will notice that you will get an empty set of code that looks like this:
Public Class redButton
Public Class redButton
End Class
Since your new class will create a button, you need to tell the program that. So, the first line of code is as follows:
Inherits Windows.Forms.Button
Classes can inherit properties and methods and other cool stuff from other classes, kind of like how I inherited my father's blue eyes and low tolerance for liars. Our class will be able to use all the stuff that buttons have, including this:
Private Sub redButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click 'this stuff is all on one line
All buttons can be clicked. So will yours
The next step is to add something simple to that button click. How's about we start with its caption and color? Add this inside that click method thingamabob:
Text = "Whoo Hoo!""
BackColor = Color.Red
BackColor = Color.Red
The final step is to add this new type of button to your form. I did mine at Form Load:
'create a new button from your class
Dim myNewButton As New redButton( )
'what text does this button have?
myNewButton.Text = "Deep Thought"
'add the Button that is created from the class to the form
Me.Controls.Add(myNewButton)
This code adds the new kind of button to your form when you run the program, and not until then. You can also set its size and location like so:
'where on the form do we create this new button?
myNewButton.Location = New Point(100, 50)
'setting the size of the Button
myNewButton.Size = New Size(100, 55)
OK, let's run that thing and see if it works. Then I'm going to show you some other different stuff I've done with my button, and I will ask you to come up with some new stuff of your own.
Cheers,
Mr. L
Tuesday, December 9, 2008
Wed December 10: Actual for real randomness and pretty colors too!
Greetings VB coders!!!
Today we will make a project that does several things:
A) Creates truly random numbers that are DIFFERENT everytime you start the program
B) Sets a limit to which number values are used -- basically, the smallest and the largest used
C) Uses these random numbers to populate an empty array with values from another array
D) Uses a for loop (which we still seem to have some issues with, at least some of us)
Here's how we do it:
1) Start off by making a project called LottsaRandom, with your name appended to the end of it
2) Add two buttons and one TextBox to this project. Rename the first button to "Mustard", & change its text to Mustard as well. Rename the second button to "Ketchup", and change its text to read ketchup
3) rename the textbox to "codeSheet" and change its text to read "secret codes will go here"
4) get into the code for this project, and just below where it says "Public Class Form1" create the following:
a) an Integer variable called "whatChar"
b) a String array that has all 26 letters of the alphabet, AND the numerals 0 to 9 AND the characters ! @ # $
please not that each one of these items is an element in your String array. If you've forgotten how to make a String array, you have one as an example in our Ferris Bueller project
c) create an empty String array like this ----> Dim codes(7) As String
notice that this is also a String array, but it has spaces for elements, not actual elements. Think of an empty egg carton.
pause, take a breath, now for the real fun:
OK, so now we have to make a SUB procedure (remember those? it seems like just yesterday...)
This SUB has to be able to create truly RANDOM numbers, and it cannot start with the same random set of numbers every time!
PLUS, the random values must fall within a certain range. Why? Well, because we are trying to randomly pick out certain elements from the array that has stuff in it, and put them in the array that doesn't have anything yet. There are only 40 elements in the array that's filled, so we don't need to get random values going up to 100, or 100; that would make no sense
Here's how we do it:
Public Sub SevenRandomNumbers( )
Dim A As New Random 'set a random seed using the RANDOM class
Dim x As Integer 'set an integer to use in the loop
For x = 0 To 6 'go thru loop to fill codes array
whatChar = A.Next(0, 40) 'number of elements in the Letters array
codes(x) = whatChar 'whatever x value is, that element in the empty array is filled
Next x
End Sub
OK, so now how do we "call" that SUB procedure? Simple, we get into the code for the "mustard" button (mustard, seed, get it? Oh well.....) and we call that SUB. Then we use the results we get to fill the textbox, like so:
SevenRandomNumbers( ) 'call the sub
Dim x As Integer
For x = 0 To 6
codeSheet.Text = codeSheet.Text & codes(x) & " "
Next x
OK, that oughtta do it. Lets try and run that program, and see what we get!
Cheers,
Mr. L
Today we will make a project that does several things:
A) Creates truly random numbers that are DIFFERENT everytime you start the program
B) Sets a limit to which number values are used -- basically, the smallest and the largest used
C) Uses these random numbers to populate an empty array with values from another array
D) Uses a for loop (which we still seem to have some issues with, at least some of us)
Here's how we do it:
1) Start off by making a project called LottsaRandom, with your name appended to the end of it
2) Add two buttons and one TextBox to this project. Rename the first button to "Mustard", & change its text to Mustard as well. Rename the second button to "Ketchup", and change its text to read ketchup
3) rename the textbox to "codeSheet" and change its text to read "secret codes will go here"
4) get into the code for this project, and just below where it says "Public Class Form1" create the following:
a) an Integer variable called "whatChar"
b) a String array that has all 26 letters of the alphabet, AND the numerals 0 to 9 AND the characters ! @ # $
please not that each one of these items is an element in your String array. If you've forgotten how to make a String array, you have one as an example in our Ferris Bueller project
c) create an empty String array like this ----> Dim codes(7) As String
notice that this is also a String array, but it has spaces for elements, not actual elements. Think of an empty egg carton.
pause, take a breath, now for the real fun:
OK, so now we have to make a SUB procedure (remember those? it seems like just yesterday...)
This SUB has to be able to create truly RANDOM numbers, and it cannot start with the same random set of numbers every time!
PLUS, the random values must fall within a certain range. Why? Well, because we are trying to randomly pick out certain elements from the array that has stuff in it, and put them in the array that doesn't have anything yet. There are only 40 elements in the array that's filled, so we don't need to get random values going up to 100, or 100; that would make no sense
Here's how we do it:
Public Sub SevenRandomNumbers( )
Dim A As New Random 'set a random seed using the RANDOM class
Dim x As Integer 'set an integer to use in the loop
For x = 0 To 6 'go thru loop to fill codes array
whatChar = A.Next(0, 40) 'number of elements in the Letters array
codes(x) = whatChar 'whatever x value is, that element in the empty array is filled
Next x
End Sub
OK, so now how do we "call" that SUB procedure? Simple, we get into the code for the "mustard" button (mustard, seed, get it? Oh well.....) and we call that SUB. Then we use the results we get to fill the textbox, like so:
SevenRandomNumbers( ) 'call the sub
Dim x As Integer
For x = 0 To 6
codeSheet.Text = codeSheet.Text & codes(x) & " "
Next x
OK, that oughtta do it. Lets try and run that program, and see what we get!
Cheers,
Mr. L
Sunday, December 7, 2008
Tues December 9: SUBS are basically pretty cool!
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
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
Monday December 8: Part One
UPLOAD ALL YOUR FILES
NOW This includes the latest version of your project from last Thursday (see HERE) AND the mini-project where I asked you to combine two different techniques (also HERE)
As of this moment, I don't have these files from any of you. Nothing else will take place in this class until they are uploaded to our account at Box.net
Cheers, Mr. L
PS If the files in question have in fact been uploaded, by all means, please come to my desk and show me where they are.
NOW This includes the latest version of your project from last Thursday (see HERE) AND the mini-project where I asked you to combine two different techniques (also HERE)
As of this moment, I don't have these files from any of you. Nothing else will take place in this class until they are uploaded to our account at Box.net
Cheers, Mr. L
PS If the files in question have in fact been uploaded, by all means, please come to my desk and show me where they are.
Wednesday, December 3, 2008
Thurs, Dec. 4: What's next
greetings, one and all,
Today, you only have to do two things:
A) finish up the assignment from yesterday and upload both that little creation of yours, AND the "jukebox" project from THIS assignment
B) work on your personal project, and upload a version of that today BEFORE the end of class
Cheers,
Mr. L
PS I am attempting to find some alternatives to the file hosting we have at Box.net I may ask some of you to participate in an experiment for this very purpose. I will appreciate your full cooperation in this effort.
Today, you only have to do two things:
A) finish up the assignment from yesterday and upload both that little creation of yours, AND the "jukebox" project from THIS assignment
B) work on your personal project, and upload a version of that today BEFORE the end of class
Cheers,
Mr. L
PS I am attempting to find some alternatives to the file hosting we have at Box.net I may ask some of you to participate in an experiment for this very purpose. I will appreciate your full cooperation in this effort.
Tuesday, December 2, 2008
Wed December 3: part two
OK, now that you've put together sound and comboboxes, I want you to repeat the process by doing this: put together in a project two things you've never made work together before. At least one of the controls you use should be something that has been demonstrated in this class. When you have done it, please post a discussion to our Google group describing what it is that you did. please include all relevant code.
When you are done with this, please upload the Jukebox project you made, then carry on with the personal project you are tending to.
Cheers,
Mr. L
When you are done with this, please upload the Jukebox project you made, then carry on with the personal project you are tending to.
Cheers,
Mr. L
Wed December 3: Something Old Something new
Greetings, chattering code monkeys!
Today we are going to do at least two things before you get after your personal projects. This posting is about the first one; there'll be a second posting in short order.
WHAT TO DO:
A) create a new project, and name it after yourself plus the phrase "JukeBox"
B) To this form, add a button and a combobox. Change the text on the button to "Play"
C) get into the combobox's properties sheet, select the "collections" thingamabob, then add these items to it:
Cars
Girl U Want
Musique Automatique
I Gotta Wear Shades
these are the names of some songs I have for you in the VB Depot folder. Please note that they are .wav files, as VB will not play mp3s, at least not that I've seen
D) OK, now to get some code monkeyin' done! get into your code, and just beneath
"Public Class Form1" add in a String variable named "DaFolder", another String variable called "MySong" and a String Array called Songs( ) that has as its elements the names of those songs you just put into the combobox. Make sure to add the .wav extension at the end of each filename
E) In your "Form Load" event, you will set the value of "DaFolder" to wherever you are going to store the .wav files. Make sure you set the full pathname!
F) OK, so that was all old stuff. There wasn't one thing on there that we haven't done before. Now for the new stuff! We are going to make use of a property of your combobox called "SelectedIndex". The items in a ComboBox are listed the same way as the elements in an array: they start at ZERO. So it's pretty easy to use this to select a certain element from an array, say an Array of song names. Here's how I did it in the button click event:
'make sure that a song has been chosen
If ComboBox1.SelectedIndex < 0 Then
MsgBox("Please choose a song!")
Else
'set up default VB wav player
Dim Sound As New System.Media.SoundPlayer( )
'establish where the sound folder is
'and then pick a sound from that folder by the array
MySong = Songs(ComboBox1.SelectedIndex)
Sound.SoundLocation = DaFolder & MySong
'load and then play the sound!
Sound.Load( )
Sound.Play( )
OK, now here's the tricky part: I couldn't upload the song files, because they are too big to fit on Box.net. I will try to put them in the H drive, but failing that, I have them on a couple of thumb drives
Cheers,
Mr. L
PS there will be second part of this lesson -- be looking for it!
Today we are going to do at least two things before you get after your personal projects. This posting is about the first one; there'll be a second posting in short order.
WHAT TO DO:
A) create a new project, and name it after yourself plus the phrase "JukeBox"
B) To this form, add a button and a combobox. Change the text on the button to "Play"
C) get into the combobox's properties sheet, select the "collections" thingamabob, then add these items to it:
Cars
Girl U Want
Musique Automatique
I Gotta Wear Shades
these are the names of some songs I have for you in the VB Depot folder. Please note that they are .wav files, as VB will not play mp3s, at least not that I've seen
D) OK, now to get some code monkeyin' done! get into your code, and just beneath
"Public Class Form1" add in a String variable named "DaFolder", another String variable called "MySong" and a String Array called Songs( ) that has as its elements the names of those songs you just put into the combobox. Make sure to add the .wav extension at the end of each filename
E) In your "Form Load" event, you will set the value of "DaFolder" to wherever you are going to store the .wav files. Make sure you set the full pathname!
F) OK, so that was all old stuff. There wasn't one thing on there that we haven't done before. Now for the new stuff! We are going to make use of a property of your combobox called "SelectedIndex". The items in a ComboBox are listed the same way as the elements in an array: they start at ZERO. So it's pretty easy to use this to select a certain element from an array, say an Array of song names. Here's how I did it in the button click event:
'make sure that a song has been chosen
If ComboBox1.SelectedIndex < 0 Then
MsgBox("Please choose a song!")
Else
'set up default VB wav player
Dim Sound As New System.Media.SoundPlayer( )
'establish where the sound folder is
'and then pick a sound from that folder by the array
MySong = Songs(ComboBox1.SelectedIndex)
Sound.SoundLocation = DaFolder & MySong
'load and then play the sound!
Sound.Load( )
Sound.Play( )
OK, now here's the tricky part: I couldn't upload the song files, because they are too big to fit on Box.net. I will try to put them in the H drive, but failing that, I have them on a couple of thumb drives
Cheers,
Mr. L
PS there will be second part of this lesson -- be looking for it!
Subscribe to:
Comments (Atom)
