| You are here: | About>Computing & Technology>Visual Basic> Learn VB.NET> Visual Basic .NET 2008 Express - About Programming |
![]() | Visual Basic |
Visual Basic .NET 2008 Express - About ProgrammingJan 19 2008 Hello World as a SubroutineIt's time to write more programming code! As promised earlier, the instructions for this example program are at a little higher level this time. I won't explain every detail to keep the instructions a little shorter. The example this time will be a Hello World program like Part 1, but this time, it will be coded as a subroutine (something we will see a lot of in future lessons) in a separate module. This is the first step in creating real objects. One of the main ideas in system development methodology is to "divide and conquer" - that is, divide programs into objects and conquer complexity. The more usual name is OOP - Object Oriented Programming. The code we will create in this lesson still falls short of being an actual object. We'll discuss why in later lessons. We will also use quite a few new VB.NET language elements. There will be more about them in later lessons. The idea in this program is try out software development methodology, become more familiar with coding a VB.NET Express program, and get a peek at things to come. But first, let's make sure we keep our code in sync with the SDLC, starting with the System Request! System Request Notice that no technical jargon is used in the request. I didn't say "using OOP" for example. The System Request should be stated as simply as possible and still be fairly precise. In this case, you are the "System Owner" and the developer too. That's not a good combination in the real world, but this is a tutorial! Analysis -------- Design -------- Programming Open the "Hello World" program from Part 1. We'll use this as a starting point for our new version. Because we're object oriented programmers, we're going to create a new module for the part of the system that actually displays the message in different languages. So the first step is to add a new module to the project (right-click the project in Solution Explorer and select Add, then Module ...). Remember that it's a good idea to rename objects as soon as they're created (I called it "HelloModule"). Click inside the module and type the statement: Sub SayHello(ByVal HelloLanguage As String) Notice the Intellisense. That's a feature of VB.NET Express and Visual Studio that suggests coding for you to speed development and prevent errors. Intellisense adds the End Sub statement automatically as soon as you press the Enter key. Now we're going to insert a Select Case block. This is just one way to add conditional logic to your VB.NET Express program. We'll see this topic again later in the course, but if you think about it, the way it works is easy to figure out. The variable HelloLanguage has a value assigned to it. If that value is any of the first three cases, then the statement following is executed. If it's not, the statement following Case Else is executed. Select Case HelloLanguage The completed HelloModule is shown in the illustration. -------- It should be noted that we're doing this in the reverse order of "top down structured programming". To do it "right" we should code the main parts of the program first and then code the "black boxes". But since this is a tutorial, we coded the subroutine first. Now that we have a working subroutine, we can code the rest of the system. We do that on the next page. |
Las Vegas on a BudgetFind a BargainHotel DealsCheap EatsFree AttractionsEntertainment for Less |
All Topics | Email Article | | | ![]() |
| Advertising Info | News & Events | Work at About | SiteMap | Reprints | Help | Our Story | Be a Guide |
| User Agreement | Ethics Policy | Patent Info. | Privacy Policy | ©2008 About, Inc., A part of The New York Times Company. All rights reserved. |


