Mono VB.NET

Implementation of programming language Basic

Mono VB.NET is an open-source implementation of Visual Basic .NET. Mono provided complete support of VB.NET since Mono 1.2.3.

Examples:

Factorial:

Example for versions Microsoft Visual Basic .NET 9 (2008), vbnc 2.4.2

This example uses recursive factorial definition.

Module Module1
    Function Factorial(ByVal n As Integer) As Long
        If n = 0 Then
            Return 1
        Else
            Return n * Factorial(n - 1)
        End If
    End Function

    Sub Main()
        For i As Integer = 0 To 16
            Console.WriteLine(i & "! = " & Factorial(i))
        Next
    End Sub
End Module

Hello, World!:

Example for versions Microsoft Visual Basic .NET 9 (2008), vbnc 2.4.2
Module Module1
    Sub Main()
        Console.WriteLine("Hello, World!")
    End Sub
End Module

Fibonacci numbers:

Example for versions Microsoft Visual Basic .NET 9 (2008), vbnc 2.4.2

This example uses recursive definition of Fibonacci numbers.

Module Module1
    Function Fibonacci(ByVal n As Integer) As Long
        If n < 3 Then
            Return 1
        Else
            Return Fibonacci(n - 1) + Fibonacci(n - 2)
        End If
    End Function

    Sub Main()
        For i As Integer = 1 To 16
            Console.Write(Fibonacci(i) & ", ")
        Next
        Console.WriteLine("...")
    End Sub
End Module

Quadratic equation:

Example for versions Microsoft Visual Basic .NET 9 (2008), vbnc 2.4.2
Module Module1
    Sub Main()
        Dim A, B, C, D As Integer
        Dim p1, p2 As Double
        Try
            Console.Write("A = ")
            A = Val(Console.ReadLine())
            Console.Write("B = ")
            B = Val(Console.ReadLine())
            Console.Write("C = ")
            C = Val(Console.ReadLine())
        Catch ex As Exception
            Console.WriteLine("Invalid input.")
            Return
        End Try
        If A = 0 Then
            Console.WriteLine("Not a quadratic equation.")
            Return
        End If
        D = B * B - 4 * A * C
        p1 = -B / 2.0 / A
        p2 = Math.Sqrt(Math.Abs(D)) / 2.0 / A
        If D = 0 Then
            Console.Write("x = " & p1.ToString())
        ElseIf D > 0 Then
            Console.WriteLine("x1 = " & (p1 + p2).ToString())
            Console.WriteLine("x2 = " & (p1 - p2).ToString())
        Else
            Console.WriteLine("x1 = (" & p1.ToString() & "," & p2.ToString() & ")")
            Console.WriteLine("x2 = (" & p1.ToString() & ",-" & p2.ToString() & ")")
        End If
    End Sub
End Module

CamelCase:

Example for versions vbnc 2.4.2

This program checks each letter of the string for being a letter; if it is not, it is replaced with a space. After this the string is converted to proper case (all words are lower case, starting with capital letter), and finally all spaces are removed.

Module Module1
    Sub Main()
        Dim Text As String
        Dim i As Long
 
        Try
            Text = LCase(Console.ReadLine())
        Catch ex As Exception
            Console.WriteLine("Invalid input.")
            Return
        End Try
 
        For i = 1 To Len(Text) Step 1
            If InStr("abcdefghijklmnopqrstuvwxyz", GetChar(Text, i)) = 0 Then
                Text = Replace(Text, GetChar(Text, i), " ")
            End If
        Next
        Console.WriteLine(Replace(StrConv(Text, vbProperCase), " ", ""))
    End Sub
End Module