mirror of
https://github.com/DualBrain/QB64.git
synced 2023-11-19 13:10:13 +00:00
More testing.
This commit is contained in:
parent
28c2dcdd4f
commit
683f4a80c8
2
wiki.md
2
wiki.md
|
@ -2,6 +2,8 @@
|
|||
|
||||
## Wiki
|
||||
|
||||
- **[PRINT](wiki/PRINT.md)**
|
||||
|
||||
Although you can find several copies of the QB64 wiki on the internet, many of these exist as *backup copies* due to the past instability issues around QB64 .org and .net websites and (most likely) aren't currently maintained.
|
||||
|
||||
To remedy this, a recent project was begun to transition the wiki so that it is managed in the same way as the source code; meaning it is now directly managed and hosted within the [github repo](https://github.com/QB64Official/qb64). You can find this official wiki at:
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
The [$ASSERTS]($ASSERTS) metacommand enables debug tests with the [_ASSERT](_ASSERT) macro.
|
||||
|
||||
## Syntax
|
||||
|
||||
> [$ASSERTS]($ASSERTS)
|
||||
|
||||
> [$ASSERTS]($ASSERTS):CONSOLE
|
||||
|
||||
## Description
|
||||
|
||||
* If an error message is passed to the [_ASSERT](_ASSERT) statement, it is displayed in the console window if [$ASSERTS]($ASSERTS):CONSOLE is used.
|
||||
|
||||
## Availability
|
||||
|
||||
* Version 1.4 and up.
|
||||
|
||||
## Example(s)
|
||||
|
||||
Adding test checks for parameter inputs in a function.
|
||||
|
||||
```vb
|
||||
|
||||
$ASSERTS:CONSOLE
|
||||
|
||||
DO
|
||||
a = INT(RND * 10)
|
||||
b$ = myFunc$(a)
|
||||
PRINT a, , b$
|
||||
_LIMIT 3
|
||||
LOOP UNTIL _KEYHIT
|
||||
|
||||
FUNCTION myFunc$ (value AS SINGLE)
|
||||
_ASSERT value > 0, "Value cannot be zero"
|
||||
_ASSERT value <= 10, "Value cannot exceed 10"
|
||||
|
||||
IF value > 1 THEN plural$ = "s"
|
||||
myFunc$ = STRING$(value, "*") + STR$(value) + " star" + plural$ + " :-)"
|
||||
END FUNCTION
|
||||
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
* [_ASSERT](_ASSERT)
|
||||
* [$CHECKING]($CHECKING)
|
||||
* [Relational Operations](Relational-Operations)
|
|
@ -1,25 +0,0 @@
|
|||
The [$CHECKING]($CHECKING) metacommand turns C++ event checking ON or OFF.
|
||||
|
||||
## Syntax
|
||||
|
||||
> [$CHECKING]($CHECKING):{ON|OFF}
|
||||
|
||||
## Description
|
||||
|
||||
* The Metacommand does **not** require a comment or REM before it. There is no space after the colon.
|
||||
* The OFF action turns event checking off and should **only be used when running stable, errorless code.**
|
||||
* The default [$CHECKING]($CHECKING):ON action is only required when checking has been turned OFF previously.
|
||||
* When [$CHECKING]($CHECKING):OFF is used, all error code and the reporting code is removed from the EXE program.
|
||||
* **Warning: Turning OFF error checking could create a General Protection Fault (or segfault). Use only with 100% stable sections of code.**
|
||||
|
||||
### Details
|
||||
|
||||
* After every QB64 command is translated to C++, the compiler adds special code sections to check for [ON TIMER (n)](ON-TIMER-(n)) events and errors that may have occured in the last function call. Disabling error checking with the [$CHECKING]($CHECKING):OFF directive prevents the compiler from adding the extra code sections.
|
||||
* Setting [$CHECKING]($CHECKING):OFF is only designed for 100% stable, errorless sections of code, where every CPU cycle saved counts, such as in a software 3D texture mapper, for example.
|
||||
|
||||
## See Also
|
||||
|
||||
* [ON TIMER(n)](ON-TIMER(n))
|
||||
* [ON ERROR](ON-ERROR)
|
||||
* [Metacommand](Metacommand)
|
||||
* [ERROR Codes](ERROR-Codes)
|
|
@ -1,62 +0,0 @@
|
|||
[$COLOR]($COLOR) is a metacommand that adds named color [CONST](CONST) in a program.
|
||||
|
||||
## Syntax
|
||||
|
||||
> [$COLOR]($COLOR):{0|32}
|
||||
|
||||
|
||||
## Description
|
||||
|
||||
* [$COLOR]($COLOR):0 adds [CONST](CONST) for colors 0-15. The actual constant names can be found in the file **source/utilities/color0.bi**.
|
||||
* [$COLOR]($COLOR):32 adds [CONST](CONST) for 32-bit colors, similar to HTML color names. The actual constant names can be found in the file **source/utilities/color32.bi**.
|
||||
* [$COLOR]($COLOR) is a shorthand to manually using [$INCLUDE]($INCLUDE) pointing to the files listed above.
|
||||
* *NOTE*: When using [$NOPREFIX]($NOPREFIX), the color constants change to **C_<old name>** (ex: **Blue** becomes **C_Blue**).
|
||||
|
||||
## Example(s)
|
||||
|
||||
Adding named color constants for SCREEN 0:
|
||||
|
||||
```vb
|
||||
|
||||
$COLOR:0
|
||||
COLOR BrightWhite, Red
|
||||
PRINT "BrightWhite on red."
|
||||
|
||||
```
|
||||
|
||||
```text
|
||||
|
||||
Bright white on red.
|
||||
|
||||
```
|
||||
|
||||
Adding named color constants for 32-bit modes:
|
||||
|
||||
```vb
|
||||
|
||||
SCREEN _NEWIMAGE(640, 400, 32)
|
||||
$COLOR:32
|
||||
COLOR CrayolaGold, DarkCyan
|
||||
PRINT "CrayolaGold on DarkCyan."
|
||||
|
||||
|
||||
```
|
||||
|
||||
Using [$COLOR]($COLOR) with [$NOPREFIX]($NOPREFIX):
|
||||
|
||||
```vb
|
||||
|
||||
$NOPREFIX
|
||||
$COLOR:0
|
||||
COLOR C_BrightWhite, C_Red
|
||||
PRINT "BrightWhite on Red."
|
||||
|
||||
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
* [COLOR](COLOR), [SCREEN](SCREEN)
|
||||
* [_NEWIMAGE](_NEWIMAGE), [$INCLUDE]($INCLUDE)
|
||||
* [$NOPREFIX]($NOPREFIX)
|
||||
* [Metacommand](Metacommand)
|
|
@ -1,90 +0,0 @@
|
|||
The [$CONSOLE]($CONSOLE) [metacommand](metacommand) creates a console window that can be used throughout a QB64 program module.
|
||||
|
||||
## Syntax
|
||||
|
||||
> [$CONSOLE]($CONSOLE)[:ONLY]
|
||||
|
||||
## Description
|
||||
|
||||
* [_CONSOLE](_CONSOLE) **ON** or **OFF** may be used to show or hide the console window at run time.
|
||||
* The **:ONLY** option can be used when only a console window is desired without a program window.
|
||||
* [_DEST](_DEST) and [_SOURCE](_SOURCE) are automatically set to [_CONSOLE](_CONSOLE) when the **:ONLY** option is used, in order to send screen output to the console window and get input from it too.
|
||||
* In normal [$CONSOLE]($CONSOLE) mode (dual screen) you have to manually set [_DEST](_DEST) and [_SOURCE](_SOURCE) to [_CONSOLE](_CONSOLE) in order to work with the console window.
|
||||
* [_SCREENHIDE](_SCREENHIDE) and [_SCREENSHOW](_SCREENSHOW) can be used to hide or show the main program window.
|
||||
* [_DELAY](_DELAY) or [SLEEP](SLEEP) can be used to allow the console window to be set in front of the main program window.
|
||||
* [_CONSOLETITLE](_CONSOLETITLE) can be used to change the title of the console window.
|
||||
* **Note:** Text can be copied partially or totally from console screens in Windows by highlighting and using the title bar menu.
|
||||
> To copy console text output, right click the title bar and select *Edit* for *Mark* to highlight and repeat to *Copy*
|
||||
* QB64 [Metacommand](Metacommand)s are not commented out with ' or REM, differently from QBasic metacommands.
|
||||
|
||||
## Example(s)
|
||||
|
||||
Hiding and displaying a console window. Use [_DELAY](_DELAY) to place console in front of main program window.
|
||||
|
||||
```vb
|
||||
|
||||
$CONSOLE
|
||||
_DELAY 4
|
||||
|
||||
_CONSOLE OFF
|
||||
_DELAY 4
|
||||
_CONSOLE ON
|
||||
|
||||
_DEST _CONSOLE
|
||||
PRINT "Close this console window or click main window and press a key!"
|
||||
|
||||
```
|
||||
|
||||
How to use a Console window to copy screen output using the *Edit* menu by right clicking the console title bar.
|
||||
|
||||
```vb
|
||||
|
||||
$CONSOLE
|
||||
_DEST _CONSOLE
|
||||
|
||||
c&& = -1: d& = -1: e% = -1: f%% = -1
|
||||
hx$ = HEX$(f%%)
|
||||
PRINT "Max hex _BYTE = "; hx$; " with"; LEN(hx$); "digits ="; VAL("&H" + hx$)
|
||||
hx$ = HEX$(e%)
|
||||
PRINT "Max hex INTEGER = "; hx$; " with"; LEN(hx$); "digits ="; VAL("&H" + hx$)
|
||||
hx$ = HEX$(d&)
|
||||
PRINT "Max hex LONG = "; hx$; " with"; LEN(hx$); "digits ="; VAL("&H" + hx$)
|
||||
hx$ = HEX$(c&&)
|
||||
PRINT "Max hex _INTEGER64 = "; hx$; " with"; LEN(hx$); "digits ="; VAL("&H" + hx$)
|
||||
hx$ = HEX$(9223372036854775807)
|
||||
PRINT "Max _INTEGER64 value = "; hx$; " with"; LEN(hx$); "digits"
|
||||
hx$ = HEX$(-9223372036854775808)
|
||||
PRINT "Min _INTEGER64 value = "; hx$; " with"; LEN(hx$); "digits"
|
||||
|
||||
```
|
||||
|
||||
```text
|
||||
|
||||
Max hex _BYTE = FF with 2 digits = 255
|
||||
Max hex INTEGER = FFFF with 4 digits = 65535
|
||||
Max hex LONG = FFFFFFFF with 8 digits = 4294967295
|
||||
Max hex _INTEGER64 = FFFFFFFFFFFFFFFF with 16 digits =-1
|
||||
Max _INTEGER64 value = 7FFFFFFFFFFFFFFF with 16 digits
|
||||
Min _INTEGER64 value = 8000000000000000 with 16 digits
|
||||
|
||||
```
|
||||
|
||||
> *Console:* Right click and select *Edit* > *Select All* (mouse highlight after) then hit Enter or select *Edit* > *Copy* to the [_CLIPBOARD$ (function)](_CLIPBOARD$-(function)).
|
||||
|
||||
```text
|
||||
|
||||
Max hex _BYTE = FF with 2 digits = 255
|
||||
Max hex INTEGER = FFFF with 4 digits = 65535
|
||||
Max hex LONG = FFFFFFFF with 8 digits = 4294967295
|
||||
Max hex _INTEGER64 = FFFFFFFFFFFFFFFF with 16 digits =-1
|
||||
|
||||
```
|
||||
|
||||
> *Copied text:* The above text was copied after *Select All* was selected and the smaller area was re-highlighted with the mouse.
|
||||
|
||||
## See Also
|
||||
|
||||
* [_CONSOLE](_CONSOLE)
|
||||
* [$SCREENHIDE]($SCREENHIDE), [$SCREENSHOW]($SCREENSHOW) (QB64 [Metacommand](Metacommand)s)
|
||||
* [_SCREENHIDE](_SCREENHIDE), [_SCREENSHOW](_SCREENSHOW)
|
||||
* [C Libraries](C-Libraries)
|
|
@ -1,39 +0,0 @@
|
|||
**$DEBUG** is precompiler [Metacommand](Metacommand), which enables debugging features, allowing you to step through your code running line by line and to inspect variables and change their values in real time.
|
||||
|
||||
## Syntax
|
||||
|
||||
> [$DEBUG]($DEBUG)
|
||||
|
||||
## Description
|
||||
|
||||
* **$DEBUG** injects extra code in the resulting binary, allowing the IDE to control the execution flow of your program.
|
||||
* When **$DEBUG** is used, the IDE will connect to your running program using a local TCP/IP connection.
|
||||
* You may get a prompt from your Operating System regarding this, so it may be necessary to allow the IDE to receive connections.
|
||||
* No external connections are created, and your running program will only attempt to connect locally to the IDE.
|
||||
* The default TCP/IP port starts at 9001. Multiple running instances of the IDE will attempt to open ports 9002 and up.
|
||||
* You can change the base port in the Debug menu.
|
||||
* The metacommand is supposed to be removed once your program is ready for release, although leaving it in won't have any effect if your program isn't run from the IDE.
|
||||
* The only drawback of leaving the metacommand in is that your binary will end up being larger than required.
|
||||
|
||||
## $DEBUG Mode Operation
|
||||
|
||||
* To start execution in pause mode, you can use **F7** or **F8**.
|
||||
* There will be an arrow next to the line number where execution is paused, indicating the next line that will be run.
|
||||
* When you enable **$DEBUG** mode, you can set breakpoints by clicking the line number at which you wish to stop execution. This can also be achieved by using the **F9** key.
|
||||
* Breakpoints are indicated by a red dot next to the line number.
|
||||
* To clear all breakpoints, hit **F10**.
|
||||
* To skip a line during execution, shift-click a line number
|
||||
* Lines marked for skipping are indicated by an exclamation mark next to the line number.
|
||||
* **F4** opens the Variable List dialog, which allows you to add variables to the Watch List.
|
||||
* During execution, the Variable List dialog also allows you to set the values of variables and also to create Watchpoints.
|
||||
* Watchpoints halt execution, similarly to breakpoints, but do so when a variable matches the condition you specify.
|
||||
* You can use relational operators (=, <>, >=, <=, >, <) to create watchpoint conditions.
|
||||
* After a breakpoint or a watchpoint is reached, **F5** can be used to continue execution.
|
||||
* **F6** can be used when the execution pointer is inside a sub/function. When used, execution will proceed until the procedure is ended.
|
||||
* **F7** can be used to run line by line, and can be used to debug code inside subs/functions (Step Into).
|
||||
* **F8** can be used to run line by line without entering sub/function calls (Step Over).
|
||||
* **F12** can be used to show the current call stack (which procedure calls led to the current line).
|
||||
|
||||
## See Also
|
||||
|
||||
* [Metacommand](Metacommand)s
|
|
@ -1,50 +0,0 @@
|
|||
The [$DYNAMIC]($DYNAMIC) [Metacommand](Metacommand) allows the creation of dynamic (resizable) arrays.
|
||||
|
||||
## Syntax
|
||||
|
||||
> {[REM](REM) | ['](apostrophe) } [$DYNAMIC]($DYNAMIC)
|
||||
|
||||
## Description
|
||||
|
||||
* QBasic [Metacommand](Metacommand) require [REM](REM) or [Apostrophe](Apostrophe) (') before them and are normally placed at the start of the main module.
|
||||
* Dynamic arrays can be resized using [REDIM](REDIM). The array's type cannot be changed.
|
||||
* All data in the array will be lost when [REDIM](REDIM)ensioned except when [_PRESERVE](_PRESERVE) is used.
|
||||
* [REDIM](REDIM) [_PRESERVE](_PRESERVE) can preserve and may move the previous array data when the array boundaries change.
|
||||
* [_PRESERVE](_PRESERVE) allows the [UBOUND](UBOUND) and [LBOUND](LBOUND) boundaries of an array to be changed. The number of dimensions cannot change.
|
||||
* [$DYNAMIC]($DYNAMIC) arrays must be [REDIM](REDIM)ensioned if [ERASE](ERASE) or [CLEAR](CLEAR) are used as the arrays are removed completely.
|
||||
|
||||
## Example(s)
|
||||
|
||||
[REDIM](REDIM)ing a $DYNAMIC array using [_PRESERVE](_PRESERVE) to retain previous array values.
|
||||
|
||||
```vb
|
||||
|
||||
REM $DYNAMIC 'create dynamic arrays only
|
||||
DIM array(10) 'create array with 11 elements
|
||||
FOR i = 0 TO 10
|
||||
array(i) = i: PRINT array(i); 'set and display element values
|
||||
NEXT
|
||||
PRINT
|
||||
REDIM _PRESERVE array(10 TO 20)
|
||||
FOR i = 10 TO 20
|
||||
PRINT array(i);
|
||||
NEXT
|
||||
END
|
||||
|
||||
```
|
||||
|
||||
```text
|
||||
|
||||
0 1 2 3 4 5 6 7 8 9 10
|
||||
|
||||
0 1 2 3 4 5 6 7 8 9 10
|
||||
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
* [$STATIC]($STATIC), [$INCLUDE]($INCLUDE)
|
||||
* [DIM](DIM), [REDIM](REDIM), [_DEFINE](_DEFINE)
|
||||
* [STATIC](STATIC)
|
||||
* [ERASE](ERASE), [CLEAR](CLEAR)
|
||||
* [Arrays](Arrays), [Metacommand](Metacommand)
|
|
@ -1 +0,0 @@
|
|||
See [$IF]($IF).
|
|
@ -1 +0,0 @@
|
|||
See [$IF]($IF).
|
|
@ -1 +0,0 @@
|
|||
See [$IF]($IF).
|
|
@ -1,33 +0,0 @@
|
|||
The [$ERROR]($ERROR) metacommand triggers a compilation error.
|
||||
|
||||
## Syntax
|
||||
|
||||
> [$ERROR]($ERROR) MESSAGE
|
||||
|
||||
## Description
|
||||
|
||||
* The Metacommand does **not** require a comment or REM before it.
|
||||
* MESSAGE is any text. Quotation marks are not required.
|
||||
* When QB64 tries to compile an $ERROR metacommand a compilation error is triggered and MESSAGE is shown to the user. This is useful in [$IF]($IF) blocks.
|
||||
|
||||
### Details
|
||||
|
||||
* If there is a particular situation where you know your program will not work properly, you can prevent the user compiling and give them a helpful error message instead by checking for the condition with [$IF]($IF).
|
||||
* An [$ERROR]($ERROR) directive not inside an [$IF]($IF) (or [$ELSEIF]($ELSEIF)) block is useless because the program will never compile.
|
||||
|
||||
## Example(s)
|
||||
|
||||
```vb
|
||||
|
||||
$IF VERSION < 2.1 OR WINDOWS = 0 THEN
|
||||
$ERROR Requires Windows QB64 version 2.1 or above
|
||||
$END IF
|
||||
|
||||
```
|
||||
|
||||
*Output*: Compilation check failed: REQUIRES WINDOWS QB64 VERSION 2.1 OR ABOVE on line 2 (assuming your version of QB64 doesn't meet those requirements).
|
||||
|
||||
## See Also
|
||||
|
||||
* [Metacommand](Metacommand)
|
||||
* [$IF]($IF)
|
|
@ -1,31 +0,0 @@
|
|||
**$EXEICON** pre-compiler metacommand embeds a designated icon file into the compiled EXE file to be viewed in Windows Explorer.
|
||||
|
||||
## Syntax
|
||||
|
||||
> [$EXEICON]($EXEICON):'iconfile.ico'
|
||||
|
||||
## Parameter(s)
|
||||
|
||||
* 'iconfile.ico' is a valid [ICO file format](https://en.wikipedia.org/wiki/ICO)
|
||||
|
||||
## Description
|
||||
|
||||
* Calling [_ICON](_ICON) without an imageHandle& uses the embeded icon, if available.
|
||||
* Starting with **build 20170906/64**, the window will automatically use the icon embedded by [$EXEICON]($EXEICON), without having to call _ICON.
|
||||
* **[Keywords currently not supported](Keywords-currently-not-supported-by-QB64)**.
|
||||
|
||||
## Example(s)
|
||||
|
||||
Embeds a designated icon file into the compiled EXE which can be viewed in Windows Explorer folders.
|
||||
|
||||
```vb
|
||||
|
||||
$EXEICON:'mush.ico'
|
||||
_ICON
|
||||
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
* [_ICON](_ICON)
|
||||
* [_TITLE](_TITLE)
|
81
wiki/$IF.md
81
wiki/$IF.md
|
@ -1,81 +0,0 @@
|
|||
**$IF** is precompiler [Metacommand](Metacommand), which determines which sections of code inside its blocks are included into the final code for compliing.
|
||||
|
||||
## Syntax
|
||||
|
||||
> [$IF]($IF) variable = expression THEN
|
||||
> .
|
||||
> [$ELSEIF]($ELSEIF) variable = expression THEN
|
||||
> .
|
||||
> [$ELSE]($ELSE)
|
||||
> .
|
||||
> [$END IF]($END-IF)
|
||||
|
||||
* $IF is the start of a precompiler code block which includes or excludes sections of code from being compiled.
|
||||
* There is no single line $IF statement. $IF must be in a valid $IF THEN...$END IF block to work properly.
|
||||
* Like all other metacommands, you can not use more than one metacommand per line. **Use of : to separate statements in a single line is not allowed.**
|
||||
* Variable names can contain numbers, letters and periods, in any order.
|
||||
* Expressions can contain one set of leading and/or trailing quotes; and any number of numbers, letters and periods, in any order.
|
||||
* The precompiler comes with some preset values which can be used to help determine which code blocks to include/exclude. These are:
|
||||
* **WIN** or **WINDOWS** if the user is running QB64 in a Windows environment.
|
||||
* **LINUX** if the user is running QB64 in a Linux environment.
|
||||
* **MAC** or **MACOSX** if the user is running QB64 in a macOS environment.
|
||||
* **32BIT** if the user is running a 32-bit version of QB64.
|
||||
* **64BIT** if the user is running a 64-bit version of QB64.
|
||||
* **VERSION**, which is set to the version of the QB64 compiler. This is a number and can be ordered, see example below.
|
||||
* Special values **DEFINED** and **UNDEFINED** can be used to check whether a precompiler variable has already been assigned a value. Useful for code in libraries which may be repeated.
|
||||
* [$END IF]($END-IF) denotes the end of a valid precompiler $IF block.
|
||||
* [$ELSEIF]($ELSEIF) must follow a valid $IF or $ELSEIF statement.
|
||||
* If [$ELSE]($ELSE) is used, it must be used as the last conditional check before $END IF. $ELSEIF cannot come after $ELSE.
|
||||
* There can only be one $ELSE in an **$IF-$ELSEIF-$ELSE-$END IF** block, and it must be the last block selection before the $END IF. $ELSEIF cannot follow $ELSE.
|
||||
|
||||
## Example(s)
|
||||
|
||||
```vb
|
||||
|
||||
$LET ScreenMode = 32
|
||||
$IF ScreenMode = 0 THEN
|
||||
CONST Red = 4
|
||||
$ELSEIF ScreenMode = 32 THEN
|
||||
CONST Red = _RGB32(255,0,0)
|
||||
$END IF
|
||||
|
||||
COLOR Red
|
||||
PRINT "Hello World"
|
||||
|
||||
```
|
||||
|
||||
*Explanation:* The same CONST is defined twice inside the program. Normally, defining a CONST more than once generates an error, but the $IF condition here is choosing which CONST will be inside the final program.
|
||||
|
||||
As long as Screenmode is 0, the program will exclude the code where CONST Red is defined as color 4. If Screenmode is 32, CONST Red will be defined as _RGB32(255, 0, 0).
|
||||
|
||||
The [$LET]($LET) and $IF statements let the programmer control the code that actually gets compiled, while excluding the other blocks completely.
|
||||
|
||||
```vb
|
||||
|
||||
$IF WIN THEN
|
||||
CONST Slash = "\"
|
||||
$ELSE
|
||||
CONST Slash = "/"
|
||||
$END IF
|
||||
|
||||
PRINT "The proper slash for your operating system is "; Slash
|
||||
|
||||
```
|
||||
|
||||
*Explanation:* For the above, the CONST slash is defined by the automatic internal flags which returns what operating system is being used at compile time. On a Windows PC, the Slash will be the backslash; for any other OS it will be the forward slash.
|
||||
|
||||
```vb
|
||||
|
||||
$IF VERSION < 1.5 THEN
|
||||
$ERROR Requires QB64 version 1.5 or greater
|
||||
$END IF
|
||||
|
||||
```
|
||||
|
||||
*Explanation:* VERSION is a predefined variable that holds the QB64 compiler version. If we know our program needs features only available above a certain version, we can check for that and give the user a helpful error message instead of a confusing error elsewhere in the program.
|
||||
|
||||
## See Also
|
||||
|
||||
* [$LET]($LET)
|
||||
* [$ERROR]($ERROR)
|
||||
* [Metacommand](Metacommand)s
|
|
@ -1,43 +0,0 @@
|
|||
[$INCLUDE]($INCLUDE) is a metacommand that is used to insert a source code file into your program which is then executed at the point of the insertion.
|
||||
|
||||
## Syntax
|
||||
|
||||
> {[REM](REM) | ['](apostrophe) } [$INCLUDE]($INCLUDE): 'sourceFile'
|
||||
|
||||
## Description
|
||||
|
||||
* QBasic [Metacommand](Metacommand) must be commented with [REM](REM) or an apostrophe.
|
||||
* The sourceFile name must be enclosed in apostrophes and can include a path.
|
||||
* $INCLUDE is often used to add functions and subs from an external text QBasic code library.
|
||||
* The $INCLUDE metacommand should be the only statement on a line.
|
||||
|
||||
### How to $INCLUDE a BAS or Text file with a QB64 Program
|
||||
|
||||
* Assemble the code to be reused into a file.
|
||||
* Common extensions are **.BI** (for declarations, usually included in the beginning of a program) or **.BM** (with SUBs and FUNCTIONs, usually included at the end of a program).
|
||||
* Any extension can be used, as long as the file contains code in plain text (binary files are not accepted).
|
||||
* $INCLUDE any [DIM](DIM), [CONST](CONST), [SHARED](SHARED) arrays or [DATA](DATA) at the **beginning** of the main program code.
|
||||
* $INCLUDE [SUB](SUB)s or [FUNCTION](FUNCTION)s at the bottom of the main program code **after any SUB procedures.**
|
||||
* **Note:** [TYPE](TYPE) definitions, [DATA](DATA) and [DECLARE LIBRARY](DECLARE-LIBRARY) can be placed inside of sub-procedures.
|
||||
* **Compile** the program.
|
||||
**Note: Once the program is compiled, the included text files are no longer needed with the program EXE.*
|
||||
|
||||
## Example(s)
|
||||
|
||||
```vb
|
||||
|
||||
** '$INCLUDE:** 'QB.BI'
|
||||
|
||||
```
|
||||
|
||||
### More examples
|
||||
|
||||
* [SelectScreen](SelectScreen) (member-contributed $INCLUDE demo)
|
||||
* [FILELIST$](FILELIST$) (member-contributed file search function)
|
||||
* [SAVEIMAGE](SAVEIMAGE) (SUB program that creates bitmaps)
|
||||
|
||||
## See Also
|
||||
|
||||
* [INTERRUPT](INTERRUPT), [INTERRUPTX](INTERRUPTX)
|
||||
* [TYPE](TYPE), [DIM](DIM)
|
||||
* [Metacommand](Metacommand)
|
31
wiki/$LET.md
31
wiki/$LET.md
|
@ -1,31 +0,0 @@
|
|||
[$LET]($LET) is a precompiler command, which is now usable by modern day [cavemen](cavemen) to help include and exclude which sections of code compiles in their program based on OS/bit-size or other predefined conditions.
|
||||
|
||||
## Syntax
|
||||
|
||||
> [$LET]($LET) variable = expression
|
||||
|
||||
## Description
|
||||
|
||||
* Unlike [LET](LET), [$LET]($LET) is not optional.
|
||||
* $LET A = 12 sets a precompiler variable "a" to the value of 12. This variable is only valid for the precompiler itself and does nothing to affect the values of any variable/constant which might also be called "a" in the program.
|
||||
* Variable names must follow QB64's variable naming conventions.
|
||||
* You can check a precompiler variable against special values **DEFINED** and **UNDEFINED**, in order to assess whether the variable has already been assigned a value. Useful for code in libraries which may be repeated.
|
||||
* The precompiler comes with some preset values which can be used to help determine which code blocks to include/exclude. These are:
|
||||
* **WIN** or **WINDOWS** if the user is running QB64 in a Windows environment.
|
||||
* **LINUX** if the user is running QB64 in a Linux environment.
|
||||
* **MAC** or **MACOSX** if the user is running QB64 in a macOS environment.
|
||||
* **32BIT** if the user is running a 32-bit version of QB64.
|
||||
* **64BIT** if the user is running a 64-bit version of QB64.
|
||||
* **VERSION**, which is set to the version of the QB64 compiler.
|
||||
|
||||
## Example(s)
|
||||
|
||||
* See example 1 in [$IF]($IF).
|
||||
|
||||
## See Also
|
||||
|
||||
* [$IF]($IF)
|
||||
* [$ELSE]($ELSE)
|
||||
* [$ELSEIF]($ELSEIF)
|
||||
* [$END IF]($END-IF)
|
||||
* [Cavemen](Cavemen)
|
|
@ -1,23 +0,0 @@
|
|||
The [$NOPREFIX]($NOPREFIX) metacommand allows all QB64 functions and statements to be used without the leading underscore (_).
|
||||
|
||||
## Syntax
|
||||
|
||||
> [$NOPREFIX]($NOPREFIX)
|
||||
|
||||
## Description
|
||||
|
||||
* QB64-specific keywords are by default prefixed with an underscore, in order to differentiate them from legacy keywords inherited from QBasic/QuickBASIC 4.5.
|
||||
* The convention exists in order to allow older code to be loaded and compiled in QB64 without naming conflicts with existing variables or constants.
|
||||
* If you are writing new code with QB64, and not importing code from QBasic/QuickBASIC 4.5, [$NOPREFIX]($NOPREFIX) allows you to reduce typing by not having to use underscores in modern keywords.
|
||||
* **SUB _GL** still must be prefixed.
|
||||
* When [$NOPREFIX]($NOPREFIX) is used, QB64 keywords can be used both with or without the leading underscore, so that both [_DISPLAY](_DISPLAY) and [DISPLAY](_DISPLAY) are valid in the same program, for example.
|
||||
* [$NOPREFIX]($NOPREFIX) can be placed anywhere in a program.
|
||||
|
||||
## Availability
|
||||
|
||||
* Version 1.4 and up.
|
||||
|
||||
## See Also
|
||||
|
||||
* [Keywords (Alphabetical)](Keyword-Reference---Alphabetical)
|
||||
* [Metacommand](Metacommand)
|
111
wiki/$RESIZE.md
111
wiki/$RESIZE.md
|
@ -1,111 +0,0 @@
|
|||
The [$RESIZE]($RESIZE) [Metacommand](Metacommand) determines if a program window can be resized by the user.
|
||||
|
||||
## Syntax
|
||||
|
||||
> [$RESIZE]($RESIZE):{ON|OFF|STRETCH|SMOOTH}
|
||||
|
||||
## Description
|
||||
|
||||
* $RESIZE:ON is used to allow the program window to be resized by a program user. Otherwise it cannot be changed.
|
||||
* $RESIZE:OFF (**default**) is used when the program's window size cannot be changed by the user.
|
||||
* $RESIZE:STRETCH the screen will be stretched to fit the new window size with a 1 to 1 ratio of width and height.
|
||||
* $RESIZE:SMOOTH the screen will be stretched also, but with linear filtering applied to the pixels.
|
||||
|
||||
## Availability
|
||||
|
||||
* Version 1.000 and up.
|
||||
|
||||
## Example(s)
|
||||
|
||||
Resizing a program screen when the user changes it without clearing the entire screen image:
|
||||
|
||||
```vb
|
||||
|
||||
$RESIZE:ON
|
||||
|
||||
SCREEN _NEWIMAGE(160, 140, 32)
|
||||
_DELAY 0.1
|
||||
_SCREENMOVE 20, 20
|
||||
_DISPLAY
|
||||
|
||||
' CLEAR _RESIZE FLAG BY READING IT ONCE
|
||||
temp& = _RESIZE
|
||||
|
||||
DO
|
||||
|
||||
_LIMIT 60
|
||||
|
||||
IF CheckResize(_SOURCE) = -1 THEN
|
||||
FOR i = 1 TO 10
|
||||
CIRCLE (RND * _WIDTH(0) - 1, RND * _HEIGHT(0) - 1), RND * 100 + 5, _RGB32(RND * 255, RND * 255, RND * 255)
|
||||
NEXT
|
||||
ELSE
|
||||
FOR i = 1 TO 200
|
||||
PSET (RND * _WIDTH(0) - 1, RND * _HEIGHT(0) - 1), _RGB32(RND * 255, RND * 255, RND * 255)
|
||||
NEXT
|
||||
END IF
|
||||
|
||||
_DISPLAY
|
||||
|
||||
k& = _KEYHIT
|
||||
|
||||
LOOP UNTIL k& = 27 OR k& = 32
|
||||
|
||||
SYSTEM
|
||||
|
||||
' *************************************************************************************************
|
||||
' * *
|
||||
' * CheckResize: This FUNCTION checks if the user resized the window, and if so, recreates the *
|
||||
' * ORIGINAL SCREEN image to the new window size. *
|
||||
' * *
|
||||
' * Developer Note: You must use $RESIZE:ON, $RESIZE:SMOOTH, or $RESIZE:SMOOTH at *
|
||||
' * the beginning of your project for this to work. *
|
||||
' * This FUNCTION only works in QB64 version 1.000 and up. *
|
||||
' * *
|
||||
' *************************************************************************************************
|
||||
FUNCTION CheckResize (CurrentScreen AS _UNSIGNED LONG)
|
||||
|
||||
' *** Define local variable for temporary screen
|
||||
DIM TempScreen AS _UNSIGNED LONG
|
||||
|
||||
CheckResize = 0
|
||||
|
||||
' *** Check to see if the user resized the window. If so, change the SCREEN image to the correct size.
|
||||
IF _RESIZE THEN
|
||||
|
||||
' *** First, create a copy of the current SCREEN image.
|
||||
TempScreen = _COPYIMAGE(CurrentScreen, 32)
|
||||
|
||||
' *** Set the SCREEN to the copied image, releasing the current SCREEN image.
|
||||
SCREEN TempScreen
|
||||
|
||||
' *** Remove (FREE) the original SCREEN image.
|
||||
_FREEIMAGE CurrentScreen
|
||||
|
||||
' *** Create a new "original" SCREEN image.
|
||||
CurrentScreen = _NEWIMAGE(_RESIZEWIDTH, _RESIZEHEIGHT, 32)
|
||||
|
||||
' *** Set the SCREEN to the new "original" image, releasing the copied SCREEN image.
|
||||
SCREEN CurrentScreen
|
||||
|
||||
' DRAW PREVIOUS SCREEN ON THE NEW ONE
|
||||
_PUTIMAGE (0, 0), TempScreen, CurrentScreen
|
||||
|
||||
_DISPLAY
|
||||
|
||||
' *** Remove (FREE) the copied SCREEN image.
|
||||
_FREEIMAGE TempScreen
|
||||
|
||||
' *** Tell the caller there was a resize
|
||||
CheckResize = -1
|
||||
|
||||
END IF
|
||||
|
||||
END FUNCTION
|
||||
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
* [_RESIZE](_RESIZE), [_RESIZE (function)](_RESIZE-(function))
|
||||
* [_RESIZEWIDTH](_RESIZEWIDTH), [_RESIZEHEIGHT](_RESIZEHEIGHT) (functions return the requested dimensions)
|
|
@ -1,36 +0,0 @@
|
|||
The [$SCREENHIDE]($SCREENHIDE) [Metacommand](Metacommand) can be used to hide the main program window throughout a program.
|
||||
|
||||
## Syntax
|
||||
|
||||
> [$SCREENHIDE]($SCREENHIDE)
|
||||
|
||||
* $SCREENHIDE may be used at the start of a program to hide the main program window when using a [$CONSOLE]($CONSOLE) window.
|
||||
* The [_SCREENHIDE](_SCREENHIDE) statement must be used before [_SCREENSHOW](_SCREENSHOW) can be used in sections of a program.
|
||||
* **QB64 [Metacommand](Metacommand)s cannot be commented out with [apostrophe](apostrophe) or [REM](REM)**.
|
||||
|
||||
## Example(s)
|
||||
|
||||
Hiding a program when displaying a message box in Windows.
|
||||
|
||||
```vb
|
||||
|
||||
$SCREENHIDE
|
||||
DECLARE DYNAMIC LIBRARY "user32"
|
||||
FUNCTION MessageBoxA& (BYVAL hWnd%&, BYVAL lpText%&, BYVAL lpCaption%&, BYVAL uType~&)
|
||||
END DECLARE
|
||||
DECLARE DYNAMIC LIBRARY "kernel32"
|
||||
SUB ExitProcess (BYVAL uExitCode~&)
|
||||
END DECLARE
|
||||
DIM s0 AS STRING
|
||||
DIM s1 AS STRING
|
||||
s0 = "Text" + CHR$(0)
|
||||
s1 = "Caption" + CHR$(0)
|
||||
ExitProcess MessageBoxA(0, _OFFSET(s0), _OFFSET(s1), 0)
|
||||
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
* [$CONSOLE]($CONSOLE), [$SCREENSHOW]($SCREENSHOW)
|
||||
* [_SCREENHIDE](_SCREENHIDE), [_SCREENSHOW](_SCREENSHOW)
|
||||
* [_CONSOLE](_CONSOLE)
|
|
@ -1,18 +0,0 @@
|
|||
The [$SCREENSHOW]($SCREENSHOW) [Metacommand](Metacommand) can be used to display the main program window throughout the program.
|
||||
|
||||
## Syntax
|
||||
|
||||
> $SCREENSHOW
|
||||
|
||||
## Description
|
||||
|
||||
* The metacommand is intended to be used in a modular program when a screen surface is necessary in one or more modules.
|
||||
* $SCREENSHOW can only be used after [$SCREENHIDE]($SCREENHIDE) or [_SCREENHIDE](_SCREENHIDE) have been used in another program module.
|
||||
* If [$SCREENHIDE]($SCREENHIDE) and then [$SCREENSHOW]($SCREENSHOW) are used in the same program module the window will not be hidden.
|
||||
* **QB64 [Metacommand](Metacommand)s cannot be commented out with [apostrophe](apostrophe) or [REM](REM).**
|
||||
|
||||
## See Also
|
||||
|
||||
* [$CONSOLE]($CONSOLE), [$SCREENHIDE]($SCREENHIDE) (QB64 [Metacommand](Metacommand)s)
|
||||
* [_SCREENHIDE](_SCREENHIDE), [_SCREENSHOW](_SCREENSHOW)
|
||||
* [_CONSOLE](_CONSOLE)
|
|
@ -1,37 +0,0 @@
|
|||
The [$STATIC]($STATIC) [Metacommand](Metacommand) allows the creation of static (unresizable) arrays.
|
||||
|
||||
## Syntax
|
||||
|
||||
> {[REM](REM) | ['](apostrophe) } [$STATIC]($STATIC)
|
||||
|
||||
## Description
|
||||
|
||||
* QBasic [Metacommand](Metacommand)s require a REM or apostrophy (') before them and are normally placed at the start of the main module.
|
||||
* Static arrays cannot be resized. If a variable is used to size any array, it becomes [$DYNAMIC]($DYNAMIC).
|
||||
* A [REDIM](REDIM) statement has no effect on [$STATIC]($STATIC) arrays except perhaps a [ERROR Codes](ERROR-Codes) at the [REDIM](REDIM) statement.
|
||||
* The array's type cannot be changed once [DIM](DIM) and a literal value sets the dimensions and element size.
|
||||
* [$STATIC]($STATIC) defined program [arrays](arrays) cannot be [REDIM](REDIM) or use [_PRESERVE](_PRESERVE).
|
||||
|
||||
## Example(s)
|
||||
|
||||
When a variable is used, the array can be resized despite $STATIC. The array becomes [$DYNAMIC]($DYNAMIC).
|
||||
|
||||
```vb
|
||||
|
||||
'$STATIC
|
||||
|
||||
INPUT "Enter array size: ", size
|
||||
DIM array(size) 'using an actual number instead of the variable will create an error!
|
||||
|
||||
REDIM array(2 * size)
|
||||
|
||||
PRINT UBOUND(array)
|
||||
|
||||
```
|
||||
|
||||
> *Note:* [DIM](DIM) using a literal numerical size will create a Duplicate definition error.
|
||||
|
||||
## See Also
|
||||
|
||||
* [$DYNAMIC]($DYNAMIC), [STATIC](STATIC)
|
||||
* [Arrays](Arrays), [Metacommand](Metacommand)
|
|
@ -1,39 +0,0 @@
|
|||
The [$VERSIONINFO]($VERSIONINFO) [Metacommand](Metacommand) adds text metadata to the resulting executable for identification purposes across the OS. Windows-only.
|
||||
|
||||
## Syntax
|
||||
|
||||
> [$VERSIONINFO]($VERSIONINFO):key=value
|
||||
|
||||
## Parameter(s)
|
||||
|
||||
* Text *keys* can be: **Comments, CompanyName, FileDescription, FileVersion, InternalName, LegalCopyright, LegalTrademarks, OriginalFilename, ProductName, ProductVersion, Web**
|
||||
* Numeric keys can be:**FILEVERSION#** and **PRODUCTVERSION#**
|
||||
|
||||
## Description
|
||||
|
||||
* Text and numerical values are string literals without quotes entered by programmer. **No variables are accepted.** (variable names would be interpreted as literals).
|
||||
* Numeric key=*value* must be 4 comma-separated numerical text values entered by programmer which usually stand for major, minor, revision and build numbers).
|
||||
* A manifest file is automatically embedded into the resulting .exe file so that Common Controls v6.0 gets linked at runtime, if required.
|
||||
* [Keywords currently not supported](Keywords-currently-not-supported-by-QB64).
|
||||
|
||||
## Availability
|
||||
|
||||
* Build 20170429/52 and up.
|
||||
|
||||
## Example(s)
|
||||
|
||||
Adding metadata to a Windows exe compiled with QB64:
|
||||
|
||||
```vb
|
||||
|
||||
$VERSIONINFO:CompanyName=Your company name goes here
|
||||
$VERSIONINFO:FILEVERSION#=1,0,0,0
|
||||
$VERSIONINFO:PRODUCTVERSION#=1,0,0,0
|
||||
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
* [$EXEICON]($EXEICON)
|
||||
* [_ICON](_ICON)
|
||||
* [VERSIONINFO resource (MSDN)](https://msdn.microsoft.com/library/windows/desktop/aa381058(v=vs.85).aspx)
|
|
@ -1,24 +0,0 @@
|
|||
[DEPRECATED] The [$VIRTUALKEYBOARD]($VIRTUALKEYBOARD) [Metacommand](Metacommand) turns the virtual keyboard ON or OFF.
|
||||
|
||||
## Syntax
|
||||
|
||||
> [$VIRTUALKEYBOARD]($VIRTUALKEYBOARD):{ON|OFF}
|
||||
|
||||
## Description
|
||||
|
||||
* Places a virtual keyboard on screen, which can be used in touch-enabled devices like Windows tablets.
|
||||
* Deprecated.
|
||||
|
||||
## Example(s)
|
||||
|
||||
```vb
|
||||
|
||||
$VIRTUALKEYBOARD:ON
|
||||
|
||||
DO: LOOP UNTIL INKEY$ = CHR$(27)
|
||||
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
* [Metacommand](Metacommand)s
|
160
wiki/&B.md
160
wiki/&B.md
|
@ -1,160 +0,0 @@
|
|||
The **&B&** prefix denotes that an integer value is expressed in a binary base 2 format using **QB64** only.
|
||||
|
||||
## Syntax
|
||||
|
||||
> a& = **&B1110110000111111**
|
||||
|
||||
* The base 2 numbering system uses binary digit values of 1 or 0, or bits on or bits off in computer register switches or memory.
|
||||
* Leading zero values **can** be omitted as they add nothing to the byte return value.
|
||||
* Eight binary digits would represent a one-byte value ranging from 0 to 255. Four-digit values("nibbles") range from 0 to 15.
|
||||
* Decimal values returned can be any **signed** [INTEGER](INTEGER), [LONG](LONG) integer, or [_INTEGER64](_INTEGER64) value so use those type of variables when converting directly as shown in the Syntax. The program ["overflow"](ERROR-Codes) error limits are listed as:
|
||||
* [INTEGER](INTEGER): 16 binary digits or a decimal value range from -32,768 to 32,767
|
||||
* [LONG](LONG): 32 binary digits or a decimal value range from -2,147,483,648 to 2,147,483,647
|
||||
* [_INTEGER64](_INTEGER64): 64 binary digits or decimal values from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
|
||||
* [LONG](LONG) values can be returned by appending the & or ~%([_UNSIGNED](_UNSIGNED) [INTEGER](INTEGER)) symbols after the binary number.
|
||||
* [VAL](VAL) can be used to convert "&B" prefixed string values to decimal.
|
||||
|
||||
**[BITS](_BIT)**
|
||||
|
||||
* The **MSB** is the most significant(largest) bit value and **LSB** is the least significant bit of a binary or register memory address value. The order in which the bits are read determines the binary or decimal byte value. There are two common ways to read a byte:
|
||||
|
||||
* **"Big-endian"**: MSB is the first bit encountered, decreasing to the LSB as the last bit by position, memory address or time.
|
||||
* **"Little-endian"**: LSB is the first bit encountered, increasing to the MSB as the last bit by position, memory address or time.
|
||||
|
||||
```text
|
||||
'''Offset or Position: 0 1 2 3 4 5 6 7 Example: 11110000'''
|
||||
---------------------------------- --------
|
||||
'''Big-Endian Bit On Value:''' 128 64 32 16 8 4 2 1 240
|
||||
'''Little-Endian Bit On Value:''' 1 2 4 8 16 32 64 128 15
|
||||
```
|
||||
|
||||
> The big-endian method compares exponents of 2 <sup>7</sup> down to 2 <sup>0</sup> while the little-endian method does the opposite.
|
||||
|
||||
**[BYTES](_BYTE)**
|
||||
|
||||
* [INTEGER](INTEGER) values consist of 2 bytes called the **HI** and **LO** bytes. Anytime that the number of binary digits is a multiple of 16 (2bytes, 4 bytes, etc.) and the HI byte's MSB is on(1), the value returned will be negative. Even with [SINGLE](SINGLE) or [DOUBLE](DOUBLE) values!
|
||||
|
||||
```text
|
||||
'''16 BIT INTEGER OR REGISTER'''
|
||||
'''AH (High Byte Bits) AL (Low Byte Bits)'''
|
||||
BIT: 15 14 13 12 11 10 9 8 | 7 6 5 4 3 2 1 0
|
||||
---------------------------------------|--------------------------------------
|
||||
HEX: 8000 4000 2000 1000 800 400 200 100 | 80 40 20 10 8 4 2 1
|
||||
|
|
||||
DEC: -32768 16384 8192 4096 2048 1024 512 256 | 128 64 32 16 8 4 2 1
|
||||
```
|
||||
|
||||
> The HI byte's **MSB** is often called the **sign** bit! When all 16 of the integer binary bits are on, the decimal return is -1.
|
||||
|
||||
```text
|
||||
'''Comparing the Base Numbering Systems'''
|
||||
|
||||
'''Decimal (base 10) Binary (base 2) Hexadecimal (base 16) Octal (base 8)'''
|
||||
|
||||
0 0000 0 0
|
||||
1 0001 1 1
|
||||
2 0010 2 2
|
||||
3 0011 3 3
|
||||
4 0100 4 4
|
||||
5 0101 5 5
|
||||
6 0110 6 6
|
||||
7 0111 7 7 -- maxed
|
||||
8 1000 8 10
|
||||
maxed-- 9 1001 9 11
|
||||
10 1010 A 12
|
||||
11 1011 B 13
|
||||
12 1100 C 14
|
||||
13 1101 D 15
|
||||
14 1110 E 16
|
||||
15 ------------- 1111 <--- Match ---> F ---------------- 17 -- max 2
|
||||
16 10000 10 20
|
||||
|
||||
When the Decimal value is 15, the other 2 base systems are all maxed out!
|
||||
The Binary values can be compared to all of the HEX value digit values so
|
||||
it is possible to convert between the two quite easily. To convert a HEX
|
||||
value to Binary just add the 4 binary digits for each HEX digit place so:
|
||||
|
||||
F A C E
|
||||
&HFACE = 1111 + 1010 + 1100 + 1101 = &B1111101011001101
|
||||
|
||||
To convert a Binary value to HEX you just need to divide the number into
|
||||
sections of four digits starting from the right (LSB) end. If one has less
|
||||
than 4 digits on the left end you could add the leading zeros like below:
|
||||
|
||||
&B101011100010001001 = 0010 1011 1000 1000 1001
|
||||
hexadecimal = 2 + B + 8 + 8 + 9 = &H2B889
|
||||
|
||||
See the Decimal to Binary conversion function that uses **[HEX$](HEX$)** on the **[&H](&H)** page.
|
||||
|
||||
```
|
||||
|
||||
## Example(s)
|
||||
|
||||
A Decimal to Binary [STRING](STRING) function that does not return leading zeroes.
|
||||
|
||||
```vb
|
||||
|
||||
PRINT BIN$(255) '1 byte(8 bits) maximum
|
||||
PRINT BIN$(32767) 'integer(2 byte, 15 bits) maximum
|
||||
PRINT BIN$(-32768) 'integer(2 byte, 16 bits) minimum
|
||||
PRINT BIN$(-1) 'all 16 bits on
|
||||
|
||||
FUNCTION BIN$(n%)
|
||||
max% = 8 * LEN(n%) ': MSB% = 1 'uncomment for 16 (32 or 64) bit returns
|
||||
FOR i = max% - 1 TO 0 STEP -1 'read as big-endian MSB to LSB
|
||||
IF (n% AND 2 ^ i) THEN MSB% = 1: B$ = B$ + "1" ELSE IF MSB% THEN B$ = B$ + "0"
|
||||
NEXT
|
||||
IF B$ = "" THEN BIN$ = "0" ELSE BIN$ = B$ 'check for empty string
|
||||
END FUNCTION
|
||||
|
||||
```
|
||||
|
||||
<sub>Code by Ted Weissgerber</sub>
|
||||
|
||||
```text
|
||||
|
||||
11111111
|
||||
111111111111111
|
||||
1000000000000000
|
||||
1111111111111111
|
||||
|
||||
```
|
||||
|
||||
*Note:* The MSB% flag allows zeroes to be added. Uncomment the MSB% = 1 statement for returns with leading zeroes.
|
||||
|
||||
QB64 converts the binary values from the example above to [INTEGER](INTEGER) decimal values automatically.
|
||||
|
||||
```VB
|
||||
|
||||
DEFLNG A-Z
|
||||
a = &B11111111
|
||||
b = &B111111111111111
|
||||
c = &B1000000000000000 '& 'or ~%
|
||||
d = &B1111111111111111 '& 'or ~%
|
||||
|
||||
PRINT a, b, c, d '' ''
|
||||
|
||||
```
|
||||
|
||||
```text
|
||||
|
||||
255 32767 -32768 -1
|
||||
|
||||
```
|
||||
|
||||
> *Bonus example:* Add an **&** symbol after the negative binary numbers to see the [LONG](LONG) decimal values below.
|
||||
|
||||
```text
|
||||
|
||||
255 32767 32768 65535
|
||||
|
||||
```
|
||||
|
||||
> *Note:* The [LONG](LONG) values returned are the same as the values you can get using [_UNSIGNED](_UNSIGNED) [INTEGER](INTEGER) (~%).
|
||||
|
||||
## See Also
|
||||
|
||||
* [_BIT](_BIT), [_BYTE](_BYTE)
|
||||
* [_SHL](_SHL), [_SHR](_SHR)
|
||||
* [OCT$](OCT$), [&O](&O) (octal)
|
||||
* [HEX$](HEX$), [&H](&H) (hexadecimal)
|
94
wiki/&H.md
94
wiki/&H.md
|
@ -1,94 +0,0 @@
|
|||
The **&H** prefix denotes that an integer value is expressed in a Hexadecimal base 16 format. Every 2 digits represent a [_BYTE](_BYTE).
|
||||
|
||||
## Syntax
|
||||
|
||||
> a& = &HFACE
|
||||
|
||||
* The base 16 numbering system uses hexadecimal digit values of 0 to F. A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15.
|
||||
* Leading zero values can be omitted just like in decimal values as they add nothing to the return value.
|
||||
* Decimal values returned can be any **signed** [INTEGER](INTEGER), [LONG](LONG) integer, or [_INTEGER64](_INTEGER64) value so use those type of variables when converting directly as shown above in the Syntax. The program ["overflow"](ERROR-Codes) error limits are listed as:
|
||||
* [_BYTE](_BYTE): 2 hex digits or a decimal value range from -128 to 127. [_UNSIGNED](_UNSIGNED): 0 to 255.
|
||||
* [INTEGER](INTEGER): 4 hex digits or a decimal value range from -32,768 to 32,767. [_UNSIGNED](_UNSIGNED): 0 to 65535.
|
||||
* [LONG](LONG): 8 hex digits or a decimal value range from -2,147,483,648 to 2,147,483,647. [_UNSIGNED](_UNSIGNED): 0 to 4294967295.
|
||||
* [_INTEGER64](_INTEGER64): 16 hex digits or decimal values from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
|
||||
* [_UNSIGNED](_UNSIGNED) [_INTEGER64](_INTEGER64): 0 to 18446744073709551615.
|
||||
* The maximum hexadecimal value for each numerical type is the maximum number of digits listed above, each valued at F.
|
||||
* Convert hexadecimal to [[LONG]] values by appending the values with &. Example: &H8000 = -32768: &H8000& = 32768
|
||||
* [LONG](LONG) 32-bit [_RGB](_RGB) values can be made using hexadecimal values from **&HFF000000** to **&HFFFFFFFF** with full [_ALPHA](_ALPHA) only.
|
||||
* [LONG] 32-bit [_RGBA](_RGBA) values can be made using hexadecimal values from **&H00000000** to **&HFFFFFFFF** with any [_ALPHA](_ALPHA).
|
||||
* Hexadecimal **0x** is often used to prefix [HEX$](HEX$) port addresses in documentation. Replace 0x with [&H](&H) in QB64 or QBasic.
|
||||
* To convert hex strings returned from [HEX$](HEX$) with [VAL](VAL) you need to prefix the string with &H (for example; if the string is "FF" you should do VAL("&HFF") or VAL("&H" + hexvalue$).
|
||||
|
||||
## Example(s)
|
||||
|
||||
The maximum octal values of decimal value -1 in each numerical type are:
|
||||
|
||||
```vb
|
||||
c&& = -1: d& = -1: e% = -1: f%% = -1
|
||||
hx$ = HEX(f%%)
|
||||
PRINT "Max hex _BYTE = "; hx$; " with"; LEN(hx$); "digits ="; VAL("&H" + hx$)
|
||||
hx$ = HEX$(e%)
|
||||
PRINT "Max hex INTEGER = "; hx$; " with"; LEN(hx$); "digits ="; VAL("&H" + hx$)
|
||||
hx$ = HEX$(d&)
|
||||
PRINT "Max hex LONG = "; hx$; " with"; LEN(hx$); "digits ="; VAL("&H" + hx$)
|
||||
hx$ = HEX$(c&&)
|
||||
PRINT "Max hex _INTEGER64 = "; hx$; " with"; LEN(hx$); "digits ="; VAL("&H" + hx$)
|
||||
hx$ = HEX$(9223372036854775807)
|
||||
PRINT "Max _INTEGER64 value = "; hx$; " with"; LEN(hx$); "digits"
|
||||
hx$ = HEX$(-9223372036854775808)
|
||||
PRINT "Min _INTEGER64 value = "; hx$; " with"; LEN(hx$); "digits"
|
||||
|
||||
```
|
||||
|
||||
```text
|
||||
|
||||
Max hex _BYTE = FF with 2 digits = 255
|
||||
Max hex INTEGER = FFFF with 4 digits = 65535
|
||||
Max hex LONG = FFFFFFFF with 8 digits = 4294967295
|
||||
Max hex _INTEGER64 = FFFFFFFFFFFFFFFF with 16 digits =-1
|
||||
Max _INTEGER64 value = 7FFFFFFFFFFFFFFF with 16 digits
|
||||
Min _INTEGER64 value = 8000000000000000 with 16 digits
|
||||
|
||||
```
|
||||
|
||||
Converting a decimal number to a binary string value using [HEX$](HEX$).
|
||||
|
||||
```vb
|
||||
|
||||
FUNCTION BIN$ (n&)
|
||||
h$ = HEX$(n&) 'get hexadecimal string value
|
||||
FOR i = 1 TO LEN(h$) 'scan the HEX$ digits
|
||||
SELECT CASE MID$(h$, i, 1) 'read each HEX$ digit
|
||||
CASE "0": b$ = b$ + "0000"
|
||||
CASE "1": b$ = b$ + "0001"
|
||||
CASE "2": b$ = b$ + "0010"
|
||||
CASE "3": b$ = b$ + "0011"
|
||||
CASE "4": b$ = b$ + "0100"
|
||||
CASE "5": b$ = b$ + "0101"
|
||||
CASE "6": b$ = b$ + "0110"
|
||||
CASE "7": b$ = b$ + "0111"
|
||||
CASE "8": b$ = b$ + "1000"
|
||||
CASE "9": b$ = b$ + "1001"
|
||||
CASE "A": b$ = b$ + "1010"
|
||||
CASE "B": b$ = b$ + "1011"
|
||||
CASE "C": b$ = b$ + "1100"
|
||||
CASE "D": b$ = b$ + "1101"
|
||||
CASE "E": b$ = b$ + "1110"
|
||||
CASE "F": b$ = b$ + "1111"
|
||||
END SELECT
|
||||
NEXT i
|
||||
b$ = RIGHT$(b$, LEN(b$) - INSTR(b$, "1") + 1) 'eliminate leading zeroes
|
||||
IF VAL(b$) THEN BIN$ = b$ ELSE BIN$ = "0" 'return zero if n& = 0
|
||||
END FUNCTION
|
||||
|
||||
```
|
||||
|
||||
<sub>Code by CodeGuy</sub>
|
||||
|
||||
> *Explanation:* Hexadecimal digits can be any value up to 15 which also corresponds to all four bits on in binary. The function above just adds every four-bit binary string value together to return the binary value. After they are concatenated, the leading bit on is found by [INSTR](INSTR) and everything from that point is kept removing the leading zeros.
|
||||
|
||||
## See Also
|
||||
|
||||
* [HEX$](HEX$), [OCT$](OCT$)
|
||||
* [&B](&B) (binary), [&O](&O) (octal)
|
||||
* [Base Comparisons](Base-Comparisons)
|
46
wiki/&O.md
46
wiki/&O.md
|
@ -1,46 +0,0 @@
|
|||
The **&O** prefix denotes that an integer value is expressed in an Octal base 8 format.
|
||||
|
||||
## Syntax
|
||||
|
||||
> a& = &O12345671234
|
||||
|
||||
* The base eight numbering system only uses octal digit values of 0 to 7.
|
||||
* Leading zero values **can** be omitted as they add nothing to the return value.
|
||||
* Decimal values returned can be any **signed** [INTEGER](INTEGER), [LONG](LONG) integer, or [_INTEGER64](_INTEGER64) value so use those type of variables when converting directly as shown above. The program ["overflow"](ERROR-Codes) error limits are listed as:
|
||||
* [INTEGER](INTEGER): 6 octal digits or a decimal value range from -32,768 to 32,767
|
||||
* [LONG](LONG): 11 octal digits or a decimal value range from -2,147,483,648 to 2,147,483,647
|
||||
* [_INTEGER64](_INTEGER64): 22 octal digits or decimal values from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
|
||||
* [LONG](LONG) Octal values can be expressed by appending & after the number. Example: &O100000& = 32768
|
||||
|
||||
## Example(s)
|
||||
|
||||
*Example:* The maximum octal values of decimal value -1 in each numerical type are:
|
||||
|
||||
```vb
|
||||
|
||||
c&& = -1: d& = -1: e% = -1: f%% = -1
|
||||
oc$ = OCT$(f%%)
|
||||
PRINT "Max octal _BYTE = "; oc$; " with"; LEN(oc$); "digits ="; VAL("&O" + oc$)
|
||||
oc$ = OCT$(e%)
|
||||
PRINT "Max octal INTEGER = "; oc$; " with"; LEN(oc$); "digits ="; VAL("&O" + oc$)
|
||||
oc$ = OCT$(d&)
|
||||
PRINT "Max octal LONG = "; oc$; " with"; LEN(oc$); "digits ="; VAL("&O}}" + oc$)
|
||||
oc$ = OCT$(c&&)
|
||||
PRINT "Max octal _INTEGER64 = "; oc$; " with"; LEN(oc$); "digits ="; VAL("&O" + oc$)
|
||||
|
||||
```
|
||||
|
||||
```text
|
||||
|
||||
Max octal _BYTE = 377 with 3 digits = 255
|
||||
Max octal INTEGER = 177777 with 6 digits = 65535
|
||||
Max octal LONG = 37777777777 with 11 digits = 4294967295
|
||||
Max octal _INTEGER64 = 1777777777777777777777 with 22 digits =-1
|
||||
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
* [OCT$](OCT$), [HEX$](HEX$), [VAL](VAL)
|
||||
* [&B](&B) (binary), [&H](&H) (hexadecimal)
|
||||
* [Base Comparisons](Base-Comparisons)
|
18
wiki/-.md
18
wiki/-.md
|
@ -1,18 +0,0 @@
|
|||
The [-](-) mathematical operator performs subtraction on two numerical values or [negation](negation) a single value.
|
||||
|
||||
## Syntax
|
||||
|
||||
> return_value = number1 [-](-) number2
|
||||
|
||||
## Description
|
||||
|
||||
* Numbers used can be any literal or variable numerical value type.
|
||||
* Subtracting a negative value will actually perform addition with the other value.
|
||||
* Subtracting a negative or [negation](negation) value will make the return value more positive.
|
||||
* Addition and subtraction are the last operations performed in QBasic's normal order of operations.
|
||||
* Subtraction cannot be performed on [STRING](STRING) values.
|
||||
|
||||
## See Also
|
||||
|
||||
* [+](+) (addition operator)
|
||||
* [Mathematical Operations](Mathematical-Operations)
|
2
wiki/.gitignore
vendored
2
wiki/.gitignore
vendored
|
@ -1,2 +0,0 @@
|
|||
# Obsidian working folder
|
||||
.obsidian/
|
43
wiki/^.md
43
wiki/^.md
|
@ -1,43 +0,0 @@
|
|||
The [^](^) operation raises a numerical value to an exponential value expressing how many times the value is multiplied by itself.
|
||||
|
||||
## Syntax
|
||||
|
||||
> return_value = number [^](^) {whole_exponent|(fractional_exponent)}
|
||||
|
||||
## Description
|
||||
|
||||
* The number value can be any type literal or variable numerical value.
|
||||
* Exponents can be any positive or negative integer or fractional numerical value inside of parenthesis brackets.
|
||||
* If the exponent is zero, the value returned is 1.
|
||||
* Fractional(or decimal point) exponents MUST be enclosed in **() brackets** and will return the fractional exponential root of a value.
|
||||
* Exponential operations are done first in the QBasic order of operations.
|
||||
* The square root of a number can be returned by the [SQR](SQR) function or by using an exponent of (1 [/](/) 2). Brackets required.
|
||||
* Values returned may be expressed using exponential or [Scientific notation](Scientific-notation) using **E** for SINGLE or **D** for DOUBLE precision.
|
||||
* WARNING: Exponential returns may exceed numerical type limitations and create an [ERROR Codes](ERROR-Codes)!
|
||||
|
||||
## Example(s)
|
||||
|
||||
Getting the cube root of a number.
|
||||
|
||||
```vb
|
||||
|
||||
INPUT "Enter a number to calculate it's cube root: ", num$
|
||||
number! = VAL(num$) 'gets single number value
|
||||
cuberoot# = number! ^ (1 / 3)
|
||||
PRINT cuberoot# 'double type variable for accuracy
|
||||
|
||||
```
|
||||
|
||||
*Details:* The value returned will most likely be a [SINGLE](SINGLE) or [DOUBLE](DOUBLE) value. Make sure that the return variable type matches the likely program operations!
|
||||
|
||||
```text
|
||||
|
||||
Enter a number to calculate it's cube root: 144
|
||||
5.241482788417793
|
||||
|
||||
|
||||
```
|
||||
|
||||
## See Also
|
||||
|
||||
* [SQR](SQR), [Mathematical Operations](Mathematical-Operations)
|
Loading…
Reference in a new issue