Viewers: in countries Watching now:
In Visual Studio 2010 Essential Training, author Walt Ritscher demonstrates how to use Visual Studio 2010 Professional to develop full-featured applications targeting a variety of platforms. Starting with an overview of the integrated developer environment, the course covers working with code editors, navigating and formatting code, and deploying applications. Also included are tutorials on running performance and load tests, and debugging code. Exercise files accompany the course.
Visual Basic is the other leading language for programming .NET. You may know it by its VB acronym or as Visual Basic .NET, but it's officially known within Microsoft as Visual Basic. C# and VB share a lot of features and are more similar than different in .NET 4.0. According to my sources at Microsoft, these two languages are tremendously popular and account for the highest percentage of .NET programmers. In this movie, I want to show you some basics of the VB language and its editor.
I'm inside Visual Studio, and I have open up this project called VBEditor. I have one code file here called module1.vb. The vb extension signifies that this code file contains Visual Basic code. I'll double-click on Module1.vb and load it in the editor. In Visual Basic when you're working in a console application, you have to specify a Sub Main, a main entry point for the application. So you call it Sub Main, and you put it inside a Module. I'm going to write some code to read and write information out to this console window.
I'll start by writing a piece of information to the console. To do that, I use the Console Class. Notice that dropdown IntelliSense I have get here inside Visual Studio is showing me the available types I can work with. At this point, I've typed enough for Visual Studio to recognize the word "console", and I can just press Tab to finish typing. Then I'll type in period and then Wri, there I find a recognition for Write and WriteLine. I am pressing the up and down arrows on my keyboard right now to get this.
Now I am going to press the enter key while WriteLine is selected. Visual Basic knows that this is a method call, so it puts the open and close parentheses automatically on that line. This is something that VB does that the C# editor does not do. This would write a blank line. I'd rather write something out of the console so I am going to come up to this line and type something in the parentheses. I am going to type in, "Hello. What is your name?" To end a line of code in VB, you just hit the Enter key. Nothing special is required, like the semicolon in C#.
So I am going to move down to the next line, and I am going to show you what happens when I run the application at this point. If I'm inside Visual Studio and I go up to Debug > Start Debugging, the application is going to run, my code will run, and then immediately terminate, so don't blink while you watch this. Did you see that window pop up? I don't want that to happen. I'd rather wait and see what the results are, so there's a mechanism inside Visual Studio to make that happen.
It's up here in the Debug > Start Without Debugging. Let's run the application again using this menu item. You see the difference? This time the application runs, asks me what my name is. My application is now terminated, but Visual Studio keeps the Console window open so it can read the results. Then I press any key on my keyboard to close this window. I'm going to press the Spacebar. I would rather have my own code listening to the keystrokes, so I am going to come down to line 9 on my computer and type in "Console.ReadLine".
That reads whatever the user types on the console and puts it in a variable. Well, I don't have a variable yet so let's make one. In Visual Basic, you use the Dim keyword to declare a variable like this, "Dim name As string". Enter. I am going to copy this Console. ReadLine, paste it down here, Ctrl+V, and then I am going to say on line 12, on my computer "name =".
So let's review what's happening. I'm writing this string to the console and declaring a variable, I am asking the user for their name, and I am storing it in this variable. Then I'm going to write again to the console. Choose copy. I'll come down here under line 13. I am going to paste it in, Ctrl+V, and then I am going to concatenate this variable on the end.
Concatenation just means taking two strings and putting the second string on the end of the first string. So I am going to say Hello and then ampersand, which is the concatenation operator in Visual Basic, name, and then I'll wait for the user to close the application. Let's try this one. Debug > Start Debugging. I type in my name, "Walt Ritscher", hit the enter key. It mirrors that back to me Hello Walt Ritscher, and then it waits for me to press the Enter key to terminate the application.
Next, I am going to show you how to declare a different type of variable. I am going to say Dim fs As New System.IO.FileStream. I am going to press the down arrow to move to FileStream and then press the Enter key. What this is saying is, "Declare a variable and instantiate an instance of this class, the FileStream class and store the instance in this variable." Now to simplify my life, I can eliminate typing in System.IO, so I'm going to delete this.
Notice I get a blue squiggle at this moment because it doesn't recognize the class name. I will then scroll up to the top of my Code module and type in an import statement up here, "Imports System.IO". Make sure you spell it correctly. Now look at line 18 in my code. That blue squiggle that was under FileStream has disappeared. That signifies that it recognized that as a valid class. Putting this Import at the top of my code simplifies the body of my code document.
So what I have showed you so far today is how to read and write from a console in Visual Basic. Obviously, teaching VB would take a course of its own. You will see more examples of it later in this course.
Find answers to the most frequently asked questions about Visual Studio 2010 Essential Training .
Here are the FAQs that matched your search "" :
Sorry, there are no matches for your search "" —to search again, type in another word or phrase and click search.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.