Skip to content

Update of all commands starting with D #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Jan 29, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions _build/pages/escape.markdown
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ SmallBASIC supports a number of escape codes for controlling the display. The co

## Using the escape codes directly

The instead of "\e" the CHR command is useful for obtaining and printing the escape character (ASCII 27)
The instead of `\e` the CHR command is useful for obtaining and printing the escape character (ASCII 27)

```Freebasic
PRINT CHR(27) + "[1mTHIS IS BOLD" + CHR(27) + "[0m"
@@ -43,7 +43,7 @@ PRINT "First line\nSecond Line"

## Using the EscapeCode Unit

The EscapeCode Unit makes it easier to use the escape codes and to deal with the different colors for foreground and background. The uint can be downloaded or copy pasted from the [SmallBASIC Github website](https://github.com/smallbasic/smallbasic.plugins/blob/master/units/EscapeCodes.bas). Please save the unit in the same directory as you basic file.
The EscapeCode Unit makes it easier to use escape codes and to deal with different colors for foreground and background. The unit can be downloaded or copy pasted from the [SmallBASIC Github website](https://github.com/smallbasic/smallbasic.plugins/blob/master/units/EscapeCodes.bas). Please save the unit in the same directory as you basic file.

Here an example on how to use the unit.

@@ -90,6 +90,6 @@ print esc.BP + "A BEEP SHOULD BE AUDIBLE"

## Escape codes in SmallBASIC console version

In the console version of SmallBASIC (sbasic.exe or sbasic) most of the escape codes, for example [ANSI Codes at wikipedia](http://en.wikipedia.org/wiki/ANSI_escape_code), can be used in version 12.25 or later. The support of the escape codes depends on the operating system and the terminal you are using.
In the console version of SmallBASIC (sbasic.exe or sbasic) most of the escape codes, for example [ANSI Codes at wikipedia](http://en.wikipedia.org/wiki/ANSI_escape_code), can be used in version 12.25 or later. Support of escape codes depends on the operating system and the terminal you are using.


7 changes: 0 additions & 7 deletions _build/reference.json
Original file line number Diff line number Diff line change
@@ -1692,13 +1692,6 @@
"signature": "STATMEAN (...)",
"type": "function"
},
{
"help": "Standard deviation.",
"keyword": "STATSTD",
"nodeID": "1800",
"signature": "STATSTD (...)",
"type": "function"
},
{
"help": "Mean absolute deviation around arithmetic mean.",
"keyword": "STATMEANDEV",
61 changes: 52 additions & 9 deletions _build/reference/1015-console-definekey.markdown
Original file line number Diff line number Diff line change
@@ -2,25 +2,68 @@

> DEFINEKEY k, sub

Binds a keystroke to a user defined function,
Binds a keystroke to a user defined function. To unbind the keystroke definition pass 0 as the `sub` argument.

Keycodes for PC keyboard

| Key | Keycode |
|------------------|------------------------------------------------|
| A to Z | asc("a") to asc("z") |
| 0 to 9 | asc("0") to asc("9") |
| Backspace | 8 |
| Delete | 127 |
| Break | 3 |
| Tab | 9 |
| Enter / Return | 13 |
| Space | 32 |
| Escape | 27 |
| Page Up / Prior | 0xFF01 |
| Page Down / Next | 0xFF02 |
| Left | 0xFF04 |
| Right | 0xFF05 |
| Up | 0xFF09 |
| Down | 0xFF0A |
| Insert | 0xFF10 |
| Home | 0xFF11 |
| End | 0xFF12 |
| Menu | 0xFF1F |
| F1 to F15 | 0xFFF0+1 to 0xFFF0+15 |
| Ctrl + A to Z | 0x71000000 + asc("a") to 0x71000000 + asc("z") |
| Alt + A to Z | 0x72000000 + asc("a") to 0x72000000 + asc("z") |
| Shift + A to Z | asc("A") to asc("Z") |


## Examples

Example 1: Bind keystroke for left and right arrow key

~~~
sub moveLeft
if (block.x > 0) then
moveBlock -1, 0
fi
defineKey 0xFF04, Increase 'Left arrow
defineKey 0xFF05, Decrease 'Right arrow

sub Increase
x = x + 1
end

sub Decrease
x = x - 1
end
defineKey 0xFF04, moveLeft

while(1)
t = ticks()
at 0,0: print t + ": " + x + " "
delay(50)
wend
~~~

To unbind the keystroke definition pass 0 as the `sub` argument, for example:

Example 2: Unbind a keystroke

```
DEFINEKEY 0xFF04, 0
```

## Example 1:
Example 3: Etch-a-Sketch

~~~
' DEFINEKEY demo.bas SmallBASIC 0.12.2 [B+=MGA] 2016-03-30
@@ -88,7 +131,7 @@ sub quit
end
~~~

## Example 2:
Example 4: This example is outdated and just a reference for buttons in PALM OS

~~~
' Note:
2 changes: 1 addition & 1 deletion _build/reference/1801-math-statmedian.markdown
Original file line number Diff line number Diff line change
@@ -8,5 +8,5 @@ see: [Wikipedia - Median](https://en.wikipedia.org/wiki/Median)

```
a = [1, 3, 3, 6, 7, 8, 9]
print statmedian(6)
print statmedian(a) ' output: 6
```
17 changes: 16 additions & 1 deletion _build/reference/542-data-delete.markdown
Original file line number Diff line number Diff line change
@@ -4,9 +4,24 @@

Deletes 'count' elements at position 'idx' of array 'a'.


* a - An array-variable.
* idx - Position in the array.
* count - The number of the elements to be deleted.

Example 1: Delete element at position 2

```
a = [1,2,3,4,5]
print a
delete a, 2
print a
```

Example 2: Delete two elements starting at position 2

```
b = [1,2,3,4,5]
print b
delete b, 2, 2
print b
```
19 changes: 17 additions & 2 deletions _build/reference/546-data-read.markdown
Original file line number Diff line number Diff line change
@@ -8,12 +8,27 @@ var - Any variable.

Unless a RESTORE command is executed, SmallBASIC moves to the next DATA item with each READ assignment. If SmallBASIC runs out of DATA items to READ, an run-time error occurs.

See DATA and RESTORE for more information.

```
FOR c=1 TO 6
FOR c = 1 TO 6
READ x
PRINT x
NEXT
...

