Learning VB.NET Through Text Game Development - Getting Started
(Page 3 of 4 )
Now that you know the basics of the .NET Framework and understand where we're going, let's get started with Visual Basic. Open up Visual Studio and create a new project. Call it whatever you want, but make sure that you use the Console Application template—our game is, of course, console-based. The project will automatically open. The Console Application template creates a minimal project. Only one file, Module1.vb is created for you. This is where we'll start. The file's contents look something like this:
Module Module1
Sub Main()
End Sub
End Module
Since Visual Basic, naturally, features a BASIC-style syntax, instead of using brackets as one would expect in a C-style language, plain words are used. Here, you can easily see that we have something called a “sub” inside of something called a “module.” The “module” begins with the keyword Module and ends with the keywords End Module. Similarly, the “sub” begins with the keyword Sub and ends with the keywords End Sub. That, of course, prompts the question, what exactly are subs and modules?
We'll start with the module. A module is akin to a static class in other languages, and it's what is used by default to contain the main “method” (we can't really use that language here, but we'll get to that in a few paragraphs) of a Visual Basic application. Everything is shared (“static” in other languages, meaning that the member is not specific to an instance of the class but, instead, belongs to the class itself) and is, by default, public. This is important to remember! Again, Visual Basic starts us off with a module in which to create our program, but we can create more modules in our program if we need to, and we could also wrap our program in a class, as is done in C#:
Public Class Class1
Public Shared Sub Main()
End Sub
End Class
This should look more familiar to many people, with the exception of the word “shared,” which was covered earlier. This will compile and has the potential to produce the same effect as with the module. (Note that in Visual Studio you must first go to Project->Properties and change the startup object.) This code snippet also demonstrates how classes are defined in Visual Basic.
Just because we can, however, doesn't mean that we should. Modules are infinitely more “VB-ish” and are what we're going to use here. The module of a new project is by default called Module1 and is contained within a file called Module1.vb. We can change this, however, to reflect the nature of our project. Change the filename to Game.vb. In Visual Studio, this will automatically change the module's name to Game (neat!):
Module Game
Sub Main()
End Sub
End Module
Next: Getting Started continued >>
More Visual Basic.NET Articles
More By Peyton McCullough