DynamicCSS

I was reading a book I checked out from the library on using JavaScript and CSS, and one of the examples it provided was Dynamically switching Style Sheets. I was wondering if RB could do the same thing natively, and sure enough, it can. You need two files for this.

This one, you should save as switch: code format="vb" Function Switch(num) Select Case num Case 1 Call BlackOnWhite Case 2 Call WhiteOnBlack End Select End Function

'These two are subs so they can't be called from the main program Sub BlackOnWhite CSSID #test, "{Color: black; Background-Color: white;}" End Sub

Sub WhiteOnBlack CSSID #test, "{Color: white; Background-Color: black;}" End Sub code

As you can see, not very much there. Just switching the background and text colors based on the parameter passed to the function. The reason I didn't include the CSS styles within the Select Case is that sometimes CSS styles can get very lengthy, and it would be harder to sort through the Select Case. Actually, this is also the reason I didn't just include this in the main program; because then you can keep all your CSS code in one file and your main program in another.

The second file doesn't need to be saved as anything specific: code format="vb" run "switch", #switch Div test Print "This is a test." End Div

link #1, "White background, black text", [w] print  'To separate the links link #2, "Black background, white text", [b]

wait
 * 1) switch Switch(1) 'Use this one automatically

[w] wait
 * 1) switch Switch(1) 'Black-on-white

[b] wait code
 * 1) switch Switch(2) 'White-on-black

This code runs the first file in sync, and assigns it the handle #switch. This is why you were supposed to save the first one as switch. It sets up two links to switch between the types, and sets up a Div block that will be changed. The links call the Switch function with a value based on what you clicked. If you run it, clicking the links will switch the text depending on what link you clicked on!

This is very rudimentary, but you can obviously store many different CSS styles in one document. If you want more, just add another Case and another sub. Very simple!