DATA "a,b,c", 2
DATA 3, 4
DATA "fifth", 6
```

Example 2: READ with two variables

```
FOR c = 1 TO 3
READ x, y
PRINT x, y
NEXT

DATA "a,b,c", 2
DATA 3, 4
DATA "fifth", 6
47 changes: 42 additions & 5 deletions _build/reference/569-data-data.markdown
Original file line number Diff line number Diff line change
@@ -4,17 +4,54 @@

Stores one or more constants, of any type, for subsequent access via READ command.

DATA commands are non executable statements that supply a stream of data constants for use by READ commands. All the items supplied by all the DATA commands in a program make up one continuous "string" of information that is accessed in order by your program's READ commands.
DATA commands are non executable statements that supply a stream of data constants
for use by READ commands. All the items supplied by all the DATA commands in a
program make up one continuous "string" of information that is accessed in order
by your program's READ commands. Use RESTORE ro specify which data block should be
read next.


Example 1:

```
RESTORE MyDataBlock
FOR I=1 TO 3
FOR I = 1 TO 3
READ v
PRINT v
NEXT
END
...
LABEL MyDataBlock

DATA 1,2,3
```

Example 2: Using several data commands.

```
FOR I = 1 TO 6
READ v
PRINT v
NEXT
END

DATA 1,2
DATA 3,4,5
DATA 6
```


Example 3: Specify which data block should be read.

