Skip to content

Update of function reference K to L #20

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 32 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
29ccdd4
Update escape.markdown
Joe7M Apr 27, 2023
57104cb
Update 591-file-kill.markdown
Joe7M Apr 27, 2023
ca0cabb
Update 684-language-label.markdown
Joe7M Apr 27, 2023
bd545b4
Update 561-data-lbound.markdown
Joe7M Apr 27, 2023
da24ca2
Update 782-string-lcase.markdown
Joe7M Apr 27, 2023
8609c32
Update 783-string-left.markdown
Joe7M Apr 27, 2023
e4cd880
Update 784-string-leftof.markdown
Joe7M Apr 27, 2023
e492475
Update 785-string-leftoflast.markdown
Joe7M Apr 27, 2023
40371f6
Update 562-data-len.markdown
Joe7M Apr 27, 2023
304a714
Update 685-language-let.markdown
Joe7M Apr 27, 2023
0df285b
Update 668-language-like.markdown
Joe7M Apr 27, 2023
5703dc2
Update 736-math-lineqn.markdown
Joe7M May 15, 2023
beb1607
Update 736-math-lineqn.markdown
Joe7M May 15, 2023
3ef880e
Update 544-data-insert.markdown
Joe7M May 19, 2023
f536196
Merge branch 'smallbasic:master' into master
Joe7M May 29, 2023
0081a72
Update escape.markdown
Joe7M May 29, 2023
167e11d
Update 1521-system-command.markdown
Joe7M May 30, 2023
0483568
Update 618-graphics-line.markdown
Joe7M May 30, 2023
60fc435
Update 528-console-lineinput.markdown
Joe7M May 30, 2023
8c0acdb
Update 529-console-linput.markdown
Joe7M May 30, 2023
24e84e8
Update 653-language-local.markdown
Joe7M May 30, 2023
0545b7f
Update 653-language-local.markdown
Joe7M May 30, 2023
057850a
Update 530-console-locate.markdown
Joe7M May 30, 2023
a5d16c2
Update 609-file-lof.markdown
Joe7M May 30, 2023
99b20f9
Update 594-file-open.markdown
Joe7M May 30, 2023
ce4926e
Update 737-math-log.markdown
Joe7M May 30, 2023
00eb5bf
Update 738-math-log10.markdown
Joe7M May 30, 2023
33862a9
Update 737-math-log.markdown
Joe7M May 30, 2023
6cd2f9e
Update 531-console-logprint.markdown
Joe7M May 30, 2023
420d92f
Update 786-string-lower.markdown
Joe7M May 30, 2023
acb2d0a
Update 1496-language-lshift.markdown
Joe7M May 30, 2023
8f2cc53
Update 787-string-ltrim.markdown
Joe7M May 30, 2023
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
10 changes: 5 additions & 5 deletions _build/pages/escape.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

