Skip to content

Update of all commands starting with e #17

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 19 commits into from
Feb 27, 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
4 changes: 1 addition & 3 deletions _build/reference/1427-language-endtry.markdown
Original file line number Diff line number Diff line change
@@ -2,8 +2,6 @@

> END TRY

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


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


22 changes: 22 additions & 0 deletions _build/reference/1440-system-export.markdown
Original file line number Diff line number Diff line change
@@ -4,4 +4,26 @@

Export a SUB, FUNC or variable from a UNIT to be used by the unit consumer.

See `UNIT` for more information.


### Example: Create an unit

```
UNIT MyTestUnit

export const my_pi = 3.145
export my_two_pi = 6.29
export MyFunc
export MySub

func MyFunc(a)
return a + 10
end

sub MySub(a)
print a + 10
end
```


69 changes: 9 additions & 60 deletions _build/reference/1443-system-exec.markdown
Original file line number Diff line number Diff line change
@@ -2,67 +2,16 @@

> EXEC file

Transfers control to another operating system program.
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.

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

Const IS_LINUX = (Left(HOME, 1) = "/") ' Check if it's Linux system
Const IS_WINDOWS = Not IS_LINUX
Const FILE_NAME = "demo.bas" ' demo file name

' Print header before each mission:
Sub header(text)
? Cbs("\\n\\n" + Cat(0) + Cat(3) + Enclose(text, " ") + Cat(0) + Chr(7))
Pause
End Sub

' Create demo SmallBASIC file:
code << "Color 15, 1: ? " + Enclose("Hello World") + ": Pause" ' append line
Tsave FILE_NAME, code

' CHAIN(source)
'
' Compile and run the given source. Source can be a file name, a line of code
' or an array of code. Use ENV to share variables with the parent process.
header "Press a key to Chain another SB program and return afterwards..."
Chain FILE_NAME ' Chain only executes another SmallBASIC code.

' RUN(command) ' invoked as a COMMAND
' x = RUN(command) ' invoked as a FUNC, returning the results of the sub process
'
' With both of these, control returns to the .bas once system 'command'
' has completed.
header "Press a key to Run another program and return afterwards..."
Select Case 1
Case IS_LINUX: Run "gedit " + FILE_NAME
Case IS_WINDOWS: Run "Notepad " + FILE_NAME
End Select
? "OK."

' EXEC(command)
'
' Invoked as a COMMAND, control returns to the .bas immediately and the
' system command does it's own thing external to SmallBASIC:
header "Press a key to Execute another program in the background..."
Select Case 1
Case IS_LINUX: Exec "gedit"
Case IS_WINDOWS: Exec "Notepad"
End Select
? "Done.";
Pause

~~~

Apparently, RUN/EXEC have bugs in SmallBASIC version 0.12.2...:

RUN/EXEC

There are three modes:
1. RUN(command) ' invoked as a COMMAND
2. v=RUN(command) 'invoked as a FUNC, returning the results of the sub process
With both of these, control returns to the .bas once system 'command' has completed.
3. EXEC(command) 'invoked as a COMMAND, control returns to the .bas immediately and the system command does it's own thing external to SmallBASIC.

Note: In the android version you can use v=RUN to look at interesting things in the /proc file system.
```
' Select your editor for testing
exec "kate" ' Editor KDE
'exec "gedit" ' Editor Gnome
'exec "Notepad" ' Editor Windows

print "This line will be printed immediately without delay"
```

19 changes: 15 additions & 4 deletions _build/reference/543-data-empty.markdown
Original file line number Diff line number Diff line change
@@ -2,11 +2,22 @@

> EMPTY (x)

Returns true if x is: a zero length array, an empty string, an integer or real with the value 0.
Returns true if x is
* a zero length array
* an empty string
* a number with the value 0.

### Example

* If x is a string, returns true if the len(x) is 0.
* If x is an integer or a real returns true if the x = 0.
* If x is an array, returns true if x is a zero-length array (array without elements).
```
s = ""
a = []
dim b
i = 0

if(empty(s)) then print "s is empty"
if(empty(a)) then print "a is empty"
if(empty(b)) then print "b is empty"
if(empty(i)) then print "i is empty"
```

12 changes: 8 additions & 4 deletions _build/reference/571-data-erase.markdown
Original file line number Diff line number Diff line change
@@ -4,12 +4,16 @@

Deallocates the memory used by the specified arrays or variables. After that these variables turned to simple integers with zero value.