```
RESTORE MyDataBlock

FOR I = 1 TO 3
READ v
PRINT v
NEXT
END

DATA 1,2,3
LABEL MyDataBlock
DATA 4,5,6

' Output: 4 5 6
```
49 changes: 36 additions & 13 deletions _build/reference/570-data-dim.markdown
Original file line number Diff line number Diff line change
@@ -6,22 +6,48 @@ Reserves storage space for an array.

The array will have (upper-lower)+1 elements. If `lower` is not specified, and `OPTION BASE` hasn't used, elements start at 0.

## Example 1: One dimensional arrays

```
REM One dimension array of 7 elements, starting from 0
REM One dimensional array of 7 elements, starting from 0
REM with elements A(0), A(1), ... , A(6)
DIM A(6)
...
REM One dimension array of 6 elements, starting from 1
DIM A(1 TO 6)
...
REM Three dimension array
DIM A(1 TO 6, 1 TO 4, 1 TO 8)
...
```

```
REM One dimensional array of 7 elements, starting from 3
REM with elements A(3), A(4), ... , A(9)
DIM A(3 TO 9)
```

```
REM One dimensional array of 6 elements, starting from 1
REM with elements A(1), A(2), ... , A(6)
option base 1
DIM A(6)
```

## Example 2: Multi dimensional arrays

```
REM Two dimensional array
DIM A(3, 4)
```

```
REM Three dimensional array
DIM A(2 TO 6, 5 TO 9, 1 TO 8)
```

## Example 3: Empty array

```
REM Allocating zero-length arrays:
DIM z()
...
IF LEN(Z)=0 THE APPEND Z, "The first element"
```

## Example 4: Creating and accessing arrays

~~~

Option Base 1 ' Set default lower bound of arrays to 1
@@ -78,9 +104,6 @@ For i = 1 To 10
a(i).z = i + 100
Next
? a(5).x, a(5).y, a(5).z,, "(map array)"

Pause

~~~


17 changes: 17 additions & 0 deletions _build/reference/572-data-restore.markdown
Original file line number Diff line number Diff line change
@@ -4,4 +4,21 @@

Specifies the position of the next data to be read.

See DATA for more information.


```
RESTORE MyDataBlock

FOR I = 1 TO 3
READ v
PRINT v
NEXT
END

DATA 1,2,3
LABEL MyDataBlock
DATA 4,5,6

' Output: 4 5 6
```
6 changes: 6 additions & 0 deletions _build/reference/573-date-datedmy.markdown
Original file line number Diff line number Diff line change
@@ -4,4 +4,10 @@

Returns the day, month and the year as integers.

See also DATE.

~~~
DateString = date
datedmy DateString, d, m, y
print DateString + " -> Day: " + d + " Month: " + m + " Year: " + y
~~~
6 changes: 6 additions & 0 deletions _build/reference/575-date-date.markdown
Original file line number Diff line number Diff line change
@@ -4,4 +4,10 @@

Returns the current date as string "DD/MM/YYYY".

See DATEDMY for splitting a date to integers.

~~~
DateString = date
datedmy DateString, d, m, y
print DateString + " -> Day: " + d + " Month: " + m + " Year: " + y
~~~
26 changes: 13 additions & 13 deletions _build/reference/576-date-datefmt.markdown
Original file line number Diff line number Diff line change
@@ -4,20 +4,20 @@

Returns formatted date string.

Format:
| Format | Desription |
|--------| -------------------------|
|D | one or two digits of Day |
|DD | 2-digit day |
|DDD | 3-char day name |
|DDDD | full day name |
|M | 1 or 2 digits of month |
|MM | 2-digit month |
|MMM | 3-char month name |
|MMMM | full month name |
|YY | 2-digit year (2K) |
|YYYY | 4-digit year |

---- ---------------------------
D one or two digits of Day
DD 2-digit day
DDD 3-char day name
DDDD full day name
M 1 or 2 digits of month
MM 2-digit month
MMM 3-char month name
MMMM full month name
YY 2-digit year (2K)
YYYY 4-digit year
---- --------------------------
See also DATE and DATEDMY.

```
PRINT DATEFMT("ddd dd, mm/yy", "23/11/2001")
Loading