Visual Basic.NET
  Home arrow Visual Basic.NET arrow The Basics of VB.NET Through Text Game Dev...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

The Basics of VB.NET Through Text Game Development
By: Peyton McCullough
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-06-04

    Table of Contents:
  • The Basics of VB.NET Through Text Game Development
  • Working with the Console
  • Working with the Console continued
  • Changing Color

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    The Basics of VB.NET Through Text Game Development


    (Page 1 of 4 )

    This is the second article in a series covering how to learn VB.NET by developing a text-based game.  The last article gave a basic introduction into the development of our application, and this one will pick up where it left off. So if you're ready to keep learning, keep reading!

    More on WriteLine

    Before we move on, I'd like to point out a few more things concerning WriteLine. First, although we passed a String (the expected type of a series of characters) as an argument earlier, we can pass just about anything as an argument, and WriteLine will print its textual representation. For example, here we print out an Integer (Visual Basic's version of a thirty-two bit signed integer, or the System.Int32 type—there is also a System.Int16, Short and a System.Int64, Long):


    Console.WriteLine(4)


    If you place the above line of code into our module and run it, the number four will be printed out. If we pass any type of object, a textual representation of it will be printed out as well. How is this representation determined? The object's ToString procedure is called on to return a String. This procedure is defined in the Object class, which is the ultimate base class of everything, though we do not need to explicitly inherit from it when constructing a new class. By default, the procedure will simply return the name of the class, but this procedure can be overridden to return any String. We can modify our program to call ToString:


    Sub Main()

     Console.WriteLine("Hello World.".ToString())

    Console.ReadKey()

     End Sub


    The effect is the same.

    The second thing I'd like to point out is WriteLine's ability to work with format strings. Let's say we have two objects. One is an Integer and one is a String. We need to print both of them out on the same line, along with some other text. One way to do this would be to append everything together using the concatenation operator, &:


    Console.WriteLine("Two objects: " & 4 & ":-)")


    This approach certainly works, but it's a bit ugly, and would be even uglier if we had more objects. A better way is to use a format string to specify what will go where. Here, we use a format string:


    Console.WriteLine("Two objects: {0}{1}", 4, ":-)")


    This example will produce the exact same output as the earlier example, but this version looks a lot neater. Notice how, above, we have two bracketed numbers, starting with 0. These bracketed numbers will be replaced with objects passed as arguments in the exact same order that the objects are passed. So, {0} is replaced by the first object passed, {1} is replaced by the second, and so forth.

    More Visual Basic.NET Articles
    More By Peyton McCullough


       · Hello, all,This is a continuation of the series introduced...
     

    VISUAL BASIC.NET ARTICLES

    - User-defined Functions using Visual Basic Ap...
    - Understanding Object Binding in VBA
    - Mastering the Message Box
    - Testing a Windows Forms Application
    - Using Visual Basic.NET Features to Code a Wi...
    - Correcting Code in a Windows Forms Applicati...
    - Write Readable Code and Comments for Windows...
    - How to Code and Test a Windows Forms Applica...
    - Adding Features to a Windows Forms Applicati...
    - How to Design a Windows Forms Application
    - LINQ to XML Programming Using Visual Basic.N...
    - Understanding Delegates using Visual Basic.N...
    - Create a Sudoku Puzzle Generator using VB.NET
    - Entity Creation and Messaging in a VB.NET Te...
    - Movement and Player Statistics in a VB.NET T...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    Stay green...Green IT