dbox
Junior Member
Posts: 84
|
Post by dbox on Apr 10, 2023 20:33:27 GMT
Starting a thread here to post fun facts about QBJS that you might not know. Fun Fact #1 - You can define optional parameters! PrintLines "First Test" PrintLines "Second Test", 4 PrintLines "Third Test", , " -> "
Sub PrintLines (msg As String, lines As Integer, prefix As String) If lines = undefined Then lines = 2 ' default to 2 lines If prefix = undefined Then prefix = "" ' default to blank prefix Dim i As Integer For i = 1 To lines Print prefix; msg Next i End Sub
Output: Try it out on QBJS
|
|
dbox
Junior Member
Posts: 84
|
Post by dbox on Apr 11, 2023 21:18:48 GMT
Fun Fact #2 - Custom types can be returned from functions! Screen 12
Type Circ x As Integer y As Integer r As Integer c As Integer End Type
Dim i As Integer Dim c As Circ Do Cls For i = 1 To 100 c = MakeCircle Circle (c.x, c.y), c.r, c.c Next i _Limit 10 Loop
Function MakeCircle Dim c As Circ c.x = Rnd * 640 c.y = Rnd * 480 c.r = Rnd * 100 + 10 c.c = Rnd * 14 + 1 MakeCircle = c End Function Try it on QBJS
|
|
dbox
Junior Member
Posts: 84
|
Post by dbox on Apr 13, 2023 11:45:15 GMT
Fun Fact #3 - QBJS has native support for associative arrays (dictionary). This feature is sometimes also known as a map or hashmap. Dim colors() As _Unsigned Long
colors("brick red") = &HFFC62D42 colors("electric lime") = &HFFCCFF00 colors("metalic sunburst") = &HFF9C7C38
Cls , 15 Line (10, 10)-(100, 100), colors("electric lime"), BF Line (200, 200)-(300, 300), colors("brick red"), BF Circle (200, 100), 50, colors("metalic sunburst") Try it on QBJS
|
|
dbox
Junior Member
Posts: 84
|
Post by dbox on Apr 21, 2023 14:02:22 GMT
Fun Fact #4 - You can call native Javascript from your QBJS program! Here's a simple example that utilizes the browser's text-to-speech functionality: Dim s As String Print "What would you like me to say?" Line Input s Say s
Sub Say (text As String) Dim success As Integer
$If Javascript Then if (window.speechSynthesis) { var utterance = new SpeechSynthesisUtterance(text); window.speechSynthesis.speak(utterance); success = -1; } $End If If Not success Then Print "Sorry, this is not supported in your browser." End If End Sub Try it on QBJS!
|
|