Tuesday, December 23, 2008

Tues Dec. 23: Please hand in ALL your projects as a zip file!

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!

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

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

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

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

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

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:



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.



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


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


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

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

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.

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.

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

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!

Thursday, November 20, 2008

Fri Nov 21: Using combox boxes

Greetings, fellow code monkeez,

Today being Friday and all, I thought that we should keep things as simple yet as informative as possible. Plus, I wanted to introduce you all to a couple of extremely useful controls:

A) the PANEL

B) the combobox aka, "pulldown menu"

A panel is good for holding other controls together as if they functioned as one unit. Combo boxes are good for holding lists of items in a visible fashion, so you can see them and use them. We are going to make use of both today. I will show you how the first time around, then you will find some other uses for BOTH these controls

OK, lets launch into this, shall we?

Step A) start up a new project and call it PullDowns

Step B) Add a button to your new form, and set its text to say "Shaazaam!"

Step C) Next, add a Panel to your form. Make it as big as possible without overlapping the Button you just made. Set its background color to red or blue or green or something bright. Set its visibility to "False"

Step D) Add a webbrowser control onto the Panel, and resize it so that it takes up most of the room inside the panel.

Step E) drag a combobox onto the Panel, and set it just above the webbrowser control

Now to set some properties and add some simple code. Here are the next steps:

Step F) your ComboBox has a property called "ITEMS"; next to it is the word "Collections" followed by a little button with dots on it. Click on that button

Step G) This pops up a place where you can add items to your combobox, similar to the way you added items to your menus the other day. Our collections list is going to consist of webpage addresses, something like this:

http://www.thinkgeek.com/
http://www.bittorrent.com/
http://www.limewire.com/

By all means, set your website addresses to whatever you want, as long as they are school appropriate

Step H) Doubleclick on the combobox to get into its code. We are going to use the items in the combobox to direct the webbrowser control to display a webpage. The code for it is pretty simple:

MsgBox(ComboBox1.SelectedItem)
WebBrowser1.Navigate(New Uri(ComboBox1.SelectedItem))

Step I) Now, add this code to that button you made:
Panel1.Visible = True

RUN your program to verify that it works; I will be observing you through LanSchool. Once you have mastered this, I want you to be able to prove what you know by using both a combobox and a panel in some other way. PLEASE POST A DISCUSSION ON HOW YOU DID THIS.

Please upload this new mini project, then you may return to work on your project, which you will also upload before the class is done.

Cheers,
Mr. L

Wednesday, November 19, 2008

Thurs Nov 20: Time to Clock OUT!!!

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

Tuesday, November 18, 2008

Tues Nov 18: kicking butt, taking names

Or words to that effect! Hello, and welcome back. Today, you will be allowed time to work on your individual projects again. Pleae make sure that you upload them to our "Depot" folder sometime before the end of class.

Additionally, I would like each of you to think of a specific request for a technique you would like to master. Please do so in the form of a discussion post, and title it your name plus "basically requests". I will do my best to incorporate theese requests into the curriculum, so please be sure that your request are as precise and as specific as possible. Remember, when the great computer was asked the question "what is the meaning of life, the universe and everything?" it took a million years for it to come back with the answer "42"

Nuff said!

Mr. L

Sunday, November 16, 2008

Mon Nov. 17: finishing up and moving on

Greetings, buccaneers of code,

Today you will need to do things:

A) Make absolutely sure that ALL the bugs have been worked out of your "Menus" mini-projects from last Friday. They should work as fully functioning webpage editors by now; when they do, please upload them to our folder on Box.net. Make sure they are named after yourself plus the word "menus"

B) Continue working on your own projects. Pass them in as well at least 3 to 4 minutes before the end of the class.

Cheers,
Mr. L

PS If you discover anything cool, please be sure to post a discussion on our Google group. If you have any long term difficulties, please be sure to email me at my gmail address.

Tuesday, November 11, 2008

Fri Nov 14: part two

OK, so as you may have guessed, what we're going to try to do is to be able to open up a webpage in your textbox, where you can change it's code. Then, you can save the changes, THEN you can open up this new improved webpage in a webbrowser so you can see the differences.

Now, here's the rest of the steps in how to do that:

A) Add a label to the bottom of Form1, somewhere underneath the textbox. No need to rename this either

B) Add this code to the "Open in Browser menu item code, just above the one line of code you already have there (ya know, the one that says Form2.visible = true)

'set the value of the current file being worked on into this Label
Label1.Text = theFileName
'call the function in the module that makes use of the text value of this label
'in assigning a URL to the webbrowser control in Form2
ShowInBrowser( )

C) Since we're going to be passing information from one form to another, it would easier to use a module. So, create a module by clicking on the "Project" menu, then clicking Add Module

D) In this module, you will need to add a simple function that will receive the value of the text in that new label you made, and return it as a String variable to Form2. Here's how my function looks:


Public Function ShowInBrowser( ) As String
Dim sendPageInfo As String
sendPageInfo = Form1.Label1.Text
Return sendPageInfo
End Function

E) Finally, you have to get into the code for the "Form Load" event for Form2. You should know how to get there already; when you do arrive, add this code to it:

'show which webpage we're loading into the browser
MsgBox(ShowInBrowser())
'make the browser go to the webpage we want
WebBrowser1.Navigate( New Uri(ShowInBrowser( ) ) )

OK, that should do it. Compile, make sure you gots no errors, then run the program. You should be able to open a webpage in your textbox so that you only see its code, you can change that code, save the changes then observe the changes by opening it in a browser you made yourself!

cheers,
Mr. L

PS If you need a webpage to play with, I uploaded one to the VBdepot folder on Box.net

