Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Introduction to Visual Basic .NET | ||||||||
Line: 22 to 22 | ||||||||
Go look in the bottom right-hand pane of Visual Studio. It should say Properties at the top of that little windowpane. (If it doesn't, select View->Properties Window and the Properties pane should appear somewhere.) | ||||||||
Changed: | ||||||||
< < | The Properties pane is mostly filled with a two-column table. Look for the left-hand cell that says Text. The right-hand side should say Label1; change that to say Lemurs rule! | |||||||
> > | The Properties pane is mostly filled with a two-column table. Look for the left-hand cell that says Text. The right-hand side should say Label1; change that to say Aardvarks rule! | |||||||
Above the Text line are a bunch of lines having to do with the appearance of the text: font (which includes size and boldness and italicness), color, background color, alignment, font direction, etc. You can make it hot pink text on a cyan background. Go wild! Take a few minutes to have some fun with the text -- I can wait. | ||||||||
Line: 64 to 64 | ||||||||
Private Sub ConvertButton_Click(ByVal sender As System.Object, | ||||||||
Changed: | ||||||||
< < | ByVal e As EventArgs) Handles ConvertButton.Click | |||||||
> > | ByVal e As EventArgs) Handles ConvertButton.Click | |||||||
Dim miles As Double Dim km As Double miles = Val(MilesTextEntry.Text) | ||||||||
Line: 99 to 99 | ||||||||
I (Ducky) wrote this tutorial very quickly, so there are probably things that you could improve upon. This is a wiki, so if you want to add screenshots, reword sentences, add clarification, etc., go for it! As a bonus, every time you add something of value, you have my permission to change the wording from "Lemurs rule!" to "(your team name)s rule!" -- DuckySherwood - 25 Oct 2005 | ||||||||
Added: | ||||||||
> > | -- AlexTung - 25 Oct 2005 (corrected code "EventArgs" to "System.EventArgs") | |||||||
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Added: | ||||||||
> > |
Introduction to Visual Basic .NETLaunching VBHere is how you get started with Visual Basic .NET 7.1 as it lives on the x360 computers. Select Start->Programs->Microsoft Visual Studio .NET 2003->Microsoft Visual Studio .NET. When that loads, click on the New Project button. Select the Visual Basic folder and the Windows Application icon. The Visual Studio will open up, which has buttons and lists all over the place. In the center will be a grey sub-window with black dots in it labeled "Form1". The tab "Form1.vb [Design]" above it will be selected (i.e. darker). On the left is something that says "Toolkit". If you click on that, you'll see a list of GUI elements (what in this context are called controls.) You'll probably see Pointer, Label, Button, CheckBox, etc. If you click on the little push-pin on the Toolkit window, it will hang. I don't know why. Instead, click on the X and then go to View->Toolbox. I think that will bring it up in an anchored window.Pretty PicturesThe basic idea behind Visual Studio is that you do a lot of the GUI building graphically. For example, you can click on Label in the toolkit, then go over to the Form1 window, drag open a rectangle, and voila! You will get a box that says something like Label1. Label1. Does that text suck, or what? Let's make it say something more interesting. Go look in the bottom right-hand pane of Visual Studio. It should say Properties at the top of that little windowpane. (If it doesn't, select View->Properties Window and the Properties pane should appear somewhere.) The Properties pane is mostly filled with a two-column table. Look for the left-hand cell that says Text. The right-hand side should say Label1; change that to say Lemurs rule! Above the Text line are a bunch of lines having to do with the appearance of the text: font (which includes size and boldness and italicness), color, background color, alignment, font direction, etc. You can make it hot pink text on a cyan background. Go wild! Take a few minutes to have some fun with the text -- I can wait.CodeOkay, so you've made pretty fonts in all kinds of whizzy colors. That's nice, but surely there's more to VB than this. Since MapQuest didn't convert miles to kilometers, let's make a quick tool to do that.
Private Sub ConvertButton_Click(ByVal sender As System.Object, ByVal e As EventArgs) Handles ConvertButton.Click Dim miles As Double Dim km As Double miles = Val(MilesTextEntry.Text) km = miles / 0.6 KilometersTextOutput.Text = "Kilometers: " + Str$(km) End SubBasically, the Foo_Click method is called when there is a click in the element named "Foo". In this case, it executes every time there is a click in ConvertButton. All the junk about ByVal sender etc and e As EventArgs, etc? You don't need to worry about right now. Basically, it's passing around events in a way that isn't that different from how Java does it. You might need to use it once you start building prototypes for your project, but you might not. Learn it when you need it. After the Private Sub line is some pretty basic miles-to-kilometers conversion math. Pretty simple.
Finally, you set KilometersTextOutput.Text to a new string, and the new string magically gets plopped in the right place in the windo and refreshed. It's magic, it does it all for you.
Running the codeTo see that this does in fact work,
Error while trying to run projectIf you get a message "Error while trying to run project: Unable to start debugging", well, that's a security thing. Not all computers are "unlocked". (The ones in the x360 lab should NOT give you this message!) If you do get "unable to start debugging" error message, all is not lost: go find your application on the file system. It's probably somewhere like My Documents -> Visual Studio Projects -> WindowsApplication1 -> obj -> Release -> WindowsApplication1. Click on file, and you should see a wonderful little window that says "Lemurs rule!" and has a miles to kilometers conversion tool.Final notesI (Ducky) wrote this tutorial very quickly, so there are probably things that you could improve upon. This is a wiki, so if you want to add screenshots, reword sentences, add clarification, etc., go for it! As a bonus, every time you add something of value, you have my permission to change the wording from "Lemurs rule!" to "(your team name)s rule!" -- DuckySherwood - 25 Oct 2005 |