What's new in sVB v1.7
- Add
ForEach
statement to the language. It is easier for iterating through arrays that have items with string keys. Ex:
arr[1] = "One"
arr["test"] = "Hello"
arr!Name = "Ahmad"
ForEach item In arr
TextWindow.WriteLine(item)
Next
The above code will print:
One
Hello
Ahmad
-
Add
Append
andAppendLine
methods to the TextBox control, andItems
andRemoveAllItems
to the ListBox control. See the For Each Sample in the Samples folder. -
Infer var types from initial values. This allows to call some methods directly from the var name. For example:
x = "abc"
x = x.Append("efg")
TextWindow.WriteLine(x) ' abcefg
Note That:
- string variables call methods of the
Text
class. - double (numertic) variables call methods of the
Math
class. - color variables call methods of the
Color
class. - array variables call methods of the
Array
class.
The editor intellisense provides you with info about the var type and auto completion list shows the available methods it can call.
Note that:
- sVB is still a dynamic type language, so, you can still store any value in the variable regardless its inferred type. I don't advice you to do that, as you should keep your code clean and readable.
- sVB can't infer the type in some cases, such as:
- you initialize the var from a call to a function you wrote.
- you initialize the var from a calculated expression or operator, even a simple addition one, as sVB will decide the value at runtime only.
- sub and function params can't be inferred unless you named them using one of the naming conventions for data, controls, colors and keys.
In such cases, you can initialize the var with ""
for strings, 0
for numerics, or {}
for arrays, then add the value to it in the next line.
- Variables that contain the word
color
is considered to be aColor
and when you assign a value for them, the auto completion list suggests theColors
class to choose a color from it's members.
The same for the word key, which is considered to be aKey
, and auto completion offers the Keys class to choose from its members. This makes it easy to deal with the pressed key in Keyboard events, such as using theEvent.LastKey
property.