Fri Nov 14: monkeying around with web pages and menus!

Hello all you kwazy kode monkeeeees,

Today, before you work on your projects, you are going to add some more functionality to your "menus" project. Specifically, You are going to be able to open up WEBPAGES inside your textbox, mod their code then pop up the way the new webpage looks in another form which you will add to this lil project.

Here's what to do:

A) you will need to add an IF statement to your save menu item. It's to prevent saving files with no extensions and no filenames. Please place it BEFORE all the code you have in the SAVE menu item:

If theFileName = "" Then
SaveFileDialog1.Filter = "Text files (*.txt)*.txtweb pages (*.html)*.html"
SaveFileDialog1.ShowDialog()
theFileName = SaveFileDialog1.FileName
End If

B) notice how I have modified the "filter" so that you can see both text files and web pages when you are saving. You will also modify the filter found in the OPEN and SAVE AS menu items, in exactly the same way.

C) Add a second form -- nope don't care if you rename this one

D) Add a webbrowser control to this form -- also no need to rename this control

E) get back into "Form1" and add this item to the file menu "Open in browser"

F) Doubleclick on that new menu item, and add just this snippet of code:

Form2.Visible = True


OK, so whatya got so far? Well, you have a new menu item that opens up a new form that has a web browser control on it. Also, we've chnaged the filters of all our menu items so they can see both text and web pages. Lets make sure it works before going on to the next step

Cheers,

Mr. L

Wed Nov 12: Ok alright, quit yer bellyachin' here's the rest of the code!

Just add this stuff underneath the rest of the code in your SAVE AS menu item

'dim another streamwriter variable
Dim newWordWriter As System.IO.StreamWriter
'make a new streamwriter and pass it the variable
'thats equal to whatever the OpenFileDialog found
newWordWriter = New System.IO.StreamWriter(theFileName)
'set text of the textbox to all the stuff found by the reader
newWordWriter.Write(MyWords.Text)
'shut down the writer
newWordWriter.Close( )

Cheers,
Mr. L

Wed Nov 12: modifying the SAVE menu item, part two

OK, so now we know how to create and save files, open them, mod them then save them.

NOW, it's time to be able to add a "Save As" menu item. Here's how you do it:


A) goto your "Toolbox" at the left scroll down and find the "SAVEFILEDIALOG". drag it onto to the space at the bottom fo your form, the one that already has your menustrip and your OpenFileDialog. No need to rename this control, just leave it as SaveFileDialog1


B) In your form, if you click once on the FILE menu header, you will see the whole list of menu items you've got

C) at the bottom, you will see a thing that says "Type Here" that's where you type in "SAVE AS".

D) Very carefully drag that item up above the EXIT and below the SAVE -- not that it really matters, but wouldn't it just bug the crap out of you if we left it there?

E) doubleclick on that menu item to get into its code, and then add this code block:

'this just gives a title to the dialog box
SaveFileDialog1.Title = "Save a Text File As......."
'this says what kind of file will be saved
SaveFileDialog1.Filter = "Text Files*.txt"
'this establishes that we are naming this thing the way it
'was until we decide to name it something else
SaveFileDialog1.FileName = theFileName
'this opens the SaveDialog, so you can save the file with its new name
SaveFileDialog1.ShowDialog( )
'when you change the name of the file,
'this changes the value of the variable
'that way, the StreamWriter writes to the new file
'not the original
theFileName = SaveFileDialog1.FileName

Cheers,
Mr. L

PS There's something missing at the end of this code. Try to guess what you might need to copy and paste from somewhere else in your code.

Wed Nov 12: modifying the SAVE menu item, part one

Hey there fellow coders!

Here's how we can dramatically revamp your menu project, so that you can open an existing file, make some changes to it, then save the changes to that SAME file, in it's same location.

Here's what you do:

A) MOVE this line of code

Dim theFileName As String

from the place its in now to just below "Public Class Form1"
that way both the "Open" and "Save" menu items will be able to use it :-)

B) rip out all that crap that we have in the current SAVE menu item code, and replace it with this:

'dim a streamwriter variable
Dim wordWriter As System.IO.StreamWriter
'make a new streamwriter and pass it the variable
'thats equal to whatever the OpenFileDialog found
wordWriter = New System.IO.StreamWriter(theFileName)
'set text of the textbox to all the stuff found by the reader
wordWriter.Write(MyWords.Text)
'shut down the writer
wordWriter.Close( )

I swear to GOD, it really is that simple! Let's make sue that all have it working, OK?

Cheers,
Mr. L

Saturday, November 8, 2008

Mon Nov. 10: more menu fun, Part The Third

OK, now its time to get serious: it's all well and good to FIND a file, but we want to load it into the textbox on our form. Otherwise, what's the point? So here's what we need to do that:

a "reader" of some kind. We've already used file "writers" to create files and put stuff in them. This is kind of the same only in reverse. Here's what you gotta add to yer code:

'dim a streamreader variable
Dim wordReader As System.IO.StreamReader

'make a new streamreader and pass it the variable
'thats equal to whatever the OpenFileDialog found
wordReader = New System.IO.StreamReader(theFileName)

'set text of the textbox to all the stuff found by the reader
MyWords.Text = wordReader.ReadToEnd

'shut down the reader
wordReader.Close( )

OK, so lets see if you can use this to open a file inside your textbox. Try it out, and understand that it will ONLY look for "Notepad" type files.

As you can see, I have extensively COMMENTED my code, so its pretty darned obvious what the heck all this stuff is for. Ahem!! And btw, I have a final message to Mr. Octopus, Mr. Crab, Mr. StarFish, Mr. Sponge, etc etc etc: you got ZERO credit for the commenting assignment. I don't have the time to figure out who those names are supposed to mean


