Microsoft Visual Basic .NET 9 (2008)
Version of implementation Microsoft Visual Basic .NET of programming language BasicMicrosoft Visual Basic .NET, version 9, released in 2008 as part of Microsoft Visual Studio 2008.
Examples:
Hello, World! - Basic (64):
Module Module1
Sub Main()
Console.WriteLine("Hello, World!")
End Sub
End Module
Factorial - Basic (65):
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
Fibonacci numbers - Basic (66):
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 - Basic (181):
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
Comments
]]>blog comments powered by Disqus
]]>