X Tutup
Skip to content

Commit b2da845

Browse files
committed
sVB 3.1
1 parent bccc63c commit b2da845

File tree

42 files changed

+1368
-818
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1368
-818
lines changed

LangServices/CompilerService.vb

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,6 @@ Namespace Microsoft.SmallVisualBasic.LanguageService
581581

582582
' The exact type/method name is stored in the comment field
583583
textEdit.Replace(line.Start + token.Column, token.EndColumn - token.Column, token.Comment)
584-
FixParans(token, line, textEdit, True)
585584
Next
586585

587586
' fix local vars definitions
@@ -691,6 +690,40 @@ Namespace Microsoft.SmallVisualBasic.LanguageService
691690
' fix goto labels
692691
FixToken(id, line.Start, symbolTable.Labels, textEdit)
693692
FixParans(id, line, textEdit, True)
693+
694+
Case CompletionItemType.PropertyName
695+
Dim tokens = LineScanner.GetTokens(line.GetText(), id.Line)
696+
Dim n = tokens.Count - 1
697+
For i = 0 To n
698+
If tokens(i).Column = id.Column Then
699+
If i - 2 >= 0 Then
700+
Dim m = symbolTable.GetMethodInfo(tokens(i - 2), id)
701+
If m IsNot Nothing Then
702+
If i = n OrElse tokens(i + 1).Type <> TokenType.LeftParens Then
703+
textEdit.Insert(line.Start + id.EndColumn, "()")
704+
End If
705+
End If
706+
End If
707+
Exit For
708+
End If
709+
Next
710+
711+
Case CompletionItemType.MethodName
712+
Dim tokens = LineScanner.GetTokens(line.GetText(), id.Line)
713+
Dim n = tokens.Count - 1
714+
For i = 0 To n
715+
If tokens(i).Column = id.Column Then
716+
If i - 2 >= 0 Then
717+
Dim p = symbolTable.GetPropertyInfo(tokens(i - 2), id)
718+
If p IsNot Nothing Then
719+
If i < n - 1 AndAlso tokens(i + 1).Type = TokenType.LeftParens AndAlso tokens(i + 2).Type = TokenType.RightParens Then
720+
textEdit.Replace(line.Start + id.EndColumn, tokens(i + 2).EndColumn - id.EndColumn, "")
721+
End If
722+
End If
723+
End If
724+
Exit For
725+
End If
726+
Next
694727
End Select
695728
Next
696729

LangServices/CompletionKeyboardFilter.vb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ Namespace Microsoft.SmallVisualBasic.LanguageService
4646
End If
4747

4848
Case Key.Space, Key.Tab
49-
args.Handled = CommitConditionally(textView, completionSurface, " ")
49+
If CommitConditionally(textView, completionSurface, " ") Then
50+
textView.Caret.MoveToPreviousCaretPosition()
51+
args.Handled = True
52+
End If
5053

5154
Case Key.OemPeriod
5255
If Keyboard.Modifiers = 0 Then CommitConditionally(textView, completionSurface)

Readme.md

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<b><center><span style="font-size:3em;">Small Visual Basic 3.0:</span>
1+
<b><center><span style="font-size:3em;">Small Visual Basic 3.1:</span>
22
<br><br>
33
<span style="font-size:2em;">You can download the sVB installer from the <a href="https://marketplace.visualstudio.com/items?itemName=ModernVBNET.sVBInstaller"><u>VS marketplace</u></a>.</span>
44
<br><br></center></b>
@@ -17,11 +17,11 @@ Small Visual Basic is the visual version of Small Basic, and the small version o
1717

1818
* You can also double-click the "sVB docs" icon on the desktop to open the sVB reference PDF book, which contains the full documentation of the sVB IDE, syntax, and library.
1919

