What's new in sVB v2 ?
-
Each project can contain a Global.sb file. You can create it just by double-clicking the Global.sb item in the project explorer.
In this file, you can declare global variables, subroutines and functions that you can use in any form in the project via theGlobal
type, such asGlobal.DoSomething()
See theShow Random Buttons 3
andShow Dialogs
apps in the samples folders. -
The toolbox got a new
ComboBox
control. -
Controls got
RightToLeft
,ToolTip
andErrors
properties.
The Error property sets the error message to display in the tooltip of the control while its borders becomes red. You can restore the normal state of the control by setting the Error
property to an empty string. -
Controls also got the
OnGotFocus
andOnLostFocus
events, so, you can use theOnLostFocus
event with theError
property to provide a validation logic for input controls. Each control also has theValidate
method that fires theOnLostFocus
event to execute your validation logic (if exists), then checks the Error property and returnsTrue
if it is empty. And to make things easier for you, theValidate
method of the form calls the Validate method of each control on the form. If any controls has errors, the process stops and the focus goes to this contols with a beep sound. So, you should callMe.Validate
before you execute you app logic. Ex:
Sub Button1_OnClick()
If Me.Validate() Then
Me.ShowMessage("OK", "")
EndIf
EndSub
But if you want to do anything else when a control input is not valid, you can validate each control your self:
Sub Button1_OnClick()
ForEach control1 In Me.Controls
If control1.Validate() = False Then
Sound.PlayBellRing()
control1.Focus()
' Do more things here if you want
Return
EndIf
Next
Me.ShowMessage("OK", "")
EndSub
For a full example, see the Validation
app in the samples folder.
- sVB now tries to infer the type of an expression, and the type of the function return value.