VBScript 5.8
Version of implementation VBScript of programming language BasicThe last version of VBScript as a standalone engine. After it the language was incorporated in ASP.NET.
Examples:
Hello, World! - Basic (466):
The program outputs the message into console, and thus should be executed using cscript.exe
.
WScript.Echo("Hello, World!")
Factorial - Basic (467):
This example shows iterative factorial calculation. Note that no overflow happens, though the type of factorial variable is inferred from its usage and never set explicitly.
f = 1
For i = 0 To 16
WScript.Echo(i & "! = " & f)
f = f * (i + 1)
Next
Fibonacci numbers - Basic (468):
This program calculates Fibonacci numbers recursively. Note the absence of a lot of elements typical for other Basic dialects: variable declarations and function return type, explicit number-to-string conversion before concatenation etc.
Function Fibonacci(N)
If N < 2 Then
Fibonacci = N
Else
Fibonacci = Fibonacci(N - 1) + Fibonacci(N - 2)
End If
End Function
For i = 1 To 16
res = res & Fibonacci(i) & ", "
Next
WScript.Echo (res & "...")
CamelCase - Basic (469):
Unlike many other Visual Basic versions, VBScript has no StrConv
function. In the end character-by-character processing of the string turns out to be easier.
Text = LCase(WScript.StdIn.ReadLine)
CamelCase = ""
WasSpace = True
For i = 1 To Len(Text)
Ch = Mid(Text, i, 1)
If InStr("abcdefghijklmnopqrstuvwxyz", Ch) = 0 Then
WasSpace = True
Else
If WasSpace Then
CamelCase = CamelCase & UCase(Ch)
Else
CamelCase = CamelCase & Ch
End If
WasSpace = False
End If
Next
WScript.Echo CamelCase
Quadratic equation - Basic (470):
Function GetInt()
Input = WScript.StdIn.ReadLine
If not IsNumeric(Input) Then
WScript.Echo "Coefficient is not a number."
WScript.Quit
End If
GetInt = CInt(Input)
End Function
A = GetInt()
If A = 0 Then
WScript.Echo "Not a quadratic equation."
WScript.Quit
End If
B = GetInt()
C = GetInt()
D = B * B - 4 * A * C
p1 = -B / 2.0 / A
p2 = Sqr(Abs(D)) / 2.0 / A
If D = 0 Then
WScript.Echo "x = " & p1
Else
If D > 0 Then
WScript.Echo "x1 = " & (p1 + p2)
WScript.Echo "x2 = " & (p1 - p2)
Else
WScript.Echo "x1 = (" & p1 & ", " & p2 & ")"
WScript.Echo "x2 = (" & p1 & ", " & -p2 & ")"
End If
End If
Comments
]]>blog comments powered by Disqus
]]>