Skip to content

Commit f29e858

Browse files
committed
Added Visual Basic Programming Language
1 parent d7a0c83 commit f29e858

File tree

8 files changed

+130
-0
lines changed

8 files changed

+130
-0
lines changed

visualbasic/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bin
2+
obj

visualbasic/Clockhands.vb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Module Clockhands
2+
Sub Main()
3+
Dim t, h, m, s as Integer
4+
For i = 0 To 10
5+
t = (43200 * i + 21600) \ 11
6+
h = t \ 3600
7+
m = t \ 60 MOD 60
8+
s = t MOD 60
9+
Console.WriteLine("{0:D2}:{1:D2}:{2:D2}", If(h = 0, 12, h), m, s)
10+
Next
11+
End Sub
12+
End Module

visualbasic/Hello.vb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Module Clockhands
2+
Sub Main()
3+
Console.WriteLine("Hello, World!")
4+
End Sub
5+
End Module

visualbasic/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<img src="https://raw.githubusercontent.com/rtoal/polyglot/master/docs/resources/visualbasic-logo-64.png">
2+
3+
# Visual Basic Explorations
4+
5+
To build and run Visual Basic programs on your local machine, download and install the most recent language version from the [Dotnet installation page](https://dotnet.microsoft.com/en-us/download) or use your favorite package manager.
6+
7+
Programs in this folder have been tested using dotnet 9.0.203 and can be run from the command line like so:
8+
9+
```
10+
cat Triple.vb > project/Program.vb && dotnet run --project project
11+
```
12+
13+
```
14+
cat Triple.vb > project/Program.vb && dotnet run --project project I like carrots
15+
```
16+
17+
```
18+
cat Triple.vb > project/Program.vb && dotnet run --project project < ../test/wnba_input
19+
```
20+
21+
To run the tests on a Unix-like shell:
22+
23+
```
24+
./test.sh
25+
```
26+
27+
Run `test.ps1` in PowerShell.
28+
29+
## About Visual Basic
30+
31+
TODO
32+
33+
## Visual Basic Resources
34+
35+
Continue your study of Visual Basic with:
36+
37+
- [Official Documentation](https://learn.microsoft.com/en-us/dotnet/visual-basic/)
38+
- [Tutorials Point for Visual Basic](https://www.tutorialspoint.com/vb.net/index.htm)
39+
- [Visual Basic at Rosetta Code](https://rosettacode.org/wiki/Category:Visual_Basic)

visualbasic/Triple.vb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Module Triple
2+
Sub Main()
3+
For c = 1 To 40
4+
For b = 1 To c
5+
For a = 1 To b
6+
If (a ^ 2 + b ^ 2 = c ^ 2) Then
7+
Console.WriteLine("{0}, {1}, {2}", a, b, c)
8+
End If
9+
Next
10+
Next
11+
Next
12+
End Sub
13+
End Module

visualbasic/project/Program.vb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Module Triple
2+
Sub Main()
3+
For c = 1 To 40
4+
For b = 1 To c
5+
For a = 1 To b
6+
If (a ^ 2 + b ^ 2 = c ^ 2) Then
7+
Console.WriteLine("{0}, {1}, {2}", a, b, c)
8+
End If
9+
Next
10+
Next
11+
Next
12+
End Sub
13+
End Module
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<RootNamespace>visualbasic</RootNamespace>
6+
<TargetFramework>net9.0</TargetFramework>
7+
</PropertyGroup>
8+
9+
</Project>

visualbasic/test.ps1

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
function Assert-MatchTests {
2+
param (
3+
[Parameter(Mandatory = $true, ValueFromPipeline)] $TestResult
4+
)
5+
6+
if ($TestResult) {
7+
Write-Error "Output does not match expected results."
8+
}
9+
}
10+
11+
function Initialize-File {
12+
param (
13+
[Parameter(Mandatory = $true, ValueFromPipeline)] $FileName
14+
)
15+
16+
Get-Content "$PSScriptRoot\$FileName" > "$PSScriptRoot\project\Program.vb"
17+
}
18+
19+
# File path for the project folder.
20+
$project = "$PSScriptRoot\project"
21+
22+
$Error.clear()
23+
Initialize-File("Clockhands.vb") && dotnet run --project $project |
24+
Compare-Object (Get-Content "$PSScriptRoot\..\test\clockhands_expected") |
25+
Assert-MatchTests &&
26+
Initialize-File("Hello.vb") && dotnet run --project $project &&
27+
Initialize-File("Triple.vb") && dotnet run --project $project |
28+
Compare-Object (Get-Content "$PSScriptRoot\..\test\triple_expected") |
29+
Assert-MatchTests &&
30+
ForEach-Object 'foo'
31+
32+
if ($Error -or !$?) {
33+
"*** VISUAL BASIC TESTS FAILED ***"
34+
}
35+
else {
36+
"VISUAL BASIC TESTS PASSED"
37+
}

0 commit comments

Comments
 (0)