Got 10 minutes? Want to get started with VB.Net Console Application?
This article is part of our series of 10 Minute Quick Starts. Each quick start is step by step, assumes you know very little about the subject, and takes about 10 minutes. You can use them to scratch the service of areas you want to learn and as a quick review when returning to something after a long absence.
VB.Net Console Application
This will show how to make a "Hello, World!" console application in Visual Studio 2008 using VB.Net. A console application is a command line interface (CLI) application similar to DOS Window available in various versions of Windows (but notable is not included with Vista 64-bit).
Setup
To get started, you have to have Visual Studio.Net installed. This article is based on Visual Studio 2008 but you can use any version you wish (there may be slight variations in menu options but we try to keep our 10 Minute Quick Starts as generic as possible).
If you don't have the full version of Visual Studio .Net, you can download Visual Basic .Net Express Edition:
Launch Visual Studio and click File | New Project.
In the dialog box, click Visual Basic | Windows project type, then click the Console Application template on the right. In the name field, type "HelloWorld" for the name of your project. You can change the project name later but it's easiest if you change the name now. Then click OK.
The following screen clip is from VS.Net 2008.
Find the section that says:
Module Module1
Sub Main()
End Sub
End Module
and alter as followed:
Module Module1
Sub Main()
Console.WriteLine("Hello, World!")
End Sub
End Module
The Program.cs file contains the Main method which is the entry point for the executable. All .NET projects except for DLLs have one.
Run-it! Press Control+F5 (or click Debug | Start Without Debugging)
Note Using F5 (start debugging) will cause the program to rapidly run and exit. Use Control+F5 to make the Application pause when it finishes.
That's it! You have created a console application.
Where is it?
You can click File | Save As to show the path location of the files for this solution and the files generated are worth exploring. Mine are located at:
D:\MP\Documents\Visual Studio 2008\Projects\HelloWorld\HelloWorld\
Deployment
To get the exe file for deployment...
From the main menu, Debug | Publish HelloWorld.
Follow the wizard instructions.
Part 2: Exploring a Few Tool Features
Now that you've got a working console application up and running, it's time to explore a bit. Console applications are a great way to explore Visual Studio because it's the simplest of programs and helps to establish a base of knowledge to build from.
Let's finish up by exploring a few features in the Project Designer.
Changing the Application Icon
Double click the project icon in the Solutions Explorer:
This displays the project designer in a tab defaulting to the application page. The application page allows you to set application settings and properties.
Change the default icon. If you don't have any .ICO icons, you can download a few from the internet to have around to play with. In the following two screen clips, notice the default icon on the left is changed to a beer icon on the right (that icon is the beer icon included with Paradox 7).
Changing Your Target .Net Framework
Because .Net applications currently are a runtime only system, you have to target a particular .Net Framework for each application you develop. Sometimes you may wish to target a different .Net Framework then the current default.
In the Project Designer, select the Compile tab:
Click the Advanced Compile Opitons... button.
Select whichever .Net Framework you wish from the Target framework (all configurations) dropdown.
Specify Publish Location
With our final romp through the features of Visual Studio of this 10 minute tutorial, I'll point out how to change the location the Publish feature (used when you click Build | Publish xyz.
In the Project Designer, select the Compile tab:
Change the path in the Publishing Folder field. Notice there is no save button. Your change takes effect immediately even without you saving your project.
Part 3: A More Complete Example
In this second console application, we'll use several commands to introduce gathering user input, using variables, and an if statement. Since VB.Net is a strongly typed language we have to convert an integer to a string using CStr() before we can write the value out to the console window.
Using what you learned so far, create a new console application using the following code:
Module Module1
Sub Main()
Dim UserName As String
Dim UserAge As Integer
'Gather name.
Console.WriteLine("What is your name?")
UserName = Console.ReadLine()
'Gather age.
Console.WriteLine("How old are you?")
UserAge = Console.ReadLine()
Console.WriteLine("Hi " + UserName + ". You are " + CStr(UserAge) + ".")
'Allow?
If UserAge < 14 Then
Console.WriteLine("You need a parent's permission to join our group.")
Else
Console.WriteLine("Welcome to our group.")
End If
'Exit.
Console.WriteLine()
Console.WriteLine("Press [ANYKEY] to exit.")
Console.ReadLine()
End Sub
End Module
Click Debug | Start Debugging to run the application.
Hi, if you are a student and do not have time to write an essay, contact us https://www.ozessay.com.au/ we will help you with this, I am sure you will have much more time to relax and other things