📄 yabasic.htm
字号:
gives you a specific ascii-character: <font face="Courier New"><strong>print asc("e")</strong></font> gives 101 as a result, because the character <font face="Courier New"><strong>"e"</strong></font> has position <font face="Courier New"><strong>101</strong></font> within the ascii-charset. Likewise the function <font face="Courier New"><strong>chr$()</strong></font> returns the ascii-char for a given position within the charset, e.g. <font face="Courier New"><strong>chr$(98)</strong></font> returns <font face="Courier New"><strong>"b"</strong></font>.</dd> <dt><a name="Escape-sequences"><strong>Escape-sequences</strong></a></dt> <dd>Nevertheless you won't use <font face="Courier New"><strong>chr$()</strong></font> as often as you might think, because the most important nonprintable characters can be constructed using escape-sequences with the <font face="Courier New"><strong>\</strong></font>-character: You might use <font face="Courier New"><strong>\n</strong></font> instead of <font face="Courier New"><strong>chr$(10)</strong></font> wherever you want to use the newline-character.</dd> <dd>The following table lists all escape sequences of yabasic (of course, these are just the sequences known within the C-language):<br> </dd> <dd><table border="1"> <tr> <td align="center"><strong>Escape-sequence</strong></td> <td><strong>Resulting Char</strong></td> </tr> <tr> <td align="center"><font face="Courier New"><strong>\n</strong></font></td> <td>newline</td> </tr> <tr> <td align="center"><font face="Courier New"><strong>\t</strong></font></td> <td>tabulator</td> </tr> <tr> <td align="center"><font face="Courier New"><strong>\v</strong></font></td> <td>vertical tabulator</td> </tr> <tr> <td align="center"><font face="Courier New"><strong>\b</strong></font></td> <td>backspace</td> </tr> <tr> <td align="center"><font face="Courier New"><strong>\r</strong></font></td> <td>carriage return</td> </tr> <tr> <td align="center"><font face="Courier New"><strong>\f</strong></font></td> <td>formfeed</td> </tr> <tr> <td align="center"><font face="Courier New"><strong>\a</strong></font></td> <td>alert</td> </tr> <tr> <td align="center"><font face="Courier New"><strong>\\</strong></font></td> <td>backslash</td> </tr> <tr> <td align="center"><font face="Courier New"><strong>\`</strong></font></td> <td>single quote</td> </tr> <tr> <td align="center"><font face="Courier New"><strong>\"</strong></font></td> <td>double quote</td> </tr> </table> </dd> <dd><br> These escape sequences are replaced within every pair of doublequotes (<font face="Courier New"><strong>""</strong></font>), i.e. within literal strings; user input read with the<font face="Courier New"><strong> input</strong></font>-statement is not affected in any way.<br> Finally note, that escape sequences have a profound impact, when specifying <a href="#Specifying Window-pathnames">Window-pathnames</a>.</dd> <dd> </dd></dl><p>Here is another example which introduces the rest of yabasic'sstring-functions:</p><blockquote> <dl> <dd><pre><strong>label loop print "Please enter a string containing the word \"yabasic\"" input a$if (instr(lower$(a$),"yabasic")<>0) then gosub thanxelse print "No, please try again !"endifgoto looplabel thanx print "Thanks a lot !"return</strong></pre> </dd> </dl></blockquote><p>If you run this program you will receive the following output:</p><blockquote> <dl> <dd><pre><strong>Please enter a string containing the word "yabasic"?</strong><em><strong><u>thequickbrownfox</u></strong></em><strong>No, please try again !Please enter a string containing the word "yabasic"?</strong><em><strong><u>jumpedyabasicoverthelazydog</u></strong></em><strong>Thanx.</strong></pre> </dd> </dl></blockquote><dl> <dt><a name="Marking locations in a program"><strong>Marking locations in a program</strong></a></dt> <dd>The first line in the example-program (<font face="Courier New"><strong>label loop</strong></font>) is a label: As yabasic has no line-numbers, you need labels to mark a specific location within your program. You can compose labels out of letters and digits; the keyword <font face="Courier New"><strong>label</strong></font> is required and the label itself should be unique within your program. Note that yabasic allows for <a href="#linenumber">line numbers</a> too.</dd> <dt><a name="Jumping around in your program"><strong>Jumping around in your program</strong></a></dt> <dd>A label by itself causes no special action. Only in conjunction with the <font face="Courier New"><strong>goto</strong></font>-statement (or <font face="Courier New"><strong>gosub</strong></font> or <font face="Courier New"><strong>restore</strong></font>) does a label have any function. If yabasic encounters a <font face="Courier New"><strong>goto</strong></font>-statement (here: <font face="Courier New"><strong>goto loop</strong></font>) then it searches for the matching label (here: <font face="Courier New"><strong>label loop</strong></font>) and proceeds to execute at the position of the label.<br> Note that you can even leave (and enter !) a for-next loop with goto.<br> <br> Closely related to the <font face="Courier New"><strong>goto</strong></font>-command is the <font face="Courier New"><strong>gosub</strong></font>-command; if yabasic encounters a <font face="Courier New"><strong>gosub</strong></font>-statement then it searches for the matching label (<font face="Courier New"><strong>label thanx</strong></font> in the example) and proceeds with execution at the position of the label, until it finds a <font face="Courier New"><strong>return</strong></font>-statement. <font face="Courier New"><strong>return</strong></font> makes yabasic return to the position of the original gosub and proceed from there.<br> <br> Note that both <font face="Courier New"><strong>goto</strong></font> and <font face="Courier New"><strong>gosub</strong></font> can be used as <a href="#on gosub"><font face="Courier New"><strong>on goto</strong></font></a> and <a href="#on gosub"><font face="Courier New"><strong>on gosub</strong></font></a>.</dd> <dt><a name="Finding strings in strings"><strong>Finding strings in strings</strong></a></dt> <dd>The example program above checks whether the user input contains the string <font face="Courier New"><strong>"yabasic"</strong></font>; this is done with the help of the <font face="Courier New"><strong>instr()</strong></font>-function; <font face="Courier New"><strong>instr()</strong></font> gives back the position of its second string-argument within the first or zero, if it can't be found. E.g. <font face="Courier New"><strong>instr("Hallo","al")</strong></font> gives back 2, because <font face="Courier New"><strong>"al"</strong></font> appears at position 2 within <font face="Courier New"><strong>"Hallo"</strong></font>; whereas <font face="Courier New"><strong>instr("Hallo","Al")</strong></font> returns 0, because <font face="Courier New"><strong>"Al"</strong></font> is not contained in <font face="Courier New"><strong>"Hallo"</strong></font> (the case doesn't match).</dd> <dt><a name="Changing the case of strings"><strong>Changing the case of strings</strong></a></dt> <dd>The sample-program contains some further string-functions: <font face="Courier New"><strong>lower$()</strong></font> and its counterpart <font face="Courier New"><strong>upper$()</strong></font> convert their string-argument to all lower or all upper case characters respectively, i.e. <font face="Courier New"><strong>lower$("aBcD12fG")</strong></font> gives back <font face="Courier New"><strong>"abcd12fg"</strong></font>.</dd> <dt><a name="Removing spaces"><strong>Removing spaces</strong></a></dt> <dd><font face="Courier New"><strong>ltrim$()</strong></font> and <font face="Courier New"><strong>rtrim$()</strong></font> are two functions to remove leading or trailing spaces from a string, e.g. <font face="Courier New"><strong>ltrim$(" foo ") </strong></font>gives<font face="Courier New"><strong> "foo " </strong></font>and<font face="Courier New"><strong> rtrim$(" foo ") </strong></font>gives<font face="Courier New"><strong> " foo"</strong></font>. Finally<font face="Courier New"><strong>, trim$() </strong></font>is the same as<font face="Courier New"><strong> rtrim$(ltrime$())</strong></font>.</dd> <dt><a name="Splitting astring into tokens"><strong>Splitting a string into tokens</strong></a></dt> <dd>There is a handy function to split a string into tokens; an example would be:</dd> <dt> </dt> <dd><blockquote> <p><font size="3" face="Courier New"><strong>l$=" one two three "<br> label loop:print token$(a$):if (a$<>"") then goto loop:fi</strong></font></p> </blockquote> <p>Running this program gives:</p> </dd></dl><blockquote> <blockquote> <p><font size="3" face="Courier New"><strong>one<br> two<br> three</strong></font></p> </blockquote> <p>Note, that <font face="Courier New"><strong>token$()</strong></font> automatically removes the tokens from <font face="Courier New"><strong>a$</strong></font>. If you supply a second argument (e.g. <font face="Courier New"><strong>token$(a$,":")</strong></font>), the tokens are split at the characters given in the second string.</p></blockquote><p><a href="#Table of contents">Back to table of contents ...</a></p><hr><h2><a name="Graphics and printing">Graphics and printing</a></h2><p>Yabasic provides some simple, general purposegraphic-commands:</p><blockquote> <pre><strong>open window 400,400line 0,0 to 400,400circle 200,200,150dot 200,200a$=inkey$clear windowtext 100,200,"Hello !"print "Press any key to close the window"inkey$close window</strong></pre></blockquote><dl> <dt><strong>Drawing</strong></dt> <dd>If you run this program, you will see a window with size of 400 pixels in x- and y-direction (the window size is given along with the <font face="Courier New"><strong>open window</strong></font>-statement). To specify a certain font for the text within this window, you may add a third argument, e.g. <font face="Courier New"><strong>open window 400,400,"swiss"</strong></font>.</dd> <dd><br> Not surprising: The <font face="Courier New"><strong>line</strong></font>-command draws a line, the <font face="Courier New"><strong>circle</strong></font>-command draws a circle (the arguments determine x- and y-position of the center and the radius of the circle) and the <font face="Courier New"><strong>dot</strong></font>-command draws a single dot at the specified location.<br> <br> After the user has pressed a key (see <a href="#Getting a key from the keyboard">below</a>) the window contents is cleared with the <font
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -