Developing Your First .NET Programs


In this section, you will create a .NET program. You will use the Console Application project template type. The application will display text onto the console window. First you will use COBOL .NET and then you will use VB .NET.

COBOL .NET Example

Start your COBOL .NET example as follows :

  1. Launch VS .NET.

  2. From the Get Started screen view (see Figure 5-14), click New Project to display the dialog box.

    click to expand
    Figure 5-14: Select New Project from the Get Started screen.

  3. Select COBOL Projects from the Project Types window (as shown in Figure 5-15). Select Console Application from the Templates window. Change the name of the application to MyFirstCobolExample , and then click OK.

    click to expand
    Figure 5-15: The New Project dialog box after making selections and changing the default project name

    Tip  

    If you want to see the traditional COBOL line numbers , select Tools Options Text Editor COBOL Reference Format.

  4. You should now see an empty program template. All of the lines of code provided should look very familiar to you. Make small adjustments to lines 20 and 80 in the template as shown here:

     000010 IDENTIFICATION DIVISION. 000020 PROGRAM-ID. MAIN. 000030 ENVIRONMENT DIVISION. 000040 DATA DIVISION. 000050 WORKING-STORAGE SECTION. 000060 PROCEDURE DIVISION. 000070  000080 END PROGRAM MAIN. 
  5. Using the DISPLAY statement and a variable definition that you are familiar with, enter the following basic pieces of code into the console, starting at line 60:

     000010 IDENTIFICATION DIVISION. 000020 PROGRAM-ID. MAIN. 000030 ENVIRONMENT DIVISION. 000040 DATA DIVISION. 000050 WORKING-STORAGE SECTION. 000060 01 NULL-X PIC X(1). 000070 PROCEDURE DIVISION. 000080    DISPLAY "Hello, .NET World.". 000090    DISPLAY "I Cannot believe how simple this is!". 000100    DISPLAY "Enter X and Press Enter to Exit.". 000110    ACCEPT NULL-X.  000120 END PROGRAM MAIN. 
  6. Before you are able to build (compile) the program, you need to change the project properties. To perform this function, begin by opening the Solution Explorer window.

    Note  

    The Solution Explorer window may already be open. If it isn't, you can open it by selecting View Solution Explorer or by pressing Ctrl-Alt-L.

  7. In the Solution Explorer window, locate the project file, as shown in Figure 5-16.

    click to expand
    Figure 5-16: Find the project file in the Solution Explorer window.

  8. Right-click the MyFirstCobolExample project.

  9. Select Properties from the shortcut menu to display the Property Pages window.

  10. Locate the entry name (about three lines from the top) and change it from Program1 to MAIN . Click OK.

  11. t is now time to build (compile) the solution. Select Build Build Solution. The Output window should appear at the bottom of the screen, indicating that the build was successful.

  12. Run the application by selecting Debug Start.

Congratulations! Your completed code should resemble Figure 5-17.

click to expand
Figure 5-17: The completed code example looks like this.

I provided this sample application to warm you up a little. Naturally, I had to stick with tradition and create a "Hello, World" program to get things started (even if I did change it slightly). Obviously, there is much more to learn about COBOL on the .NET platform, .NET's common language runtime (CLR), XML access, the .NET Framework, and much more. You have gotten off to a good start. I am sure that you will enjoy the learning experiences that await you in each and every remaining chapter.

VB .NET Example

You should be all warmed up now. You have seen some COBOL code (or rather COBOL .NET code). In this section, you will move on to create another console application using VB .NET.

  1. Click the New Project button on the Get Started screen, as shown in Figure 5-18.

    click to expand
    Figure 5-18: Notice that the previous COBOL .NET example is shown in the recent projects found list.

  2. In the New Project dialog box, select Visual Basic Projects from the Project Types window and Console Application from the Templates window. This time you will change the name of the project to MyFirstVBExample (see Figure 5-19). After you have done so, click OK.

    click to expand
    Figure 5-19: The New Project dialog box with VB .NET selections

  3. As in the previous section's example, you should now be viewing an empty template. The template contains a very basic skeleton into which you will build your application. The following lines represent your "skeleton code" in the VB .NET console application template:

     Module Module1     Sub Main()     End Sub End Module 
  4. Enter some VB .NET code to display in the console window. In keeping with tradition, use the following lines of code to complete the "Hello, World" application:

     Module Module1     Sub Main()        Console.WriteLine("Hello, .NET World.")        Console.WriteLine("I Cannot believe how simple this is!")        Console.WriteLine("Press Enter to Exit.")        Console.ReadLine()     End Sub End Module 
  5. Build (compile) the solution by selecting Build Build Solution. As before (with the COBOL .NET example), the Output window should appear at the bottom of the screen, indicating that the build was successful. Start the VB .NET application by selecting Debug Start. (Optionally, you can press F5 to start the application.)

Again, congratulations! You are now an official VB .NET programmer. Your completed console application should resemble the one shown in Figure 5-20.

click to expand
Figure 5-20: The completed VB .NET console application looks like this.

Now that you have completed your obligatory "Hello, World" applications, suffice it to say that you are officially welcomed into the .NET world. You are now prepared for the deep dive into .NET.




COBOL and Visual Basic on .NET
COBOL and Visual Basic on .NET: A Guide for the Reformed Mainframe Programmer
ISBN: 1590590481
EAN: 2147483647
Year: 2003
Pages: 204

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net