Code: |
require stdwindows #windows
object #demo is window title = "Rosetta Task: Simple windowed application" button #btn, "Click Me", btnClick, 20, 50, 100, 25 statictext #num, "There have been no clicks yet.", 20, 100, 240, 30 sub btnClick #sender static nClicks nClicks += 1 #num "The button has been clicked ";nClicks;" times." end sub end object #demo show() do wait while #windows count? end |
Require - a list of modules the program requires. The handle is optional and allows access to module-level methods.
Object - defines an object commonly called a Singleton. This is convenient when we don't need a full-blown class.
Is - indicates the parent from which a child class/object inherits some functionality.
Title - a method exposed by the Window class. The line could also be written title("Rosetta blah blah"). The equals sign can be used when a method has just one argument.
Button - a class exposed by StdWindows. The line it starts declares an object that is private to #demo. btnClick is the name of a subroutine. (I think no labeled event handlers for VF.) Unlike LB, UL and the like are optional. The button constructor literally takes a Rect object from which UL is derived. In VF, anywhere an object argument is expected, we can pass what that object's constructor expects instead. This may also allow for a flowing arrangement rather than pixel coordinates.
Sub - looks and works very much like LB. Subs and functions are private inside classes. If this were to use Method instead, that would be exposed.
Static - similar to LB's Global but the variable is local in scope to the sub. It lives as long as the object does.
+= - assigns the sum of the variable and the RHS expression to the same variable. Copied from C-like languages.
Show() - calls the method exposed by the Window class. Windows are hidden until explicitly shown.
Do - permits defining a very tight loop - one with just a single statement. The line waits for all windows to close. The question mark is an optional replacement for the empty parentheses.