Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 3 - 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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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 - Working with the Console continued


    (Page 3 of 4 )

    Write and WriteLine write to the screen wherever the cursor is at. Usually, the cursor will just move straight down the screen. A line will be written out, and then the cursor will move to the first column of the next row in the console in preparation for another line being written. This default behavior is of little use to us, but if Write follows around the cursor, then all we need to do is change the location of the cursor. Then we can write characters out anywhere.

    We can move the cursor around using the SetCursorPosition procedure. It takes two Integer arguments, which basically form a standard (x, y) coordinate. The first argument indicates the horizontal position of the cursor (the column that the cursor is in) and the second argument indicates the vertical position of the cursor (the row that the cursor is in). Note that the top left edge of the console is the zeroth column of the zeroth row. So, to write something at the very top left, we'd do this:


    Console.SetCursorPosition(0, 0)

    Console.Write("Hello World.")


    Note that after running the above code, the cursor will be immediately after the written text. So, if we write more text to the screen, it will follow right after “Hello World.”

    Feel free to go ahead and play around a bit more with SetCursorPosition. Here, we write “Hello World” well off the top left edge of the screen:


    Console.SetCursorPosition(10, 10)

    Console.Write("Hello World.")


    We can also set the position of the cursor through the CursorLeft and CursorTop properties of Console. The following code produces the same effect as the above code:


    Console.CursorLeft = 10

    Console.CursorTop = 10

    Console.Write("Hello World.")


    We can use these same two properties to read the position of the cursor. Here, we display the position of the cursor using Write and a format string:


    Console.Write("The cursor is at ({0}, {1})", Console.CursorLeft, Console.CursorTop)


    I'm going to switch topics for just a moment because this is a good time to introduce an aspect of Visual Basic's syntax. Notice how the above line is a little long. You may be tempted to break long lines of code into two or more lines. This is, of course, possible, but you can't just break them up with the return key. Instead, you have to mark line breaks with underscores, like this:


    Console.Write("The cursor is at ({0}, {1}).", _

    Console.CursorLeft, _

     Console.CursorTop)


    Notice how the underscore has a space before it. This is required.

    More Visual Basic.NET Articles
    More By Peyton McCullough


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

    VISUAL BASIC.NET ARTICLES

    - 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...
    - Creating and Drawing a Game Map in VB.NET (F...
    - Working with Classes and Properties for Game...
    - Working with Loops, Arrays, and Collections ...
    - Learning Loops in VB.NET for Game Development
    - Learning VB.NET: Working with Variables, Con...
    - The Basics of VB.NET Through Text Game Devel...
    - Learning VB.NET Through Text Game Development
    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




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