Cheers,
Mr. L

Mon Nov. 10: more menu fun, Part The Second

OK, now you've got a FileOpen thing going on, but it doesn't do very much. So let's remedy that: let's make it so it can find a file, and when you click on it, a Message box pops up that says the name of the file and where it is located. Add this code just BELOW where the other code went.

'this allows you to create a filename based on what you've chosen
Dim theFileName As String
theFileName = OpenFileDialog1.FileName
MsgBox(theFileName)

All this code does is make a String variable (useful for words and text and such) and then sets that variable equal to whatever is chosen in the OpenFile thingy. Then, it passes this to a MsgBox, which pops up to tell you what you've chosen

Make sure this works, then we will move on to the third and final installment

Cheers,
Mr. L

Mon Nov. 10: more menu fun, Part The First

Gr33tings krazy k0d3 m0nk3yz!


Today, we will be working with menu stuff again BEFORE you get to work on your projects. So open up that menu project you have stored somewhere in your vast archive of programming fun, and let's get started!

OK, ready? Here's the first you have to do:

A) You already have a thing called a menustrip at the bottom of your form. You are going to drag an "OpenFileDialog" thingamabob next to it. Just scroll down the list of controls at left and you should see it in there somewhere.

B) Now you will have to connect this new control to an item on your menu. There's an "Open" menuitem available so doubleclick on it to get into its code

C) We're going to do this a piece at a time, so let's start with some very simple things. Type in this following code:

'this says where you start
OpenFileDialog1.InitialDirectory = "C:\"
'this just gives a title to the dialog box
OpenFileDialog1.Title = "Open a Text File"
'this says which kind of files to look for
OpenFileDialog1.Filter = "Text Files*.txt"
'this opens a fileDialog, so you can go looking for files
OpenFileDialog1.ShowDialog( )


Basically (hahaha Ryan) this code makes a FileOpen dialog box pop up when you click on the Open menuitem. It will start in the main directory of your hard drive, and it will ONLY look for text files. Plus, it will have a cool title that says its only looking for text files. Try it and see what you get!

Cheers,
Mr. L

Thursday, November 6, 2008

Thurs Nov 6: Whose Line Is It Anyway?

Greetings VB code monkeys!

Today you will be looking over the code of (most) of your classmates, and rating each one based on it's "ease of translation". By this I mean two things:

A) How well is it commented? Has the author of this particular program made enough notes about what is going on in their program for you, a fellow programmer, to be able to figure out what they are doing now, and what they are going to TRY to do in the future.

B) How easy is it to "read" this program? Even beyond the commenting, is the code set up so that it is easier for you to figure out what they mean to do with this program? Have they re-named their controls with descriptive words that tell you what each thing is for? Have they divided up their program among different forms, and made use of modules, such that it seems that this program would not only be easy for you a fellow programmer to debug, but for the average person to use?

I will need you to post a discussion on our Google group where you will write at least two complete sentences about each program. Please list the name of the program -- PROGRAM1, PROGRAM2, etc etc -- followed by those descriptive complete sentences. At the end of each one, assign a rating from 1 to 5, with 1 being "what the heck was THAT? It's completely unreadable!" to 5 being "D--n you're good, I envy you, you complete show off!"

Additionally, I wish for you to make one constructive suggestion OR ask one specific question about each program. This should be done at the very end of your discussion posting.

When you are done with this, please continue on with your project work

Cheers,
Mr. L

PS Here is the address of the folder where you will find these code sheets:

http://www.box.net/shared/rsoath5sk8

Wednesday, November 5, 2008

Wed Nov 5: Before we begin....

Before we begin, I need each of you to do the following:

A) Open up your projects

B) Oen up WORD

C) Save this Word document with your name followed by the phrase "My Code"

D) Put your name at the very top of this document

E) Very carefully copy ALL the code for your program into this word document, one form at a time. Before sure to include ALL your code, including all comments you have made in it, EVEN IF THE CODE DOES NOT ALWAYS WORK

F) Also, be sure to include all your code, from ALL your forms and your module if you have one

G) When you are done with this, please upload this WORD doucment to the VBDEPOT folder on BOX.NET When I get them all then we may proceed to the next thing we are doing

Cheers,

Mr. L

Sunday, November 2, 2008

Nov 3: more work with functions and modules

Hey there again!

Now that you kinda sorta know how to call a function and then make it do somethign, lets see about calling a function that will call many functions, each of which does something different. Here is what to do:

A) get back into your module and add the following code:

Public Function CallAllRandoms( ) As Integer
Random1( )
Random2( )
Random3( )
Random4( )
Random5( )
End Function

Public Function Random1( ) As Integer
Dim q As Integer
q = Int(Rnd( ) * 5)
Return q
End Function

Public Function Random2( ) As Integer
Dim z As Integer
z = Int(Rnd( ) * 5)
Return z
End Function


B) get back into form1, and then doubleclick the button that says "Call Many Functions", and add this code to it:

CallAllRandoms()
Label1.Text = Random1( )
Label2.Text = Random2( )

Cheers,
Mr. L

Mon Nov. 3: Using Modules

Hey there hi there ho there,

Today, before you get onto working with your projects some more, you will need to do three things:
A) Create a module
B) Create a function
C) connect a button to some functions and make it do stuff!

Oh, OK, so you wanna actually KNOW what those two things are? Well, let's start with the second one. A function is just some code that makes things happen. It's kind of like the events that we've been using, events like "keydown" or "buttonclick"EXCEPTTTTTTTTTT that functions don't belong to any particular control. they can just kind of sit around all by themselves and wait to be used by any control you say that they should be used by. Which brings us to:

