Saturday, May 18, 2013

Cross-platform and open-source development

Cross-platform and open-source development

The creation of open-source tools for VB.NET development has been slow compared to C#, although the Mono development platform provides an implementation of VB.NET-specific libraries and a VB.NET 8.0 compatible compiler written in VB.NET, as well as standard framework libraries such as Windows Forms GUI library.
SharpDevelop and MonoDevelop are open-source alternative IDEs.

Examples

The following is a very simple VB.NET program, a version of the classic "Hello world" example created as a console application:
Module Module1
 
    Sub Main()
        Console.WriteLine("Hello, world!")
    End Sub
 
End Module
The effect is to write the text Hello, world! to the command line. Each line serves a specific purpose, as follows:
Module Module1
This is a module definition, a division of code similar to a class, although modules can contain classes. Modules serve as containers of code that can be referenced from other parts of a program.
It is common practice for a module and the code file, which contains it, to have the same name; however, this is not required, as a single code file may contain more than one module and/or class definition.
Sub Main()
This is the entry point where the program begins execution. Sub is an abbreviation of "subroutine."
Console.WriteLine("Hello, world!")
This line performs the actual task of writing the output. Console is a system object, representing a command-line interface and granting programmatic access to the operating system's standard streams. The program calls the Console method WriteLine, which causes the string passed to it to be displayed on the console. Another common method is using MsgBox (a Message Box).
This piece of code is a solution to Floyd's Triangle:
Imports System.Console
 
Module Program
 
    Sub Main() 
        Dim rows As Integer
 
        ' Input validation.
        Do Until Integer.TryParse(ReadLine("Enter a value for how many rows to be displayed: "),
rows) AndAlso rows >= 1 
            WriteLine("Allowed range is 1 and {0}", Integer.MaxValue) 
        Loop
 
        ' Output of Floyd's Triangle
        Dim current = 1
 
        For row = 1 To rows
            For column = 1 To row 
                Write("{0,-2} ", current) 
                current += 1
            Next
 
            WriteLine()
        Next 
    End Sub
 
    ''' <summary>
    ''' Shadows Console.ReadLine with a version which takes a prompt string.
    ''' </summary>    
    Function ReadLine(Optional prompt As String = Nothing) As String
        If prompt IsNot Nothing Then
            Write(prompt)
        End If
 
        Return Console.ReadLine()
    End Function 
 
End Module

No comments:

Post a Comment