### Example

```
DIM x(100)
...
PRINT FRE(0)

x(1) = 1
x(2) = 2

ERASE x
PRINT FRE(0)
PRINT x(1):REM ERROR

PRINT x(1) ' This will create an error
```

49 changes: 49 additions & 0 deletions _build/reference/603-file-eof.markdown
Original file line number Diff line number Diff line change
@@ -4,4 +4,53 @@

Returns true if the file pointer is at end of the file. For COMx and SOCL VFS returns true if the connection is broken.

### Example 1: Reading data from a file

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

for i = 1 to 10
print #1, i
next

close #1

' open text file and print content line by line
open "MyDemoFile.txt" for input as #1

while(!eof(1)) ' eof works only without #
input #1, c
print c
wend

close #1
```

### Example 2: Reading from a TCP/IP socket

```
rem Print a date string like '29 SEP 2018 09:31:49 ACST'
func get_time
local today = julian(date)
local start = timer
local t_hour, t_min, t_sec, t_str
timehms start, t_hour, t_min, t_sec
rem TODO, format should support multiple arguments
t_str = format(" ##:", t_hour) + format("##:", t_min) + format("##", t_sec)
return datefmt("dd mmm yyyy", today) + t_str
end

while 1
open "SOCL:8080" as #1
while (not eof(1))
lineinput #1, s
if (s == "time")
print #1, get_time
else
print #1, "unknown command"
endif
wend
close #1
wend
```
31 changes: 8 additions & 23 deletions _build/reference/604-file-exist.markdown
Original file line number Diff line number Diff line change
@@ -5,28 +5,13 @@
Returns true if file exists.


~~~

' Return nonexisting file or directory name (12 A..Z letters + extension)
' in the current directory; e.g. filename = tempfile("-me.tmp")
Func tempfile(ext)
Local i, f = Space(12) + ext
Repeat
For i = 1 To 12
f = Replace(f, i, Chr(floor((Rnd * 25.5) + 65)))
Next
Until Not Exist(f)
tempfile = f
End Func
' demo:
filename = tempfile(".bak")
a << "This is a backup file: " + filename ' append one line
Tsave filename, a
Tload filename, b
? b
Pause
Kill filename ' delete demo file

~~~
### Example

```
if(exist("test.bas")) then
print "test.bas exists"
endif
```



26 changes: 25 additions & 1 deletion _build/reference/643-language-elif.markdown
Original file line number Diff line number Diff line change
@@ -2,6 +2,30 @@

> ELIF

foo = 2: if foo==1: ? "one": ELIF foo==2: ? "two": fi
Short for ELSEIF.

### Example 1

~~~
foo = 2
if foo == 1
print "one"
ELIF foo == 2
print "two"
fi
~~~

### Example 2: using IF ... ELSE ... IF instead of ELIF

~~~
foo = 2
if foo == 1
print "one"
else
if foo == 2
print "two"
fi
fi
~~~


12 changes: 11 additions & 1 deletion _build/reference/644-language-else.markdown
Original file line number Diff line number Diff line change
@@ -2,6 +2,16 @@

> ELSE

foo = 2: if foo==1: ? "one": ELSE: ? "not one": fi
Part of an if ... then ... else statement. For more information see `IF`.

### Example

```
foo = 2
if foo == 1
print "one"
else
print "not one"
fi
```

26 changes: 25 additions & 1 deletion _build/reference/645-language-elseif.markdown
Original file line number Diff line number Diff line change
@@ -2,6 +2,30 @@

> ELSEIF

foo = 2: if foo==1: ? "one": ELSEIF foo==2: ? "two": fi
Alternative condition in an IF statement.

### Example 1

~~~
foo = 2
if foo == 1
print "one"
ELSEIF foo == 2
print "two"
endif
~~~

### Example 2: using IF ... ELSE ... IF instead of ELSEIF

~~~
foo = 2
if foo == 1
print "one"
else
if foo == 2
print "two"
endif
endif
~~~


11 changes: 10 additions & 1 deletion _build/reference/646-language-endif.markdown
Original file line number Diff line number Diff line change
@@ -2,6 +2,15 @@

> ENDIF

foo = 1: if foo==1: ? "one": ENDIF
ENDIF ends an if statement. For more information see IF.

### Example

```
foo = 1
if foo == 1 then
print "one"
endif
```


Loading
Oops, something went wrong.