MODULES. A module is just a place where you can store functions. These functions can be called by any control or any form within your program.

Alllllllllllllllllllllllllllllllllllllllllll RIGHTY then, let's launch into this shall we?

What to do

A) start up a new project, and name it after yourself, plus the word "functions"

B) In "Form1" please create two buttons and five labels. Replace the text of one button with this text "MessageBox Function"

C) Replace the text of the other button with this "Call Many functions"

D) Create a module by clicking on the Project menu, then clicking "Add Module". This will add a tab called "Module1.vb" at the top of your form.

E) Click on that tab if necessary, and add this code right below where it says "Module Module 1"

Public Function AddRandom() As Integer 'declaring a function that adds integers
Dim x, y As Integer
'declaring two integers and assigning values to them
x = Int(Rnd( ) * 10) ' a random number
y = Int(Rnd( ) * 20) 'another random number
'adding two integers and return the value
Return (x + y)
End Function

F) Get back into the main form, and doubleclick on the button that says "MessageBox Function"

G) add this to its code:
MsgBox(AddRandom())

Run the program to make sure it works. When everyone is set, I will pass out the code sheets to make a function that calls other functions.

When everyone is done with that, you will upload this new program to the "VBdepot" folder on Box.net, and then proceed to working with your projects

Cheers,
Mr. L

Wednesday, October 29, 2008

Thurs, Oct. 30: Yet more work with menus

Greetings and salutations, VB coders!

Today, before you begin work on your projects, I would like to be able to extend the reach of your menus. So, without any further ado --not that there was any previous ado-- let's open up the "Menus" project we made the other day, and add two controls to it.

The first control is called an "OpenFileDialog"; just drag it onto the bottom of your "Menus" form, next to the menustrip you placed there the other day. In its properties sheet, rename it "OpenSaysMe"

The other control is a "SaveFileDialog" --yup, Microsoft went all out making creative names for these controls -- drag it next to the OpenFileDialog, and rename it "SaveIt"

Once you've done that, you will want to get into the code to Open files by doubleclicking on the Open command in your menu list. Then, add in this code:

'THIS IS WHERE WE OPEN A FILE AND PUT THE STUFF INTO OUR TEXTBOX
'OpenSaysMe is the name of the FileOpenDialog
OpenSaysMe.Title = "Go Get 'em!"
'start inside the folder for your project
OpenSaysMe.InitialDirectory = saveFolder

OpenSaysMe.ShowDialog() 'open up the control to browse for files
Dim theFileIwant As String
theFileIwant = OpenSaysMe.FileName
'set the string to whatever file you chose

'make a filereader that will use the file you chose
Dim objReader As New StreamReader(theFileIwant)
MyWords.Text = objReader.ReadToEnd 'put the text of file into textbox
objReader.Close() 'stop reading

OK, once you've done that, make sure you save your work, then run the program to make sure you can actually use this to use the "Open" menu command to open up files and then put their contents into a textbox. Please be careful to open up only files with actual, words in them!

Cheers,
Mr. L

PS, If you run into any difficulties, the first thing I would look at would be the Import statement at the top of your code. If need be, please add this import line:

Imports System.IO

PPS There will be another post soon which coughs up the code for maiking the Save menu work too; be looking for it!

Sunday, October 26, 2008

Mon October 27: More fun with menus, more work on your projects!

Greetings, VB code monkeys!

Today, we will do three things; but only after you make a small teeny change to your menu codes (I will let you know what it is):

A) Each of you will make a group discussion posting consisting of at least one paragraph of three complete sentences each. Name the discussion posting after yourself + the name of your project. This discussion posting will need to include a brief discussion of what the project is supposed to do, and what it currently is able to do. Also, if you have run across any difficulties, please include that as part of your post

B) Each of you is required to comment on at least two of the other discussion postings. Extra credit will be awarded for making truly helpful suggestions to your classmates as part of your comments. By helpful, I do not mean posting the equivalent of "man, you should really try not to have your project suck". Try to offer specific guidance, if you can.

btw, there is no real limit to the amount of extra credit you can get for offering assistance to your fellow coders

C) Work on your projects, and upload them before the end of the class

Cheers,
Mr. L

Thursday, October 23, 2008

Fri Oct 24: yet more fun with menus

More code to add to your menu:



First, add this code to THE VERY TOP of your code sheet, above where it says “Public Form1”



Imports System.IO.File



If you recall from our “Crypto” program, this allows you to create and save files in VB



Next, just beneath “Public Form1’ create the following variable:


Dim saveFolder As String



Next, give this variable a value in “Form Load”, something like this:


"C:\Documents and Settings\Paul\My Documents\Visual Studio 2005\Projects\PaulLaRueMenus\"


It’s the pathname for a folder; your pathname will be different, since you are not me



Finally, doubleclick on the SAVE command, and then add this code to it:


Dim myFile As System.IO.File


'create a file writer


Dim myWrite As System.IO.StreamWriter


'set the folder and name of file where contents of textbox will be written


myWrite = IO.File.CreateText(saveFolder & "My Words.doc")



'write the contents of your textbox to a file


myWrite.WriteLine(MyWords.Text)


'closes the file no more writing to it


myWrite.Close()



Now, SAVE your work, then run the program and see if you can save a text file from the text you type in your textbox



Cheers,


Mr. L

Friday October 24: fun with menus

Greetings, and yes, it's good to be back. Today we will work towards accomplishing two goals:

A) using menus in your VB applications

B) working on your projects

and btw, you need to pass in both these items today before the class is done!

