Microsoft Visual Basic .NET
Implementation of programming language BasicVisual Basic .NET is an object-oriented implementation of Basic, developed by Microsoft Corporation to replace Visual Basic. Its version numbering continues the series of Visual Basic, but these implementations differ essentially. Porting code from Visual Basic to VB.NET is a non-trivial job, and though Microsoft provides an automated VB6-to-VB.NET converter as part of Visual Studio .NET, it still can’t process the conversion without programmer’s assistance.
Examples:
Hello, World!:
Example for versions Microsoft Visual Basic .NET 9 (2008), vbnc 2.4.2Module Module1
Sub Main()
Console.WriteLine("Hello, World!")
End Sub
End Module
Factorial:
Example for versions Microsoft Visual Basic .NET 9 (2008), vbnc 2.4.2This 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
Fibonacci numbers:
Example for versions Microsoft Visual Basic .NET 9 (2008), vbnc 2.4.2This 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.2Module 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
Comments
]]>blog comments powered by Disqus
]]>