SmallBASIC supports a number of escape codes for controlling the display. The codes allow you to set foreground and background colors, change the font and also set underline and inverse text display. The escape codes are based on [ANSI Codes](http://en.wikipedia.org/wiki/ANSI_escape_code).

## The supported standard codes are:
## Supported standard codes

```
\a beep
Expand All @@ -27,9 +27,9 @@ SmallBASIC supports a number of escape codes for controlling the display. The co
\e[nm n colors - 30..37 foreground, 40..47 background
```

## Using the escape codes directly
## Using escape codes directly

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

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

## Using the EscapeCode Unit

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.
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 your basic file.

Here an example on how to use the unit.
Here an example on how to use the unit:

```Freebasic
' SmallBASIC 12.25
Expand Down
37 changes: 14 additions & 23 deletions _build/reference/1496-language-lshift.markdown
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
# LSHIFT

> result = LSHIFT number, amount
> result = x LSHIFT n

Performs an arithmetic left shift on a bit pattern.
Performs a bitwise operation that shifts all the bits of `x` to the left by an amount of `n`.

### Example 1:

```
print 1 lshift 2 ' Output 4
```

### Example 2:

~~~

' Tested on 32-bit system (I'm not sure yet about the result on 64-bit system):
x = 1 ' x = 1 (0b1)
? Bin(x)
?
x = x Lshift 1 ' Shift-Left x by 1
? Bin(x)
x = x Lshift 30 ' Shift-Left x again by 30
? Bin(x)
?
x = 1 Lshift 33 ' The same as: x = 1 Lshift (33 Mod 32)
? Bin(x)
?
x = 0b1111 Lshift 30 ' The two upper bits are lost (on 32-bit system)
? Bin(x)
? x ' x is -1073741824 (on 32-bit system)

~~~


```
x = 1
print bin(x) ' Output: 1
print bin(x lshift 1) ' Output: 10
print bin(x lshift 2) ' Output: 100
print bin(x lshift 3) ' Output: 1000
```
49 changes: 35 additions & 14 deletions _build/reference/1521-system-command.markdown
Original file line number Diff line number Diff line change
@@ -1,50 +1,71 @@
# COMMAND

> COMMAND
> s = COMMAND

SmallBASIC startup command line options.
Returns a string `s` containing the SmallBASIC startup command line options.


### SDL version (GUI):
### Example 1: SDL version (GUI)

Running the following line from the command line:

```
LINUX: sbasicg -r test.bas "abc xyz fileName"
WINDOWS: sbasicg.exe -r test.bas "abc xyz fileName"
LINUX: sbasicg -r test.bas abc xyz fileName
WINDOWS: sbasicg.exe -r test.bas abc xyz fileName
```

When "test.bas" is:

```
? COMMAND
PRINT COMMAND
```

Will print "abc xyz fileName"

Note: Run
Note: When using the paramter `-r` in the above shown example, sbasicg will from now on always start the programm. If you want, that sbasicg starts again in edit-mode, please use the parameter `-e`

```
LINUX: sbasicg -e test.bas
WINDOWS: sbasicg.exe -e test.bas
```

to enable 'Edit' mode again.

### Non-graphical console version (cygwin or linux):
### Example 2: Non-graphical console version (cygwin or linux)

Running the following line from the command line:

```
LINUX: sbasic test.bas "abc xyz fileName"
WINDOWS: sbasic.exe test.bas "abc xyz fileName"
LINUX: sbasic test.bas abc xyz fileName
WINDOWS: sbasic.exe test.bas abc xyz fileName
```

When "test.bas" is:

```
? COMMAND
PRINT COMMAND
```

Will print "abc xyz fileName"

### Example 3: Use SPLIT to separate parameters

```
LINUX: sbasicg -r test.bas abc xyz fileName
WINDOWS: sbasicg.exe -r test.bas abc xyz fileName
```

When "test.bas" is:

```
s = COMMAND()

split s, " ", parameters

print "First parameter : "; parameters[0]
print "Second parameter: "; parameters[1]
print "Third parameter : "; parameters[2]

' Output:
' First parameter : abc
' Second parameter: xyz
' Third parameter : fileName
```

33 changes: 31 additions & 2 deletions _build/reference/528-console-lineinput.markdown
Original file line number Diff line number Diff line change
@@ -1,7 +1,36 @@
# LINEINPUT

> LINEINPUT [#fileN] var
> LINEINPUT [#fileN,] var

Reads a whole text line from file or console.
Reads a whole text line from file or console and stores it in the string `var`. If a file handle `#fileN` is specified, LINEINPUT will read from the corresponding file otherwise it will read from the console.

### Example 1: Read from console

```
LINEINPUT S
PRINT S
```

### Example 2: Read from file

```
' create a file
open "File.txt" for output as #1

print #1, "First line"
print #1, "Second line"

close #1


' open file and print content
open "File.txt" for input as #1

LINEINPUT #1, S
Print S
LINEINPUT #1, S
Print S

close #1
```

34 changes: 32 additions & 2 deletions _build/reference/529-console-linput.markdown
Original file line number Diff line number Diff line change
@@ -1,7 +1,37 @@
# LINPUT

> LINPUT [#fileN] var
> LINPUT [#fileN,] var

Reads a whole text line from file or console.
Reads a whole text line from file or console and stores it in the string `var`. If a file handle `#fileN` is specified, LINPUT will read from the corresponding file otherwise it will read from the console. LINPUT has the same function as LINEINPUT.

### Example 1: Read from console

```
LINPUT S
PRINT S
```

### Example 2: Read from file

```
' create a file
open "File.txt" for output as #1

print #1, "First line"
print #1, "Second line"

close #1


' open file and print content
open "File.txt" for input as #1

LINPUT #1, S
Print S
LINPUT #1, S
Print S

close #1
```


126 changes: 75 additions & 51 deletions _build/reference/530-console-locate.markdown
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
# LOCATE

> LOCATE y, x
> LOCATE row, column

Moves the console cursor to the specified position. x,y are in character cells.
Moves the console (text-mode) cursor to the specified position. `row` and `column` are in text-mode character cells.

See AT for positioning the cursor in pixel.

~~~
### Example 1:

```
locate 5,7
print "text at row 5 and column 7"
```

### Example 2: Print text always in center of window

```
' Define functions to calculate lines and columns
Def lines() = (Ymax + 1) \ Txth("x") ' maximum lines in window
Def columns() = (Xmax + 1) \ Txtw("x") ' maximum columns in window

' Define functions to calculate position of text
Def center_line() = lines \ 2
Def center_column(text) = (columns \ 2) - (Len(text) \ 2)

' calculate y and x in characters cells:
Def lines = (Ymax + 1) \\ Txth("x") ' maximum lines in window
Def columns = (Xmax + 1) \\ Txtw("x") ' maximum columns in window
' center line,column for printing "text" (top,left is 0,0):
Def center_line = lines \\ 2
Def center_column(text) = (columns \\ 2) - (Len(text) \\ 2)
' attributes for printing text (ESCAPE codes):
Const ESC = Chr(27)
Const bold_on = ESC + "[1m" ' strong
Expand All @@ -21,62 +32,75 @@ Const line_on = ESC + "[4m" ' underline
Const line_off = ESC + "[24m"
Const reve_on = ESC + "[7m" ' reverse
Const reve_off = ESC + "[27m"

' colors for printing text:
Const WHITE = 7
Const BLACK = 0
Const YELLOW = 14
Const BLUE = 1

Const HELLO = "* Hello World! *" ' text to print.

' loop until user press Esc key:
While Inkey <> Chr(27)
' update screen if user resized the window:
If (x <> Xmax) Or (y <> Ymax) Then
Color WHITE, BLACK
Cls
Print Using "Please resize window (Esc=Stop) 000:0000"; lines, columns;
' Print hello world:
l = center_line
c = center_column(HELLO)
Color YELLOW, BLUE
Locate l - 1, c: Print bold_on + HELLO + bold_off;
Locate l , c: Print reve_on + HELLO + reve_off;
Locate l + 1, c: Print line_on + HELLO + line_off;
' remember current windows size:
x = Xmax
y = Ymax
Endif
' update screen if user resized the window:
If (x <> Xmax) Or (y <> Ymax) Then
Color WHITE, BLACK
Cls

Print Using "Please resize window (Esc=Stop) 000:0000"; lines(), columns();

' Print hello world:
l = center_line()
c = center_column(HELLO)

Color YELLOW, BLUE
Locate l - 1, c: Print bold_on + HELLO + bold_off;
Locate l , c: Print reve_on + HELLO + reve_off;
Locate l + 1, c: Print line_on + HELLO + line_off;

' remember current windows size:
x = Xmax
y = Ymax
Endif
Wend
```
### Example 3: Print ASCII table

~~~


~~~

```
' LOCATE MOD CHR ASC.bas SmallBASIC 0.12.2 [B+=MGA] 2016-03-23
' LOCATE row, column - sets the next print location on screen, rows down, columns across
' a MOD b - returns the remainder of a/b as integer 0 to b-1
' for example odd number n mod 2 returns 1, while even number n mod 2 returns 0
' n mod 10 returns 0,1,2,3,4,5,6,7,8 or 9 we will use this in demo
' CHR - returns the CHaRracter for the ASC number, for demo we will print a chart of CHR for ASC numbers 30-129
' ASC(Character) - is a number code for a print characters, 32 is the code for a space
' ? - is shortcut for PRINT
' RIGHT(string,n) - returns right most n characters of string
' STR(n) - returns a number in string form
' : - code statement seperator often used with LOCATE row, column : ? string
LOCATE 1,16 : ? "ASC Table 30-129:" 'locate print spot, print title for our chart
FOR column=0 to 9 'print a header, 10 numbers plus + (to add to row value)
LOCATE 2,column*5+4 : ? "+";column
'
' LOCATE row, column: sets the next print location on screen,
' rows down, columns across
' a MOD b : returns the remainder of a/b as integer 0 to b-1
' for example odd number n mod 2 returns 1, whil
' even number n mod 2 returns 0
' n mod 10 returns 0,1,2,3,4,5,6,7,8 or 9
' we will use this in demo
' CHR(number) : returns the CHaRracter for the ASC number,
' for demo we will print a chart of CHR for ASC
' numbers 30-129
' ASC(Character) : is a number code for a print characters, 32 is
' the code for a space
' ? : is shortcut for PRINT
' RIGHT(string,n) : returns right most n characters of string
' STR(n) : returns a number in string form
' : : code statement seperator often used with
' LOCATE row, column : ? string

LOCATE 1, 16 : ? "ASC Table 30-129:" ' locate print spot, print title for our chart
FOR column = 0 to 9 ' print a header, 10 numbers plus + (to add to row value)
LOCATE 2, column * 5 + 4 : ? "+";column
NEXT
FOR row=3 to 12
LOCATE row,0 : ? RIGHT(" "+STR(row*10)+":",4)
FOR row = 3 to 12
LOCATE row, 0 : ? RIGHT(" " + STR(row * 10) + ":", 4)
NEXT
FOR ASCnumber=30 to 129 'note ASC(32) = space so wont see anything in Table
row=ASCnumber\\10 ' \\ rounds division down to integer
column=(ASCnumber MOD 10)*5+5 'times 5 to space out the characters printed plus 5 for column labels
LOCATE row,column : ? CHR(ASCnumber) '<=========== handy reference
FOR ASCnumber = 30 to 129 ' note ASC(32) = space so wont see anything in Table
row = ASCnumber \ 10 ' \ rounds division down to integer
column = (ASCnumber MOD 10) * 5 + 5 ' times 5 to space out the characters printed plus 5 for column labels
LOCATE row, column : ? CHR(ASCnumber) '<=========== handy reference
NEXT
PAUSE
```

~~~


Loading