20-
* The reference book may not be the easiest way for kids and beginners to start learning sVB with, and this is why I am publishing the ["Small Visual Basic Kid Programmer" book series](https://a.co/d/5LGnE5m) on Amazon.
20+
* The reference book may not be the easiest way for kids and beginners to start learning sVB with, and this is why I am publishing the ["Small Visual Basic Kid Programmer" book series](https://www.amazon.com/dp/B0DNX2ZR4D) on Amazon.
2121

2222
<p align="center">
23-
<a href="https://a.co/d/5LGnE5m">
24-
<img src="https://modernvbnet.gallerycdn.vsassets.io/extensions/modernvbnet/svbinstaller/3.0/1714546030343/image__3.png"/>
23+
<a href="https://www.amazon.com/dp/B0DNX2ZR4D">
24+
<img src="blob:https://marketplace.visualstudio.com/5280dd5a-f721-4f5e-9064-11699bb3c994"/>
2525
</a>
2626
</p>
2727

@@ -104,5 +104,28 @@ Thread.SubToRun = Task1
104104
Thread.SubToRun = Task2
105105
```
106106

107+
* Small Visual Basic is easier than Python for kids and young beginners!
108+
1. Python is a full stack language, while sVB is only for desktop apps and only for educational purposes, which make it more focused on its purpose. But this doesn't mean sVB has no future, or it is just a toy. It is actually the doorway to a popular and powerful development platform: the DotNET and VS .NET. It is easy to use your understanding of sVB syntax, library, form designer, and even the code editor experience to move to VB .NET (and later to C# if you want). But actually sVB has some advanced topics, like designing a multi-form application, using XAML styles, using multi-threading and creating code libraries. sVB also comes with the LitDev external library that contains a 3D engine and a Physics engine, which allows endless advanced possibilities.
109+
2. Both Python and sVB are dynamically typed languages, but sVB is easier in this aspect, because it doesn't require type conversions.
110+
3. Python is case-sensitive (and surprisingly, the True and False keywords starts with uppercase letters), while sVB is case-insensitive, and the code editor makes sure to fix words to their original casing. This makes it more easier to learn.
111+
4. Python lists have 0-based indexes, while sVB arrays by default have 1-based indexes, which is more natural and easier for kids to deal with, but nothing prevents them from using the 0 index or even negative indexes, because arrays in sVB are actually dictionaries, so indexes are actually keys!
112+
5. Trigonometry functions use radian angles in Python. This is the default case in sVB, but you can disable this behavior to use degrees by using:
113+
Math.UseRadianAngles = False
114+
6. Python for loops can be confusing because of the range exclusive end:
115+
```py
116+
for i in range(5, 0, -1):
117+
print(i)
118+
```
119+
while for loops are very simple in sVB:
120+
```vb
121+
For I = 5 To 1 Step -1
122+
TW.WriteLine(I)
123+
Next
124+
```
125+
126+
7. Python block indentation is confusing for kids, and make nested statement harder to understand and more error borne because of miscounted spaces, while sVB uses end blocks (like EndIf, EndSub, and Next) which makes the code readable and well constructed. The sVB editor automatically adds the end block token while the kid is typing. It also adjusts block indentation and pretty-lists spaces and identifier casing. It even enforces a variable casing rule: local vars and parameters start with a lowercase, while global vars, subroutines and functions start with uppercase. So, in sVB, kids focus only on the code logic, not formatting!
127+
8. The sVB IDE is easy and powerful to deal with forms and graphics.
128+
129+
107130
* The sVB source code is fully written with VB .NET and published on [GitHub](https://github.com/VBAndCs/sVB-Small-Visual-Basic). All sVB projects are WPF projects, that target the .NET framework 4.5. You can run the source code in VS.NET 2019 and later. But before running the code, please copy the "Lib" and "Toolbar" folders from the "SmallBasicIDE\SB.Lib" folder to both "SmallBasicIDE\bin\Debug" and "SmallBasicIDE\bin\Release" folders.
108131

SBCompiler/SBCompiler/Statements/MethodCallStatement.vb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,6 @@ Namespace Microsoft.SmallVisualBasic.Statements
5656
MethodCallExpression.Evaluate(runner)
5757
Return If(SmallVisualBasic.Library.Program.IsTerminated, New EndDebugging(), Nothing)
5858
End Function
59+
5960
End Class
6061
End Namespace

SBCompiler/SBCompiler/SymbolTable.vb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Imports System.Globalization
22
Imports Microsoft.SmallBasic
33
Imports Microsoft.SmallVisualBasic.Expressions
4+
Imports Microsoft.SmallVisualBasic.Statements
45
Imports TokenDictionary = System.Collections.Generic.Dictionary(Of String, Microsoft.SmallVisualBasic.Token)
56

67
Namespace Microsoft.SmallVisualBasic
@@ -512,6 +513,32 @@ Namespace Microsoft.SmallVisualBasic
512513

513514
End Sub
514515

516+
Public Function GetMethodInfo(mc As MethodCallStatement) As System.Reflection.MethodInfo
517+
If mc Is Nothing Then Return Nothing
518+
Return GetMethodInfo(mc.MethodCallExpression)
519+
End Function
520+
521+
Public Function GetMethodInfo(mc As MethodCallExpression) As System.Reflection.MethodInfo
522+
If mc Is Nothing Then Return Nothing
523+
Return GetMethodInfo(mc.TypeName, mc.MethodName)
524+
End Function
525+
526+
Public Function GetMethodInfo(typeName As Token, methodName As Token) As System.Reflection.MethodInfo
527+
Dim typeInfo = Me.GetTypeInfo(typeName)
528+
If typeInfo Is Nothing Then Return Nothing
529+
Dim key = methodName.LCaseText
530+
If Not typeInfo.Methods.ContainsKey(key) Then Return Nothing
531+
Return typeInfo.Methods(key)
532+
End Function
533+
534+
Public Function GetPropertyInfo(typeName As Token, propName As Token) As System.Reflection.PropertyInfo
535+
Dim typeInfo = Me.GetTypeInfo(typeName)
536+
If typeInfo Is Nothing Then Return Nothing
537+
Dim key = propName.LCaseText
538+
If Not typeInfo.Properties.ContainsKey(key) Then Return Nothing
539+
Return typeInfo.Properties(key)
540+
End Function
541+
515542
End Class
516543

517544
Friend Structure EventHandlerInfo
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
L = LblRange.Width
2+
St = LblRange.Left
3+
LblSrart.Width = 0
4+
LblEnd.Width = 0
5+
LblMsg.Width = 0
6+
TextBox1.Focus()
7+
Num = Math.GetRandomNumber(100)
8+
Trials = 0
9+
Start = Date.Now
10+
Min = 1
11+
12+
' ------------------------------------------------
13+
Sub BtnRand_OnClick()
14+
TextBox1.Text = ""
15+
Trials = 0
16+
LblRange.Left = St
17+
LblRange.Width = L
18+
Min = Math.Rnd(0, 10) * 10 + 1
19+
LblSrart.Text = Min - 1
20+
LblSrart.Right = St
21+
LblEnd.Text = Min + 100
22+
LblEnd.Left = LblRange.Right
23+
LblMsg.Text = Text.Format(
24+
"Guess a number between [1] and [2]",
25+
{Min, Min + 99}
26+
)
27+
Num = Math.Rnd(Min, Min + 99)
28+
TextBox1.Focus()
29+
Start = Date.Now
30+
EndSub
31+
32+
' ------------------------------------------------
33+
Sub BtnGuess_OnClick()
34+
BtnRand.Enabled = False
35+
d = Date.Now - Start
36+
n = TextBox1.Text
37+
Trials = Trials + 1
38+
Me.Text = Trials & " trials in " & Math.Round(d.TotalSeconds) & " seconds"
39+
40+
If n = Num Then
41+
Sound.PlayBeep()
42+
Forms.ShowMessage("Yes, that is right! You can play again.", "Well done!")
43+
BtnRand_OnClick()
44+
BtnRand.Enabled = True
45+
Return
46+
EndIf
47+
48+
Sound.PlayBellRing()
49+
x = St + (n - Min + 1) * L / 100
50+
51+
If LblRange.Left < x And LblRange.Right > x Then
52+
If n < Num Then
53+
LblRange.Left = x
54+
LblRange.Width = LblEnd.Left - LblRange.Left
55+
LblSrart.Text = n
56+
LblSrart.Right = LblRange.Left
57+
Else
58+
LblRange.Width = x - LblSrart.Right
59+
LblRange.Right = x
60+
LblEnd.Text = n
61+
LblEnd.Left = LblRange.Right
62+
EndIf
63+
EndIf
64+
65+
TextBox1.SelectAll()
66+
TextBox1.Focus()
67+
EndSub
68+
69+
70+
' ------------------------------------------------
71+
Sub TextBox1_OnKeyDown()
72+
If Event.LastKey = Keys.Enter Then
73+
BtnGuess_OnClick()
74+
Event.Handled = True
75+
EndIf
76+
EndSub
77+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
'@Form Hints:
2+
'#Form1{
3+
' LblMsg: Label
4+
' TextBox1: TextBox
5+
' BtnGuess: Button
6+
' Label2: Label
7+
' LblRange: Label
8+
' LblSrart: Label
9+
' LblEnd: Label
10+
' BtnRand: Button
11+
'}
12+
13+
Me = "form1"
14+
LblMsg = "form1.lblmsg"
15+
TextBox1 = "form1.textbox1"
16+
BtnGuess = "form1.btnguess"
17+
Label2 = "form1.label2"
18+
LblRange = "form1.lblrange"
19+
LblSrart = "form1.lblsrart"
20+
LblEnd = "form1.lblend"
21+
BtnRand = "form1.btnrand"
22+
_path = Program.Directory + "\form1.xaml"
23+
Form1 = Forms.LoadForm("Form1", _path)
24+
Form.SetArgsArr(form1, Stack.PopValue("_form1_argsArr"))
25+
'#Events{
26+
' BtnGuess: OnClick
27+
' TextBox1: OnKeyDown
28+
' BtnRand: OnClick
29+
'}
30+
31+
' BtnGuess Events:
32+
Control.HandleEvents(BtnGuess)
33+
Control.OnClick = BtnGuess_OnClick
34+
35+
' TextBox1 Events:
36+
Control.HandleEvents(TextBox1)
37+
Control.OnKeyDown = TextBox1_OnKeyDown
38+
39+
' BtnRand Events:
40+
Control.HandleEvents(BtnRand)
41+
Control.OnClick = BtnRand_OnClick
42+
43+
44+
Form.Show(Me)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<Canvas Background="#FFF0F0F0" Name="Form1" Width="590.393700787401" Height="329.92125984252" FlowDirection="LeftToRight" AutomationProperties.HelpText="Form1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib"><Canvas.Tag><s:Boolean>False</s:Boolean></Canvas.Tag><Label FontWeight="Bold" Name="LblMsg" Width="Auto" MaxWidth="Infinity" Height="34.0157480314961" MaxHeight="Infinity" Visibility="Visible" IsEnabled="True" Canvas.Left="117.165354330709" Canvas.Top="102.047244094488" AutomationProperties.Name="LblMsg"><TextBlock Text="Guess a number between 1 and 100" TextWrapping="Wrap" /></Label><TextBox HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" IsInactiveSelectionHighlightEnabled="True" Width="109.606299212598" MaxWidth="Infinity" Height="45.3543307086614" MaxHeight="Infinity" Visibility="Visible" IsEnabled="True" Canvas.Left="192.755905511811" Canvas.Top="245.669291338584" AutomationProperties.Name="TextBox1" xml:space="preserve" /><Button Foreground="#FF0000FF" FontWeight="Bold" Name="BtnGuess" Width="49.1338582677168" MaxWidth="Infinity" Height="41.5748031496063" MaxHeight="Infinity" Visibility="Visible" IsEnabled="True" Canvas.Left="321.259842519685" Canvas.Top="245.669291338583" AutomationProperties.Name="BtnGuess"><TextBlock Text="Try" TextWrapping="Wrap" /></Button><Label Background="#FF181616" Width="536.692913385827" MaxWidth="Infinity" Height="37.7952755905512" MaxHeight="Infinity" Visibility="Visible" IsEnabled="True" Canvas.Left="22.6771653543307" Canvas.Top="162.51968503937" AutomationProperties.Name="Label2"><TextBlock Text="Label2" TextWrapping="Wrap" /></Label><Label Background="#FF008000" Name="LblRange" Width="487.55905511811" MaxWidth="Infinity" Height="37.7952755905512" MaxHeight="Infinity" Visibility="Visible" IsEnabled="True" Canvas.Left="41.5748031496063" Canvas.Top="162.51968503937" AutomationProperties.Name="LblRange" AutomationProperties.HelpText=""><TextBlock TextWrapping="Wrap" /></Label><Label Background="#FF6F0B0B" Foreground="#FFFFFFFF" Name="LblSrart" Width="19.1633333333333" MaxWidth="Infinity" Height="37.8" MaxHeight="Infinity" Visibility="Visible" IsEnabled="True" Canvas.Left="22.6771653543307" Canvas.Top="162.51968503937" AutomationProperties.Name="LblSrart"><TextBlock Text="0" TextWrapping="Wrap" /></Label><Label Background="#FF6F0B0B" Foreground="#FFFFFFFF" Name="LblEnd" Width="37.49" MaxWidth="Infinity" Height="37.7952755905512" MaxHeight="Infinity" Visibility="Visible" IsEnabled="True" Canvas.Left="529.133858267717" Canvas.Top="162.51968503937" AutomationProperties.Name="LblEnd"><TextBlock Text="101" TextWrapping="Wrap" /></Label><Button Foreground="#FF0000FF" FontWeight="Bold" Name="BtnRand" Width="105.826771653543" MaxWidth="Infinity" Height="34.0157480314961" MaxHeight="Infinity" Visibility="Visible" IsEnabled="True" Canvas.Left="219.212598425197" Canvas.Top="45.3543307086614" AutomationProperties.Name="BtnRand"><TextBlock Text="Rand start" TextWrapping="Wrap" /></Button><Control Name="__FORM__PROPS__" Tag="{x:Null}" MinWidth="0" MaxWidth="Infinity" MinHeight="0" MaxHeight="Infinity" ToolTip="{x:Null}" Canvas.Left="Auto" Canvas.Top="Auto" /></Canvas>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
N = Math.GetRandomNumber(100)
2+
Win = False
3+
Count = 0
4+
5+
While Win = False
6+
TW.Write("Guess the number between 1 & 100: ")
7+
X = TW.ReadNumber()
8+
Count = Count + 1
9+
If X = N Then
10+
TW.WriteLine("Bravo. You win in " & Count & " steps.")
11+
Win = True
12+
ElseIf X < N Then
13+
TW.WriteLine("Try a bigger number!")
14+
Else
15+
TW.WriteLine("Try a smaller number!")
16+
EndIf
17+
Wend
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Turtle.Speed = 10
2+
Side1 = 200
3+
R = 0.5
4+
Angle1 = 60
5+
Angle2 = (90 - Angle1) * 2
6+
X1 = Turtle.X
7+
Y1 = Turtle.Y
8+
Turtle.TurnLeft()
9+
10+
Turtle.Turn(180 - Angle1)
11+
Turtle.Move(Side1)
12+
X2 = Turtle.X
13+
Y2 = Turtle.Y
14+
15+
Turtle.Turn(180 - Angle2)
16+
Turtle.Move(Side1)
17+
X3 = Turtle.X
18+
Y3 = Turtle.Y
19+
20+
W = (X3 - X1) / 2
21+
H = Y3 - Y2
22+
X4 = X1 + W
23+
Y4 = Y2 + R * H
24+
25+
Turtle.MoveTo(X4, Y4)
26+
Turtle.MoveTo(X1, Y1)

0 commit comments

Comments
 (0)
X Tutup