oh Cheat Sheet | Help | Manual | Document
Update for v 2021-06-15 String Math update
oh cheat sheet(s) txt file, b+ rev 2021-06-15 String Math Update
*** oh = One Handed Interpreter ***
Create your oh program in your favorite Word Processor, I am using Notepad++.
Drag and drop the file onto the compiled oh.exe to run it (old way).
oh Menu:
oh now displays the contents of a program on a scroller if get one off Command$.
All files selected from Load with be displayed on scroller with Menu on top line:
(in yellow and red) New, Edit, Load, Run, Quit ; click or press first letter of
menu item to select it. Edit or New should load up the file in your default .Txt
Editor from a Shell call.
Commands, variables, line labels are case insensitive.
Re: Comments
' at start of a line, formally tells oh to ignore the line, it's a comment.
You can probably write comments in at your own risk without the '
as long as they don't start with a command word or symbol or have = sign
after first word.
Re: oh color settings, in case you need to get back to them:
Ink 100;180;225
Paper 0;0;39
*** Preloaded Variables and their Values:
"MouseX" ' use the poll command to update x pix see demo ao 3/14
"MouseY" ' use the poll command to update y pix
"MouseL" ' use the poll command to update Left button down = -1 or 0
"MouseR" ' use the poll command to update Right button status
"Key" ' use the poll command to update Last non empty key pressed, not sure about this one
"MT" = "" ' constant, handy name for nut'n which you can compare to inps (Input String)
"XMAX" = "1024" screen pixel width, constant
"YMAX" = "672" screen pixel height, constant
"RMAX" = "42" screen print rows, constant
"CMAX" = "128" screen print columns, constant
"NL" = Chr$(13) + Chr$(10) for .txt file delimiter
(note: I say constant but these are variable not wise to change them though.)
*** Print commands which use ; to delimit variables inside text
. normal print and carriage return line feed use / one space after . or after ; to set spaces
; print and next print position is right where it is, dont forget to finish line with a . line
, tab built in columns
tab columnWidth;item;item;item;...
cpr row;textgoes here with plug-in variables ';here; and ;here;.
Center Print Row print a line of text.
clipout args1 - replace Clipboard contents from any variable or literal
clipadd args1 - Append tp Clipboard contents any variable or literal,
the command does the first NL$ = Chr$(13) + Chr$(10),
you must do manually any inside the stuff you are appending, if needed.
*** Input commands also ; to delimit prompt and variable
inps this is a sample prompt;var s on end signals string expected and will return mt for just enter keypress
inpn this is a sample number prompt;var n on end will turn an empty string entered to 0
*** Screen stuff now semi-colon delimited arguments to allow each argument to be evaluated:
loc row;col AKA Locate for print chars 8x16
at col;row Alternate that corresponds to graphics x, y but in char cells 8x16
tag pixX;pixY;text$ AKA _PrintString
cpr row;text Center Print atRow;text with variables;embedded;I think.
*** Screen Drawing now semi-colon delimited arguments to allow each argument to be evaluated:
ink r;g;b;a fore-color for printing or drawing
paper r;g;b;a back-color usually set at start
pix x;y AKA Pset(x, y)
line x1;y1;x2;y2 AKA Line(x1, y1)-(x2, y2)
box x1;y1;w;h AKA Line(x1, y1)-Step(x2, y2), ,B
fbox x1;y1;w;h AKA Line(x1, y1)-Step(x2, y2), ,BF
circ x1;y1;r AKA Circle (x1, y1), r
fcirc x1;y1;rr AKA For r = 0 To rr Step .25 : Circle (x, y), r : Next
ftri x1;y1;x2;y2;x3;y3 Special MapTriangle command for
*** Misc:
poll Updates preset mouse and key variables
cls AKA Cls
zzz AKA Sleep
beep AKA Beep this comes in handy for debugging
wait nSecs AKA _Delay
show TF AKA _Display, AutoDisplay Boolean: True = stops blinking, False = immediate draw/print
mouse TF Mouse Hide if False = 0, Show Mouse if True <> 0
set Astring;index;itemValue compare to A(i) = itemValue
also see var = get[astring,index] SFunction below
rndPt (arg = variableContainer) gets the next rndPt from a deck of all points on screen,
this helps distribute graphics "randomly" on screen, covers every point
then deck is reshuffled for next layer
rp = rndPt
x = rp mod xmax or as we like to say at oh, m[rp,xmax]
y = int(rp/ymax) or as we like to say at oh, int[d[rp,ymax]]
*** Boolean IF blocks
if BooleanExpression
ei BooleanExpression AKA ElseIf
el AKA Else
fi AKA End If
*** Loop structure only one unless count goto
[ - starts loop
] - ends loop
*** only ways out of loops are:
jmp BooleanExpression Jump! out of the current loop level the command is in.
exit usually from inner if block, exits current loop level
end stop run
goto labelName:
*** GoSub
gs labelName\ AKA GoSub (3/21 : changed to \ as line label marker)
rtn AKA Return
labelName\ for gs and goto (3/21 : changed to \ as line label marker)
*** File simplicity:
Save Astring;toFileName - command
AstringVar = load[fileName] - SFunction
files[] - AString list of the files in the current directory
*** SFunctions Syntax:
var = SFunction[a1, a2, a3,...] variables setting or reassigning
*** Booleans:
and[a1, a2, a3,... ] only returns -1 when all are <> 0
or[a1, a2, a3,... ] returns -1 if any one is <> 0
seq[a1, a2] does a string compare a1 = a2? -1 if true, 0 if not
eq[a1, a2] does a numeric compare a1 = a2? -1 if true, 0 if not
lt[a1, a2] less than a1<a2 -1 if true, 0 if not
lte[a1, a2] less than or equal a1<=a2 -1 if true, 0 if not
gt[a1, a2] greater than a1>a2 -1 if true, 0 if not
gte[a1, a2] greater than or equal a1>=a2 -1 if true, 0 if not
noteq[a1, a2] not equal a1<>a2 -1 if true, 0 if not
not[a1] if a1 = 0 then Not returns -1 else Not returns 0
*** Arithmetics:
a[a1, a2, a3,...] adds them all, a is for add
x[a1, a2, a3,...] multiplies all, x is for mult.
s[a1, a2] a1 - a2 s is for subtract
d[a1, a2] a1 / a2 if a2 <> 0 d is for divide
m[a1, a2] a1 mod a2 m is for mod AKA the remainder
p[a1, a2] a1 ^ a2 p is for power
*** Extended Arithmetics extended math so extended the names ;-))
add[a1,a2]
subtract[a1,a2] - should this be subtract or subtr? I don't like sub
mult[a1,a2] - I am sure this is OK for multiply
divide[a1,a2] - handles approx 100 decimal places (got to set a limit or it'd go on forever!),
the 3 binary's above are arbitrary.
inverse[PosInteger,NumberOfDecimals] - for custom designed division when 100 decimals wont do.
sqrroot[a1] - working independently from Mr$ Function like inverse.
(The extended math had 14 Routines, MR$ is controller of the Big 4 and stands for Math Regulator.)
*** Maths misc:
int[a1] converts to Integer, remove floating point decimal end if any
sqr[a1] returns square root if a1 is positive or 0
log[a1] QB64's Log, natural logarithm, see wiki Log to convert to Log(base 10)
exp[a1] QB64's Exp, Exp(1) = e
rnd[a1] a1 is multiplier of Rnd (0 to almost 1) * a1
abs[a1] Absolute value of a1
*** Trigs (Radian angle units)
sin[a1] a1 angle in radians, returns unique ratio
cos[a1] a1 angle in radians, returns unique ratio
tan[a1] a1 angle in radians, returns unique ratio
asin[a1] a1 is ratio, returns angle in radian units
acos[a1] a1 is ratio, returns angle in radian units
atan[a1] a1 is ratio, returns angle in radian units
rad[a1] a1 is usually an angle in degrees needing to be changed to radian units
deg[a1] a1 is usually an angle in radians needing to be converted to degree units
pi[a1] a1 is a multiplier or fraction of Pi
atan2[a1 (=deltaY's) , a2 (=deltaX's) ] SFunction with 2 args, definitely a plus!
note: delta usu. means difference
Find the angle of point 1 (x1,y1) from point 2 (x2, y2) )
Basic: var = _atan2(y1-y2,x1-x2) or oh: var = atan2[s[y1,y2],s[x1,x2]]
( You can figure the rest of the Trig Functions from these. )
*** String functions:
bnd[a1, a2, a3,...] bind, bond, bound this concatenates a1, a2, a3,...
join[delimiter$, a2, a3,...] like the above but links the with delimiter,
for comma or space separated items or Chr$(10) line separators
Allot of string functions have counterparts joins counterpart is:
split[a1, a2] a1 is string to split, a2 is the delimiter, splits usually go into arrays
for oh we are using Astrings, strings that can be indexed to retrieve items using the "get" function.
Another way to build giant strings from building block is:
cop[a1, a2] better than String$ command because it makes a1 concatenated copies of string a2
rejoin[a1, a2] will take the special Astring, a1, formed from split or cop maybe bnd and split
and rejoin using the the delimiters given as a2. Say you have processed an Astring of data and
wish to save it in a file as comma separated or as line by line.
*** String slices:
mid1[a1, a2] AKA Mid$(a1, a2, 1) a 1 char return in a1 at a2
mid2[a1, a2] AKA standard Mid$(a1, a2) 2 argument return remainder of a1 starting at a2
mid3[a1, a2, a3] AKA standard 3 argument MID$
left[a1, num of chars] AKA Left$
right[a1, num of chars] AKA Right$
head[a1, a2] from a1 find a2 and take the part that comes before a2
tail[a1, a2] from a1 find a2 (end) and take the remainder of string from there.
*** String finds:
in2[a1, a2] position of first a2 found in a1
in3[a1, a2, a3] starting at a1, find and return a3 position in a2
*** Chars:
asc[a1] returns ascii value of char, space = 32, enter = 13, tab = 9, dbl quote = 34, hyphen = 45
chr[a1] returns char of ascii number chr(65) = A, chr(48) = 0
*** Trimming spaces:
rtr[a1] removes spaces from right
ltr[a1] removes spaces from left
trim[a1] removes spaces left and right
*** Shouting, whispering, modifying:
cap[a1] a1 in all capitals
low[a1] a1 all lower case
replace[source$,replace$,new$] - replaces a string with new$ wherever found in source$
*** Astrings: like arrays, these are strings you can "get" an item value by index #
Set Astring;index;itemToAddOrReassign - this is a command as opposed to an SFunction
so sets counterpart is get:
get[a1, a2] from Astring, a1, get the item at index, a2. Compare to var = A(i), var = get[astring, index]
nItems[Astring] number of Items in the Astring (counts delimiters and adds 1)
*** Now for some easy string functions:
len[a1] returns the length in chars of a1
spc[a1] returns a1 block of spaces
date[] no argument Date$
time[] no argument Time$
clip[] no argument get contents of _ClipBoard
timer[] no argument still need [] this the number of secs since midnight, 3 decimals at least.
*** Special Order String Functions:
ASSORT[a1] ascending string sort of astring, a1
DSSORT[a1] descending string sort of astring, a1
ANSORT[a1] ascending numeric sort of astring, a1
DNSORT[a1] descending numeric sort of astring, a1
Fval[a1] will attempt to evaluate a string or numeric expression of functions and literals.
*** File simplicity:
Save Astring;toFileName
AstringVar = load[fileName]
files[] - AString list of the files in the current directory
Change Log: ==============================================================================================
*** 2021-03-09 The "Screen" commands are now ; delimited to allow each argument to be evaluated.
Commands effected: loc at tag ink pix line box fbox circ fcirc ftri wait show paper
All demos effected have been updated.
New command: cpr for centering print on a row: cpr row;my text is this with a variable ;here; to plug in.
See: Test ac Fval$ Tester.txt, demo as this has been completely rewritten for cpr and first
test of using Fval$ to check arguments to commands.
A Splash screen for Oh?
*** 2021-03-10 Added 300 plus lines for File Dialog & Company including a very nice array displayer for showing the
loaded programs, maybe I could do a help? No that is better in tabbed Notepad++
Internal Splash is gone and the other internal test programs, net effect 1300 LOC including the start
of oh's menu system
direntry.h has been added to the zip package, please copy | paste into your QB64 folder for cross platform
directory and files access if you dont have a copy there already. This allows the File Dialog part of oh to
work correctly.
*** 2021-03-14
Dumped checking the _ClipBoard for a program now with File Dialog and all.
Tidied up oh's menu a tiny bit.
Check cpr handling of embedded variables and or SF[]'s, OK that is fixed up but not sure I want to
do that for the other print commands? Oh yes!!! I do want that! (Done)
Note: it you call edit without a file name you will wind up on the command line, just type exit.
Add Command:
Save Astring;Filename
Reminder: Astring is my term for a string with indexed variable length string items.
Save will store each item as a line in given filename.
Add SFunction:
Astring = Load[filename]
So that you can load a file into an Astring for indexed access to lines.
Consolidate Set and RndPt (even though RndPt takes no arguments it assigns a var)
commands with all the other ; delimited commands that do calculations. So now,
you don't have to have middleman variables in the commands, you can calc directly
in the command.
Add preloaded Mouse variables:
MouseX, MouseY, MouseL, MouseR
Locate (x, y) mouse in pix and Boolean Left or Right Button Down
Add preloaded variable:
Key
For keypress detection.
New Poll command to update all those preloaded variables with mouse and Key status.
Left$ and Right$ var = Right[a1$, val(a2$)
Ubound of Astring amount = nItems[AString]
*** 2021-03-16
Added: string math for extended arithmetics in SFunctions
add[a1,a2]
subtract[a1,a2]
mult[a1,a2]
divide[a1,a2]
(Divide: numerator/denominator, is calc'd by multiplying numerator by inverse of denominator).
(So the inverse is calculated to 100 Decimal Places, but sometimes 100 decimal places wont do
so inverse[posInteger,NumberOfDecimals] is added to do custom "division" by controlling the
decimals in inverse and to be then multiplied by numerator in a hand made division calculation.)
Added command:
clipout a1 + whatever argument 1 is holding: literal, variable value substitution
or expression of SFunctions replaces contents of Clipboard
Added command:
clipadd a1 appends to, instead of replaces, Clipboard data.
Added SFunction clip[] no argument SFunction, you still need the brackets.
This puts the contents of the contents of the Clipboard into the spec'd var.
eg var = clip[]
*** 2021-03-17
Basically just a few fixes and tweaks to get Donut.txt to work. Fixed the file line count
with a different load of a file. Fixed bug from reading the Len[] of a file, thrown off by
the file containing []'s!!! So a new SafeBS$ Function filter/converter created that
converts [] to {}. Needed to fix the Ink, Paper and color restoring after Run.
*** 2021-03-19
For Mouse Action Shooter - Target Practice (Graphics Game #2 attempt)
3/18 added mouse TF - command with 1 argument. True to Show Mouse, False to Hide Mouse
3/18 added abs[arg1] - SFunction with 1 argument. Kind of surprised how much I use ABS.
3/18 added timer[] - SFunction no argument, still need brackets.
3/18 added atan2[a1 (=deltaY's) , a2 (=deltaX's) ] SFunction with 2 args, definitely a plus!
Find the angle of point 1 (x1,y1) from point 2 (x2, y2)
Basic: var = _atan2(y1-y2,x1-x2) or oh: var = atan2[s[y1,y2],s[x1,x2]]
3/19 added beep (command) no args, main reason: to help debug.
*** 2021-03-22
3/20 added inverse[PosInteger,NumberOfDecimals] for custom division or control of decimals.
This is = 1/PosNumber to a set amount of decimals.
3/21 added files[] - no argument SFunction that loads the files of current directory into an AString.
3/21 added replace[stringSource,stringToReplace,StringToRplaceWith] - 3 arguments SFunction.
3/21 fix? load[] renders [ brackets impotent by swapping them with { brackets
save Astring;FileName sort of needs to reverse that by replacing { back to [
This is messy, in future something else may be a better solution.
3/21 Line labels now end with \ instead of colon. This is to be consistent to oh rule, no shifts.
3/21 Added another preloaded variable nl (Next Line) for file line delimiter.
Vnames$(11) = "NL": Vvalues$(10) = Chr$(13) + Chr$(10)
3/21 Gutted out opening code and rewrote the code to display files on a scroller when have a
filename and existing file. Now the menu runs across top line in yellow and red and can
click menu item or key press first letter for New, Edit, Load, Run, or Quit.
Much better if I do say so myself :) This completes my goals for this revision.
*** 2021-03-27
3/23 Fix file display scroller to accept PgUp, PgDn, Home, End Keypresses.
Also run file lines through filter JIT to replace tabs with 4 spaces and other
chars < 32 with *. This enables the display of 39 lines on 39 lines without screen
scrolling and menu line lost.
3/23 NL fixed and working as expected in: Test oh replace and nl.txt file.
3/23 Adding SHARED Lists: CmdList$ and FunList$ for Function OK$ a line Syntax checker function
that will return nothing (OK) if the line is fine, or what it found wrong with proposed
program line. Inventory: 40 commands (fix 4 more), 74 SFunctions
3/26 Added 3 more procedures for Syntax checking and immediately learned I missed 4 commands in
command list. The only line it caught after that was an title line without a formal comment.
I started editing Particle Fountain (it is hopelessly S L O W) and the syntax checker caught
a missing argument in an Or line when I mistakenly typed a } instead of a regular ] bracket.
Good, it catches at least something. So now lines start with comments, commands, variables
or line labels\ (\ ends a line label now).
3/27 Fixed - Mouse Action Shooter - the first bullet fired was always nothing?? and yet 10 points
is deducted from the score as it should be. Show me the bullet! I just initialized all the
bullets properties instead of only the bLive AStrings (arrays).
3/27 Fixed. After editing a file, you have to change directory and change back to get the new
file loaded with the changes. I now do that automatically in code after an Edit.
*** 2021-03-27A
3/27A Syntax checking had a little sloppy handling of closing ] assuming it was at end of line
instead of checking if one was actually there to match opening [. I found 4
working programs that were missing a final bracket at the end. I also found a program
that used [] instead of parenthesis and it was flagged for unknown SFunction. So that part
of syntax checking is also fixed, you will be flagged for unrecognized functions.
So I went through all working programs and they now fly through syntax checking right into
a successful run.
*** 2021-06-03 fix divide$
6/03 Fix the divide$ Function so that, Test oh High Precision Square Root.txt, file program works.
Also found the clipout and clipadd help in, oh Cheat Sheet.txt in error and fixed (no square
brackets to enclose the argument).
*** 2021-06-15 String Math update
6/15 A number of fixes and improvements to the String Math package including new sqrroot[number]
Function. Unfortunately with the new fixes the inverse of STx number takes a bit longer than
it did, it's a wonder it was getting correct results originally. When testing all the
programs I noticed the nl "constant" I had forgotten all about. This is doing double spaced
lines because it is Chr$(13)+Chr$(10) probably should be one or other, not both together.
Since last update we created new programs:
Aurels Henon code, Bresenham Circle Fill, First 100 digit Fibonacci, Sqr Root estimating.
A version of the last program became part of the String Math package update!