Anyway, lets get going with menus. The first step is to start a new VB project, and name it after yourself plus the word "menus".

Next, scroll down in the list of controls at the left and drag a "MenuStrip" onto your form. It doesn't matter where, since its just a container, and the real guts of it will always go up at the top of the form

Next, go up top to where those "guts" are; it will say "TYPE HERE" click there, and type the word "FILE" then hit the Enter key

Repeat this process four more times, adding the following menu items:
NEW
OPEN
SAVE
EXIT

Save your work, then run the program to make sure your new menu looks OK. You should be able to click on all of the menu items, but they won't do anything....yet!

OK, now to make one of your menu items actually do something. Doubleclick on the "EXIT" menuitem to get into it's code, then type in this code:

Me.Close( )

Save, then run the program. See if the EXIT command now brings you out of the program.

Does it work? Cool! OK, let's do one last thing: Add a textbox to your form, re-size it so that it takes up most of the form. In the Properties sheet at the right, rename the textbox to "MyWords" and set its "Multi-line" value to TRUE. When you're ready, I have some very interesting code for you

Cheers,
Mr. L

Wednesday, October 22, 2008

Thurs, Oct 23: How to properly zip and upload

Greetings, esteemed colleagues in code!

Today, before you get to work on your projects, I would like to take this opportunity to remind you of the importance of HANDING YOUR WORK IN ON TIME. Some of you have already lost points for not bothering to upload as I have demonstrated and as I have insisted that you do.

I believe this to be so important that I am including a series of instructions on how to upload your Projects:

A) After working on your project, notice that it is about 5 to 10 minutes before the end of the period

B) Save all your work, then close Visual Basic

C) Get into your "Projects" folder by going to "My Documents", then Visual Studio 2005, then into the Projects folder

D) Inside this main Projects folder, you should see many other folders, including the one which contains your current project

E) Create a new Winzip file next to this current project folder by right clicking in a blank space, then going to NEW then Winzip

F) Rename this Winzip file so that the filename includes your name, the name of your project and todays date as a number; for example "PaulLaRueMissionRisk1023"

G) Drag your current project folder onto this winzip file, then click the Add button

H) Get online and go to your shared "VBDepot" folder on Box.net. Upload the zip file you created

It's really that simple. From now on, do it before the end of EVERY CLASS.

Cheers,
Mr. L

Tuesday, October 21, 2008

Tuesday Oct 21: more project work, and commenting, and not dying of heat exhaustion

Greeting esteemed coders in the Microsoft tradition

If you please, today I would like to do three things with you:

A) Make sure that you have commented the relevant parts of your program, including the comments at the very top if your program has been modified. (This way if you've slacked off on commenting, I will never know the difference!)

'Commenting is important, and will be important in your near future

B) Continue working on your projects, and make sure to hand them in before the end of class

C) Try not to wilt from the heat....apparently, they're trying to make sure we're snug and cozy up here. What I wish they would realize is that in cyberspace, the best warriors are COLD warriors.

Cheers,
Mr. L

Sunday, October 19, 2008

Mon Oct 20: help files and the web browser control

Greetings VB coders!

and welcome back from your weekend! Today, before you work on your projects, I want to demonstrate to you how to use a RIDICULOUSLY simple control that has many uses: the web browser control. Here's what you will do:

A) start a new project and name it after yourself plus the letters "WWW"

B) in the form that opens up, drag onto it a button, a textbox and a "webbrowser" control. This last is waaaaaaaayyy down towards the bottom of your list of controls

C) Doubleclick on the button to get into its code

D) Type in the name of your webbrowser control -- most likely it's called "Webbrowser1"

E) type in the period "." This will bring up a list of stuff you can do with this control, including -- oh please, just let it come -- "Navigate"

F) Next, type an opening parenthesis "(", then type in the name of the Textbox, which is probably going to be "TextBox1"

G) Type in the "." again, then choose "Text"

OK, that ought to do it. Run the program, and then type a website address in the textbox, then hit the button; the chosen website should appear in the webbrowser control

SO, what is this control good for? Well for one, it's cool all by itself. More specifically, you can set up some online help, or even offline help in the form of a webpage that goes with your program. It's a lot easier to pack useful information like that in this format, and be able to call it up from your program in this fashion.

OK, enough preaching: be sure to upload this very small and easy to make project to our "Depot" folder. Then, work on your own project some more, and upload that too before the end of the period.

Cheers,

Mr. L

Wednesday, October 15, 2008

Wed October 15: I need your projects NOW and at the END of the class too!

Greetings VB coders!

Today, before you do anything, you need to UPLOAD the project you are working on. You were supposed to do this yesterday; here are the names of the people who actually did that:

Erik Johnson

Callum Bushe & Jacob Mokler

Evan Kollmeyer

The rest of you need to upload your projects NOW



Once you are done with that, you have the entire class to work on this project -- again (Two whole days in a row -- whoo hoo!!)

Five minutes before the class ends, upload this file as well

Cheers,
Mr. L

Monday, October 13, 2008

Tues October 14 Comments: not just for breakfast anymore.

OK, seeing as how it's our first day together in a long, long time, and seeing as you haven't had as much time to work on your projects as any of us would have liked, that's what you have to do today: work on your projects. And the very first thing you are going to need to do, before you write another line of code, is to do this:

TELL ME WHAT YOUR PROGRAM IS ALL ABOUT

and here's the particulars:

A) I want you to do this telling as a block of comments at the very top of your program

B) The easiest way to make a comment is to put a ' at the beginning of each comment line. It's kind of liking putting // at the beginning of each line in a JAVA program or REM at the beginning of each line in Qbasic.

