IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
VB.Net
Search VB.Net Group:

Advanced
-Collapse +Expand VB.Net To/From
To/FromCODEGuides
-Collapse +Expand VB.Net Store
PRESTWOODSTORE

Prestwood eMagazine

October Edition
Subscribe now! It's Free!
Enter your email:

   ► KBProgrammingVB.NetTool Basics   Print This     
  From the January 2016 Issue of Prestwood eMag
 
VB.Net Tool Basics:
A 10 Minute VB.Net Console Application Quick Start
 
Posted 16 years ago on 10/8/2008 and updated 1/31/2011
Take Away:

This will show how to make a "hello world" console application in Visual Studio 2008 using VB.Net.

KB101325

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:

And, here, we, go...

Part 1: Simple Console App

  1. Launch Visual Studio and click File | New Project.
  2. 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.
    VB.Net Console Application
     
  3. 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.
     
  4. 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
  1. 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.

      
  2. 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.

  1. In the Project Designer, select the Compile tab:

     
  2. Click the Advanced Compile Opitons... button.
  3. 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.

  1. In the Project Designer, select the Compile tab:

     
  2. 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.

  1. 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

     
  2. Click Debug | Start Debugging to run the application.

That's it! I hope this was helpful.


Comments

1 Comments.
Share a thought or comment...
First Comment
Comment 1 of 4

how can you create a console application in vb.net 

and other programs and project  

---
Bhagwat kushwaha
Posted 13 years ago

Comment 2 of 4

Did you follow the instructions in this article? If not, that's how. If you did "give it a shot", then let me know what happened.

Posted 13 years ago

Comment 3 of 4

Very helpful.  Thank you.

---
Elly
Posted 11 years ago

Latest Comment
Comment 4 of 4

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

Posted 56 months ago
 
Write a Comment...
...
Sign in...

If you are a member, Sign In. Or, you can Create a Free account now.


Anonymous Post (text-only, no HTML):

Enter your name and security key.

Your Name:
Security key = P157A1
Enter key:
Article Contributed By Mike Prestwood:

Mike Prestwood is a drummer, an author, and creator of the PrestwoodBoards online community. He is the President & CEO of Prestwood IT Solutions. Prestwood IT provides Coding, Website, and Computer Tech services. Mike has authored 6 computer books and over 1,200 articles. As a drummer, he maintains play-drums.com and has authored 3 drum books. If you have a project you wish to discuss with Mike, you can send him a private message through his PrestwoodBoards home page or call him 9AM to 4PM PST at 916-726-5675 x205.

Visit Profile

 KB Article #101325 Counter
42715
Since 10/8/2008
Go ahead!   Use Us! Call: 916-726-5675  Or visit our new sales site: 
www.prestwood.com


©1995-2024 Prestwood IT Solutions.   [Security & Privacy]