Link

Link
toc A **Link** in Run BASIC is the equivalent of a button in Liberty BASIC. It has the following syntax:

LINK #handle, labelExpr$, handler - Add a link to the web page with #handle, labelExpr$, and handler

The labelExpr$ is the text the user sees. When the user clicks on the link, the event handler specified is activated. It can be either a sub or a branch label. If the handler is a sub, the handle of the link is passed into the sub. If the handler is a branch label, the global variable EventKey$ is set to be the handle of the link.

Here is a short demo.

code format="vbnet" 'create a link with sub event handler link #doStuff, " Do Stuff ", doStuff print:print

'create a link with branch label event handler link #doMore, " Do More ", [doMore]

wait

sub doStuff handle$ print:print "Handle is ";handle$ end sub

[doMore] print:print "Handle is ";EventKey$ wait code

LINK methods
Links have the following methods:


 * 1) handle CSSCLASS //- Set the CSS class tag//
 * 2) handle SETKEY(stringExpr$) //- Set the link's event key to stringExpr$//
 * 3) handle ISNULL //- Returns zero (or false)//
 * 4) handle DEBUG$ //- Returns the string "Link"//

CSSClass
You can set the CSSClass tag for a link. This is handy if you want to make the link look like a button. This requires some basic knowledge of CSS. (CSS means Cascading Style Sheets.) You can learn more here: http://www.w3schools.com/css/default.asp

You'll also want to visit SimpleCSSDesigns on this wiki.

The HTML tag for a link is "a" as in the HTML for a link

code Run BASIC Home Page code

The CSSCLASS definition should also begin with "a.". The "a" can be omitted, but the be sure to use the dot. Some possible link class names:

a.linkButton .linkButton a.fancyButton .fancyButton

To invoke those styles, use the **CSSCLASS** statement, placing the CSSCLASS name inside of quotation marks, without the "a.":


 * 1) handle CSSClass("linkButton")
 * 2) handle CSSCLASS("fancyButton")

Here is a short demo that causes the links in the demos above to look like buttons.

code format="vbnet" 'create a link with sub event handler link #doStuff, " Do Stuff ", doStuff print " ":print

'create a link with branch label event handler link #doMore, " Do More ", [doMore]

'minimum CSSClass to make a link look like a button CSSClass "a.linkButton", "{       Width: 140px;        Height: 30px;        Text-Align: Center;        Border-Width: Medium;        Border-Style: Outset;        Text-Decoration: None;        Display: Block;    }"

'more styles added CSSClass "a.fancyButton", "{       Text-Decoration: None;        Font-Size: 16pt;        Font-Weight: Bold;        Width: 140px;        Height: 30px;        Display: Block;        Background: #C0C0C00;        Color: #000000;        Text-Align: Center;        Border-Width: Thick;        Border-Style: Outset;        Border-Color: #AAAAAA;    }"

wait
 * 1) doStuff CSSClass("linkButton")
 * 2) doMore CSSCLASS("fancyButton")

[doMore] print "EventKey$ is ";EventKey$ wait

sub doStuff key$ print " ":print print "Key$ is ";key$ end sub code

SETKEY
When the user clicks on a link and there is a key set on that link then the handler will use that key instead of the name of the handle. It will be passed into the sub if the handler is a sub. It will be assigned to the global variable EventKey$ if the handler is a branch label.

Here is a demo of **SETKEY** in action.

code format="vbnet" 'create a link with sub event handler link #doStuff, " Do Stuff ", doStuff print " " :print " "

'create a link with branch label event handler link #doMore, " Do More ", [doMore]

wait
 * 1) doStuff setkey("New Do Stuff Key")
 * 2) doMore setkey("New Do More Key")

sub doStuff handle$ print " ":print "Handle is ";handle$ end sub

[doMore] print " ":print "Handle is ";EventKey$ wait code


 * setkey** can also pass numeric values

code format="vbnet" link #lk1,"[Link 1]",doIt wait
 * 1) lk1 setkey(20)

sub doIt key print key*2 'more code end sub code

ISNULL and DEBUG$
This code demonstrates the **Debug$** and **IsNull** methods:

code format="vbnet" '#handle ISNULL //- Returns zero (or false)// print "Before creation, IsNull returns:" print #doStuff isnull

'create a link with sub event handler link #doStuff, " Do Stuff ", doStuff print:print print "Object is a ";#doStuff debug$print print "After creation, IsNull returns:" print #doStuff isnull wait

sub doStuff handle$ print " ":print "Handle is ";handle$ end sub code