C) Your comments will have to include at least four different things this program will be able to do when you are done, and it should also list the components -- buttons, labels, textboxes etc-- you plan on using and how these components will interact with the code you are writing.

D) You will need to put a date at the very beginning of your comments, as well as the author name or names -- in other words, who is creating this thing?

When you are done with that, you have the rest of the class, except for the last five minutes, to work on your project.

When it is five minutes 'til the end of the class, you will need to make a zip file, name it after yourself plus the word "Project" plus today's date.

Upload that zip file to our account at BOX.net

Cheers,
Mr. L

Tuesday, October 7, 2008

Wed October 8: File creation and for loops

Greetings, invincible ones!

Today we will be accomplishing two distinct goals

A) You will continue to work on your ongoing projects....but FIRST

B) I will demonstrate to you how easy it is to create, save and write to files in Visual Basic. We will create our first "General Declaration", in which we import some code that's already pre-written in the VB language. This code will allow us to do the work with files

We will also use a "for loop" to take all the stuff in your array -- meaning all the letters-- and write it to your file, one line at a time. I'll explain a little more about exactly what a loop is and how it works at that time

btw, this time, I have handouts :-)

Cheers,
Mr. L

this is a private sub for the keydown event

Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.A Then
whichKey = 0
ElseIf e.KeyCode = Keys.B Then
whichKey = 1
ElseIf e.KeyCode = Keys.C Then
whichKey = 2
ElseIf e.KeyCode = Keys.D Then
whichKey = 3
ElseIf e.KeyCode = Keys.E Then
whichKey = 4
ElseIf e.KeyCode = Keys.F Then
whichKey = 5
ElseIf e.KeyCode = Keys.Space Then
whichKey = 26
ElseIf e.KeyCode = Keys.F11 Then
MsgBox("Do you want to save your label?")
allTheWords = secretCode.Text
wordsGoHere.Text = allTheWords
wordsGoHere.Visible = True
End If
secretCode.Text = secretCode.Text & CodeKeys(whichKey)

End Sub

put this stuff in the section where you first declared your variables

Go above where you typed this stuff:
Dim whichKey As IntegerDim whichLetter As StringDim allTheWords As String

And add this array there:

Dim CodeKeys() As String = {"Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "A", "S", "D", "F", "G", "H", "J", "K", "L", "Z", "X", "C", "V", "B", "N", "M", " "}

Sunday, October 5, 2008

Tuesday October 7: I'm grateful to be here

TLEQHOFU ZIKGXUI ZIT SOSN YOTSRL

O EQDT QEKGLL QF TDHZN LHQET

ZKTDWSTR QFR TBHSGRTR

STYZ Q WXL LZGH OF OZL HSQET

Ok, now that I have your attention, today we are going to be extending our understanding of arrays, variables and keyboard events by working on a separate assignment which allows you to create encrypted messages (secret codes, that is). Here is what you need to do before I hand you out the actual code sheets:

A) create a project and name it "Crypto" plus your first name and last Initial

B) add to your form a label and name the label "secretCode"

C) add a textbox, name it "wordsGoHere" and set its visibility to false

D) click on the "F7" key to get into your code, and outside of any control, type in the following code:

Dim whichKey As Integer
Dim whichLetter As String
Dim allTheWords As String

E) get into the "Form Load" part of your code, and add this code:
'set default as first element in the array
whichKey = 0
'set the letter that is going
'into the label as the first letter in the array
whichLetter = CodeKeys(whichKey)

F) Once you're done with that, I will hand out the rest of the code you will need to begin completing this assignment.

When you're done with this assignment, you will need to upload it so that I can see how well you've done. After that, feel free to work on your projects!

cheers,
Mr. L

Friday, October 3, 2008

Friday October 3: as you were gentlemen!

Greetings, feared VB coders!

Today is Friday. And a "spirit" day. And people are spirited. So here is all you need to do:

A) work on your current projects

B) zip them up and email them to me

C) post a discussion on how you are doing thus far, including any discoverioes and any concerns

that'll do

Mr. L

Thursday, October 2, 2008

Thursday Oct 2: Before you work on your projects, or continue with amkeup work!

Greetings, fellow code monkeys!

It has come to my attention that many of you are being prompted to "activate" your copy of Visual Basic. I was having the same problem, and I fixed it. Here is how you do it (and hopefully it will work for you too!):

A) Go to www.hotmail.com, and then click on the SIGNUP button in the middle of the screen

B)On the next page underneath the words "Windows Live Hotmail" click the GET IT button

C)On the next page fill in all the necessary information, and be sure to set the email type to HOTMAIL -- I cannot guarantee that a live.com account will work

D)Click the I ACCEPT button to bring you to your new account

E) LEAVE YOUR NEW HOTMAIL ACCOUNT OPEN

F) Turn on Visual Basic and when that thing near the system clock comes up to "activate" Visual Basic, click on it

G) This should bring you to a webpage where you have to fill out a form, complete with your new hotmail address, and then submit the form

H) You should receive an "activation code" and instructions on how to use it in your new hotmail inbox.

I) Follow the instructions, and let's see if we can solve this problem

Once we are done with this, I will be continuing to make last minute updates to your grades, and you will be working on your new projects BEFORE THE END OF THE CLASS, you will need to ake a new discussion posting talking about the progress you have made on this new project. When you make the discussion posting, please put todays date in the subject line, along with "Project Progress" plus your name.

Cheers,

Mr. L

Tuesday, September 30, 2008

Wednesday October 1: Getting caught up with classwork

Greetings, fellow VB coders!

