Skip to content

Commit

Permalink
Merge pull request #24 from Joe7M/master
Browse files Browse the repository at this point in the history
Update of function reference starting with T
  • Loading branch information
chrisws authored Sep 9, 2023
2 parents dddb9e9 + fac6aea commit 4219b15
Show file tree
Hide file tree
Showing 30 changed files with 443 additions and 255 deletions.
3 changes: 1 addition & 2 deletions _build/pages/articles.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
- [Android](/pages/android.html)
- [SDL](/pages/sdl.html)
- [FLTK](/pages/fltk.html)
- [Visual Studio Code, Atom and Geany](/pages/language_support.html)
- [Setup external editors](/pages/language_support.html)
- [Distribute your program](/pages/distributiontool.html)


## Plugins

- [Raylib: 2D and 3D game development](/pages/plugins_raylib.html)
Expand Down
1 change: 0 additions & 1 deletion _build/pages/community.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
## Forum

- [SyntaxBomb / SmallBASIC](https://www.syntaxbomb.com/smallbasic)
- [Basic4All](http://basic4all.epizy.com/index.php)

## Issues
- [GitHub](https://github.com/smallbasic/SmallBASIC/issues){target=new}
Expand Down
7 changes: 1 addition & 6 deletions _build/pages/links.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
## External articles

- [Wikipedia entry](http://en.wikipedia.org/wiki/SmallBASIC){target=_blank}
- [PalmPilot Software Development - Alternatives to C](http://goanna.cs.rmit.edu.au/~winikoff/palm/dev.html){target=_blank}
- [David A. Wheeler's Suggestions for PalmOS PDA Users](http://www.dwheeler.com/palm-suggest.html){target=_blank}
- [PalmOS-hosted programming languages](http://www.ibm.com/developerworks/linux/library/l-palmos2.html?dwzone=linux#h7879){target=_blank}
- [PC Advisor](http://www.pcadvisor.co.uk/how-to/software/3307979/how-program-software/){target=_blank}
- [Learn X in Y minutes](https://learnxinyminutes.com/docs/smallbasic/){target=_blank}

## External documentation
Expand All @@ -20,9 +17,7 @@

## What about the other "SmallBASIC?"

We noticed there's another version of [SmallBASIC](http://smallbasic.com/faq.aspx){target=_blank}. Other than the naming coincidence, our version of SmallBASIC doesn't have anything to do with this other version.

- [Small Basic to SmallBASIC translator - experimental](http://sb-translator.appspot.com/){target=_blank}
We noticed there's another version of [SmallBASIC](https://smallbasic-publicwebsite.azurewebsites.net){target=_blank}. Other than the naming coincidence, our version of SmallBASIC doesn't have anything to do with this other version.

## ECMA-55

Expand Down
4 changes: 2 additions & 2 deletions _build/reference/1420-language-to.markdown
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# TO

> FOR t = 1 TO 10
> FOR t = var1 TO var2
Specifies the loop counter end in a FOR loop
Specifies the loop counter end in a FOR loop. For more information see FOR.

### Example

Expand Down
53 changes: 36 additions & 17 deletions _build/reference/1425-language-try.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

> TRY
The TRY statement introduces a TRY/CATCH block. A try/catch block consist of the following structure:

__TRY__

The TRY statement introduces a TRY/CATCH block.
The TRY statement starts a block of commands which might create a run-time error.

__CATCH [var | expr]__

The CATCH statement is used to CATCH an run-time error. This is typically used with errors raised when calling a file system command that cannot be completed, for example attempting to open a non-existent file.

The CATCH statement has two modes. You can supply a variable argument to store the error string. Alternatively you can supply an expression. When the raised error matches the (String) expression, the error will be caught.
The CATCH statement is used to catch a run-time error of one of the commands in the try-block. This is typically used with errors raised when calling a file system command that cannot be completed, for example attempting to open a non-existent file.

When using the expression mode, you can supply a succession of CATCH statements to handle various error messages separately.
The CATCH statement has two modes. You can supply a variable argument to store the error string. Alternatively you can supply an expression. When the raised error matches the (String) expression, the error will be caught. When using the expression mode, you can supply a succession of CATCH statements to handle various error messages separately.

__END TRY__

Expand All @@ -26,18 +26,45 @@ try
' DON'T use existing file for demo.
open "try demo.tmp" for input as #1
catch err
print err; " "
print err
' Some error handling could be implemented here
' i.e: if(err = "...") then ...
end try
print "This point is reach, even if opening the file was not possible"
```

### Example 2: Advanced error handling for opening files
### Example 2: Open COM-Port

```
try
open "com2000:" AS #1
catch err
print "open failed: ";err
end try
```
### Example 3: Using error expressions

```
try
' DON'T use existing file for demo.
open "demo.tmp" for input as #1 ' Replace "demo.tmp" by "?.tmp"
catch "FS(2): NO SUCH FILE OR DIRECTORY"
print "File not found"
' Some error handling could be implemented here
goto aftertrycatch
catch "FS(22): INVALID ARGUMENT"
print "Filename not allowed"
' Some error handling could be implemented here
end try
label aftertrycatch
print "end of program"
```

~~~
### Example 4: Advanced error handling for opening files

```
' See also: Home -- Articles -- TRY / CATCH
Const FILE_NAME = "try demo.tmp" ' -- DON'T use existing file for demo.
' OPEN file or device safely:
Expand Down Expand Up @@ -99,14 +126,6 @@ If fn Then
? lines;
Close #fn
Fi
~~~
```

### Example 3: Open COM-Port

```
try
open "com2000:" AS #1
catch err
? "in catch: open failed";err
end try
```
20 changes: 17 additions & 3 deletions _build/reference/1426-language-catch.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,23 @@

> CATCH [var | expr]
The CATCH statement is used to CATCH a run-time error. This is typically used with errors raised when calling a file system command that cannot be completed, for example attempting to open a non-existent file.
The CATCH statement is used to catch a run-time error. This is typically used with errors raised when calling a file system command that cannot be completed, for example attempting to open a non-existent file.

The CATCH statement has two modes. You can supply a variable argument to store the error string. Alternatively you can supply an expression. When the raised error matches the (String) expression, the error will be caught. When using the expression mode, you can supply a succession of CATCH statements to handle various error messages separately.
The CATCH statement has two modes. You can supply a variable argument to store the error string. Alternatively you can supply an expression. When the raised error matches the (String) expression, the error will be caught. When using the expression mode, you can supply a succession of CATCH statements to handle various error messages separately.

For more information and examples please see TRY.
For more information see TRY.

### Example

```
try
' DON'T use existing file for demo.
open "try demo.tmp" for input as #1
catch err
print err
' Some error handling could be implemented here
' i.e: if(err = "...") then ...
end try
print "This point is reach, even if opening the file was not possible"
```
15 changes: 14 additions & 1 deletion _build/reference/1427-language-endtry.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

> END TRY
The END TRY statement marks the end of a TRY/CATCH block. For more information and examples please see TRY.
The END TRY statement marks the end of a TRY/CATCH block. For more information see TRY.

### Example

```
try
' DON'T use existing file for demo.
open "try demo.tmp" for input as #1
catch err
print err
' Some error handling could be implemented here
' i.e: if(err = "...") then ...
end try
print "This point is reach, even if opening the file was not possible"
```
41 changes: 9 additions & 32 deletions _build/reference/1437-language-throw.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,22 @@

> THROW [info [, ...]]
The THROW command (previously known as RTE) is used to initiate a catch-able error. If there is no surrounding TRY/CATCH block, THROW can be used to abort the program.
The THROW command is used to initiate a catch-able error. If there is no surrounding TRY/CATCH block, THROW can be used to abort the program. Optional a string `info` can be used to create an error message.

*Summary*
TRY/CATCH is used to trap errors allowing a program to recover without having to be restarted.
### Example 1: Abort a program

```
TRY
throw("Error")
```

The TRY statement introduces a TRY/CATCH BLOCK.
### Example 2: Initial a catch-able error

```
CATCH [var | expr]
```

The CATCH statement is used to CATCH an run-time error. This is typically used with errors raised when calling a file system command that cannot be completed, for example attempting to open a non-existent file.

The CATCH statement has two modes. You can supply a variable argument to store the error string. Alternatively you can supply an expression. When the raised error matches the (String) expression, the error will be caught.

When using the expression mode, you can supply a succession of CATCH statements to handle various error messages separately.
END TRY

The END TRY statement marks the end of a TRY/CATCH block.

```
THROW
```

The THROW command (previously known as RTE) is used to initiate a catch-able error. If there is no surrounding TRY/CATCH block, THROW can be used to abort the program.

Example

~~~
try
open "com2000:" AS #1
a = 1
if(a == 1) then throw("a == 1")
if(a == 2) then throw("a == 2")
catch err
? "in catch: open failed";err
print "Error: "; err
end try
~~~

```
12 changes: 10 additions & 2 deletions _build/reference/1443-system-exec.markdown
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# EXEC

> EXEC file
> EXEC (file)
Transfers control to another operating system program. Control returns to the .bas immediately and the system command is executed parallel and independent to SmallBASIC. File name is case sensitive in Linux.
Transfers control to the program `file`. Control returns to the calling bas-file immediately and the program is executed parallel and independent to SmallBASIC. File name is case sensitive in Linux. Enclose the string `file` with quotation marks to start a program with parameters.

See `run` for starting an external program and wait until program finished execution.

### Example 1

```
' Select your editor for testing
exec "kate" ' Editor KDE
Expand All @@ -15,3 +17,9 @@ exec "kate" ' Editor KDE
print "This line will be printed immediately without delay"
```

### Example 2: Execute with parameters

```
' Call shutdown in Linux
exec(enclose("shutdown -h now"))
```
6 changes: 5 additions & 1 deletion _build/reference/1448-date-ticks.markdown
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
# TICKS

> TICKS
> n = TICKS
Returns the number of milliseconds that have elapsed since start of the operating system.

### Example 1:

```
t = ticks()
print t
```

### Example 2: Game with constant frame rate

```
' ticks() can be used to let your game
' run with a constant frame rate
Expand Down
7 changes: 6 additions & 1 deletion _build/reference/1449-date-timer.markdown
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# TIMER

> TIMER
> n = TIMER
Returns the number of seconds from midnight.

### Example

```
print timer() ' Output 41595
```

16 changes: 14 additions & 2 deletions _build/reference/1450-date-timestamp.markdown
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
# TIMESTAMP

> TIMESTAMP filename
> s = TIMESTAMP (filename)
Returns the file last modified date and time.
Returns the file `filename` last modified date and time as a string. The returned string `s` has the format "YYYY-MM-DD hh:mm AM|PM".

### Example

```
' Create a file
open "timetest.txt" for output as #1
print #1, 1
close #1
' Get time stamp
print timestamp("timetest.txt") ' Output: 2023-09-03 11:36 AM
```


33 changes: 32 additions & 1 deletion _build/reference/1455-language-true.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,38 @@

> TRUE
TRUE
Boolean TRUE.

### Example 1: Assign TRUE to a variable

```
a = true
b = false
print a ' Output: 1
print b ' Output: 0
```

### Example 2: Use in a while loop

```
IsRunning = true
while(IsRunning)
i++
print i
if(i == 5) then IsRunning = false
wend
' Output: 1 2 3 4 5
```

### Example 3: Use in a if statement

```
ButtonPressed = true ' replace true with false
if(ButtonPressed) then print "Button was pressed"
```



Expand Down
18 changes: 9 additions & 9 deletions _build/reference/540-console-tab.markdown
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# TAB

> TAB (n)
> s = TAB (n)
Moves cursor position to the nth column.
Moves cursor position to the `n`th column. the return value `s` contains the escape sequence for moving the cursor.

### Example

~~~
print tab(50); "Oh! TAB works with PRINT and moves x pixels not x character cells."
pause
~~~

```
print tab(1); "1 tab"
print tab(2); "2 tabs"
s = tab(3)
print s; "3 tabs"
```
Loading

0 comments on commit 4219b15

Please sign in to comment.