Today, before you even think about working on your new projects, each one of you will have to have a look at your grades, which are based on work that I can PROVE THAT YOU HAVE DONE. A few of you have not made posts to our Google discussion group, as per my instructions; at least one of you has not uploaded ANY project files to my BOX.NET online file storage, and several of you have either uploaded shortcuts to various folders, or files that are either unreadable or un-openable.

I CANNOT BASE YOUR GRADES ON ANYTHING THAT I CANNOT SEE

ITS NOT WHAT I "KNOW" ITS WHAT I CAN PROVE

we need to get this fixed TODAY

After that, we can re-commence work on your projects

Cheers,
Mr. L

Friday, September 26, 2008

Friday September 26: hand in your Ferris Bueller assignment, and......

....begin coming up with a project of your own. OK, today should be really simple:

A) Make sure your "Ferris Bueller" keyboard project works

B) Use winzip to "zip up" that project file

C) Upload that zipfile to the VBDepot folder I have shared out on my Box.Net account

D) You will now have plenty of free exploration time. You will use at least some of it to make a Discussion post outlining -- in some rough draft sense-- the kind of project you would like to work on. Tell me what you want your program to do!

E) Additionally, if you have made any new discoveries for which you wish to receive some sort of extra special credit, please post a discussion detailing what you have found. C'mon, you guys are smart: show off a little!

Cheers,
Mr. L

Tuesday, September 23, 2008

Tuesday September 23 -- a new way to pass in your projects

Hey there hi there ho there,

Today, we will accomplish two great and magnificent things:

A) I will show you a new way to get your projects handed in to me

B) I will demonstrate how to connect keyboard events to sound output (yes, the infamous "Ferris Bueller keyboard"...coming soon to a computer right in front of you!)

OK, let's start with A.

1) Yesterday, I shared a folder called "VBDepot" on my Box.net account. According to my account instructions, I can share it with you guys by emailing you invites, which I did yesterday before I left the building. So, the first step is to check your email

2) You will find an email with the subject line
"UnclePaulie (mrlarue2009@gmail.com) invited you to collaborate on Box.net"
get into that email and click on the link which is just below the line that says
UnclePaulie has invited you to share files in the "VBdepot", folder

3) This will bring you to a webpage where you enter in your name, your email address, and a password, then hit the SIGNUP button

4) This brings you to a webpage where you can see the shared VBDepot folder. click on the link that says VBDepot

5) On the next webpage, there is a link where you can upload new files. Click on that link. This pops up a dialog box

6) In that dialog box, there is an "Add Files" button. You use that to browse for files. Just to test out the system, just upload a file that I can recognize as being yours.

7) Click the Upload button, and Shazzam!!! your file is uploaded

Now for the tricky part: can you read the instructions from yesterday? The ones that tell you how to find your the folder which holds everything for your current project, and then zip it up inside a WinZip folder? I'm sure that you can. And, if you need help, that's what I get paid the big bucks for :-)

OK guys, lets do it! Let's get it done! The Ferris Bueller program awaits....

Cheers,
Mr. L

Sunday, September 21, 2008

Monday Sept 22 -- sending me your projects, working with keyboard events and sound

Greetings, O most mighty of all VB coders! Today, we are going to do two pretty darned important things:

A) We will learn how to zip up your projects and send them to Mr. LaRue as email attachments

B) We will learn about using keyboard events in VB, and making things happen in response to those events

Let's do A) first

Here is what you need to do:

1) Unless you went out of your way to change where you save your files, you probably have a "Projects" folder associated with VB. It's located inside the "Visual Studio 2005" folder inside of the "My Documents" folder.

2) Inside of the "Projects" folder, you will find a separate folder for each project. It might be called "WindowsApplication1" or "buttonAction" or whatever you named your project when you first created it.

3) You will want to copy this folder to your desktop

4) Once you've done this, you should be able to create a new "zip" file by right clicking on the desktop then clicking in the menu where it says "new" then "winzip file". Name this zip file after yourself

5) drag the project folder onto the zip folder

6) when the menu pops up, click the ADD button

7) send this zip file to me as an email attachment

Once you've done that, we will work on using keyboard events and sound. I have some lovely handouts for that :-)

Cheers,
Mr. L

PS We may not need them today, but I have some sounds associated with a project which I will be demonstrating to you. The sounds are bundled in a winzip file found here:
http://www.box.net/shared/n19oryovx2

Thursday, September 18, 2008

iiiiiiiiiiiiiiiiiiiiiiiiiiittttts Friday! (September 19)

and to celebrate, let's do a little work with some pretty pictures, shall we?

The program you will create today will make use of many features we have already explored, such as a "Form Load" statement, which makes stuff happen when your form appears on the screen, an array declared outside of any control on the form, an integer variable and a button to move through the array one element at a time.

We will also make use of some new stuff, including :

A) the use of a String variable to hold a pathname, that is, something which describes where a file can be found. Here is an example of a pathname:
C:\Documents and Settings\Paul\Desktop\Meladie

B) the use of a PictureBox control, and more importantly, the "Image.FromFile()" constructor, which allows you to set the image property of a PictureBox. (In other words, we'll be able to change the picture at will.)

So OK, before we get going, please setup a folder somewhere that's convenient, and then download some pictures to it. Then I'll pass out the code sheets, and away we go!

Cheers,

Mr. L

Tuesday, September 16, 2008

Wed Sept 17: Show What You Know, Part One

Greetings, fellow VB programmers~!

Today will be a day for you to "show what you know". Rather than just assuming that you know how to use the techniques I've shown you, I'm going to challenge you to prove it. Here's how it gets done:

A)You will need to create a completely fresh program

B) This program will need to be able to do at least three different things.

C) Your program will need to make use of at least four of the following controls:
  • a button
  • radio buttons
  • textbox
  • label
  • groupbox
  • something else (your choice)

D) Your program will need to make use of at least
  • one if statement
  • two variables, each of a different type (integer, boolean, string)
  • one array

E) Your program will need to have at least one variable that is declared outside of any Subroutine, one which can be accessed by an control on your form

F) You will need to have at least one event which takes place at Form Load

G) You will need to add comments to your code, saying what different parts of it are good for.

If you have forgotten what some of this stuff is, well, that's part of why we do this. I will try to help; you should also consider working with the people sitting near you, or even those all the way across the room.

Cheers,

Mr. L

Monday, September 15, 2008

(Sept 16) -- more arrays, form load events, labels, and some weird variable called a Boolean

Tuesday greetings O most exalted VB coders!
hello there, and welcome back from your weekend. Today, we are going to accomplish the following tasks:

A) create another array -- which remember, is just a collection of variables -- and this time, the array will be created OUTSIDE of any subroutine. It's not attached to any particular button or control, so it can be used by any of them

B)Create a label, which is kind of like a textbox, only its words can't be changed just by mnaully typing it in.

C) Use the "Form Load" event to set the text of that label. (You'll see, you'll see)

D) Use the View --> Code menu to get into the code; another way of getting there, rather than double clicking a button or some other control. This will also be important in accomplishing (A) above

E) Use yet another GroupBox, complete with two radio buttons, to determine whether or not a button's text says "forward" or backward"

F) create and use a Boolean variable -- one which can only have two values, either true or false. This Boolean will be linked to the two radio buttons mentioned above, and will also be used in yet another If statement to determine whether or not you will go forward or backward in seting the text of the label found in (B) above

Whew! After that, you'll have time for free exploration. Just be sure to make a Discussion posting in our Google group for whatever discoveries you may make.

Cheers,

Mr. L

Thursday, September 11, 2008

Friday, September 12 -- multiple forms, changing buttons and more work with arrays!

Hello there O most distinguished VB code jockeys! Today we will be working to accomplish several goals:

A) We will learn how to add a second form to our programs, and how to make that form appear and disappear

B) We will learn how to change properties of a control in response to events, using an If statement

C) we will attempt to make use of another array on that second form

D) we will, I promise, have some "free exploration" time; provided that you record the results of your exploration as a post in our Google Group

Cheers,
Mr. L

Thursday Sept 11 -- more if statements, our first array...and MORE!!!

OK VB coders, yesterday we explored the wonderful world of If statements and MsgBoxes. Today, we will continue exploring If statements, as well as making our first array. An array is a collection of related variables, and is a very convenient way of being able to group relate ditems, such as the names of bands, favorite TV shows, athletic rosters, you name it!

We will also look at how you can affect the properties of the actual form a component is located in, using the "Me" keyword. Additionally, we will learn how to tranfer properties -- such as text -- from one control to another.

And last but not least, we will have some "free exploration time" so that you may make discoveries all of your own, and then post what you've found to our Google Group!

Cheers,
Mr. L

Thursday, September 4, 2008

VB programmers, Friday Sept 5 -- Part Two

I’ve been reading your emails with great interest, and have discovered a little bit about each of you, what some of your interests are, why you want to be in this class. You will need to expand upon this in a discussion post you will create on the Google Group you just joined. Here is what your discussion post needs to include:

A) What sort of programming most interests you? Would it be something that plays music? Looks up stuff for you online? Perhaps plays a simple game? Helps a person study? Keeps track of who owes you money?


B) What kind of person would use your program? Is this going to just be for your own personal use, or would it be something you might want to share with friends, classmates, family, etc etc?

C) For that matter, would you like to see it posted to some sort of online software repository, where others can download it?

D) What would a program of yours look like? Would it have a clean simple interface, like the Google homepage? Would it be crammed full of buttons and other components? Would it have a menubar at the top? If so, what kind of commands should it hold? Or would it be something that only works in a command prompt window?

E) Will your program be able to save settings? Will it be able to create files? Should it be able to print? Should it be able to connect to the Internet? Will it be able to do some things automatically?

OK, that ought to do it. Please be as complete as possible. When you are finished, make sure to post your discussion, and then take a look at the discussions put out by your classmates. It may be that there are others who share your interests, which would be good, since we will probably have a group project or two during the course of this class. In real life, no one writes a program all by himself anymore: they're created by teams

Cheers,

Mr. L

What to do on Friday September 5 -- part one

Greetings, and welcome once again!

Today in Visual Basic Programming, you will be doing two things, both of them related. this is the first thing you must do:

In your email inbox, you SHOULD have an invitation from me to join the Google Group which I have set up for this class. It's called "Welcome to the Monkey House". You will need to follow the instructions in this email TO THE LETTER to get signed up, and to be able to go on to the next step. If you need assistance, I will do my utmost to help.

OK, so get get set up RIGHT NOW. C'mon back when you're done, and then we'll go on to part two, which I will post when you're ready.

Cheers,
Mr. L

Greetings, Visual Basic Programmers!

This is C0D3 M0NK3YZ, where the students from Mr. LaRue's period 5 Visual Basic Programming class will receive news, instructions, marching orders and potentially leave comments and ask questions. If you are allowed and you do leave a comment, please bear in mind that this blog is available to the entire world, or at least that part of it that's on the Internet. This includes your parents, other teachers, your guidance counselor, the principal, the superintendent, and what the heck, the mayor, the governor, the chief of police, the head of the FBI, and pretty much EVERYONE. So be cautious, courteous and school appropriate in any comments you leave