Skip to content

Commit 0b1e0b3

Browse files
committed
SAMPLES: initial commit
1 parent 81fc54e commit 0b1e0b3

File tree

420 files changed

+46454
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

420 files changed

+46454
-0
lines changed

000 getting started/000 hello.bas

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
2+
'000 hello.bas SmallBASIC 0.12.6 [B+=MGA] 2016-06-08
3+
'For Code library section: 000 Getting Started
4+
?
5+
? "Getting Started: Hello World example"
6+
?
7+
? "0. From sbasicg.exe main 'Navigator' window"
8+
? " (the first screen you see when running sbasicg.exe)"
9+
?
10+
? "Make sure you are in the directory/folder you want."
11+
? " Sub-directories or folders, under the current one you"
12+
? " are in, are enclosed with square brackets"
13+
? " [I_am_a Folder]"
14+
? " Only .bas files will show under the folders listing."
15+
?
16+
? "You may need to 'go up' in the directory tree,"
17+
? " use [Go up] folder listed first under the current"
18+
? " directory you are in according to the Navigator"
19+
? " current directory listing."
20+
?
21+
? "To start a new file called Hello.bas:
22+
? "1. Click/tap menu File and get into File screen."
23+
?
24+
? "2. Clear first line (backspace) then type Hello"
25+
? " and click New, Hello.bas should appear in files listing."
26+
? " (You have just created a new file called Hello.bas"
27+
? " but you have to go back to Navigator window to edit it.)"
28+
?
29+
? "3. Click << to get back to main Navigator window"
30+
? " where Hello.bas should now also appear."
31+
?
32+
? "click to continue......." : pause : cls
33+
?
34+
? "4. Make sure the Editor is toggled on, Editor On mode."
35+
?
36+
? "!!! Right click mouse or tap 3 vertical bars (Android)"
37+
? "!!! to access the popup menu that gives access to vital"
38+
? "!!! functions. Call this GET POPUP."
39+
?
40+
? "You may have to toggle a couple of times"
41+
? " there are 3 modes from GET POPUP:"
42+
? " Editor [Off] run only mode, Editor [On], Editor [Live]"
43+
? " keep toggling (clicking or tapping that line)"
44+
? " until you see Editor [On]"
45+
?
46+
? "Now click on Hello.bas from Navigator window,"
47+
? " you should see two REM comments in editor"
48+
? " with new Hello.bas file loaded:"
49+
?
50+
? "5. under the two REM comments type:"
51+
? "print \"Hello world\""
52+
? "pause"
53+
?
54+
? "6. GET POPUP, select RUN"
55+
?
56+
? "7. see Hello world in output screen, yeah!"
57+
? "8. GET POPUP, select back"
58+
? "9. should be back to editor"
59+
? "10. GET POPUP and select back again to exit SmallBASIC"
60+
?
61+
? "click to continue......." : pause : cls
62+
?
63+
? "Comments about Hello.bas:"
64+
? " The PRINT keyword is so often used in SmallBASIC"
65+
? " it has a shortcut ? So we could also write:"
66+
? "? \"Hello World\""
67+
? " and get the same result in output window."
68+
?
69+
? "PAUSE is used to hold the output screen until a"
70+
? " click or keypress, without it you will only see"
71+
? " a flash and then be back in edit window."
72+
?
73+
? "There is an option in GET POPUP to show the Output"
74+
? " screen. Click/tap that and see the Output screen"
75+
? " anytime while you are editing. It comes in handy to"
76+
? " refer to that while tweaking your program."
77+
?
78+
? "A comment about comments:"
79+
? " REM or # can start a whole line comment at the left"
80+
? " most position in a line. But only ' the apostrophe"
81+
? " can be used to the right side of code on a line."
82+
?
83+
? "click to continue......." : pause : cls
84+
?
85+
? "HELP!"
86+
? " F1 will access keyword category help in the right"
87+
? " column of screen. From there you can access keywords."
88+
? " To exit back to the main editor, use esc."
89+
?
90+
? " Ctrl+h will give a listing of keyboard shortcuts"
91+
? " in the right column of screen. To exit that, press"
92+
? " esc and get focus back into editor."
93+
?
94+
? " When you run code and get an error message, press esc"
95+
? " to get the focus back into the editor, otherwise all"
96+
? " typing in the editor will be for naught!"
97+
?
98+
? " You are also invited to participate in the forum at
99+
? " http://smallbasic.sourceforge.net/"
100+
?
101+
? " OK, I hope this helps,
102+
? " B+=MGA"
103+
pause
104+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
REM 3 ways to print hello five time.bas 2016-03-05 SmallBASIC 0.12.2 [B+=MGA]
3+
'modified for 001 Getting Started
4+
5+
REM remember ? is the same as PRINT, each ? is a print statement
6+
? "!!! Right click mouse or tap 3 vertical bars (Android)"
7+
? "!!! to access the popup menu that gives access to vital"
8+
? "!!! functions. Call this GET POPUP."
9+
?
10+
? "GET POPUP now and select View Source to see the code for this!"
11+
?
12+
? "Three Ways to PRINT hello Five Times:"
13+
?
14+
? "It's all in the punctuation at the end of a print statement."
15+
?
16+
? "1) no punctiation at the end of a print statement"
17+
?
18+
print "hello"
19+
print "hello"
20+
print "hello"
21+
print "hello"
22+
print "hello"
23+
?
24+
? "Each hello takes a whole line."
25+
?:? '2 blank lines, the colon : separates statements
26+
27+
? "2) a comma which tabs to next avaiable tab column"
28+
? " and will stay on same line until run out of columns"
29+
?
30+
print "hello",
31+
print "hello",
32+
print "hello",
33+
print "hello",
34+
print "hello",
35+
? "& this will finish the hello, line."
36+
?:? 'print two are blank lines a : colon separates statements
37+
38+
? "3) a semicolon (and space after hello)
39+
?
40+
print "hello ";
41+
print "hello ";
42+
print "hello ";
43+
print "hello ";
44+
print "hello ";
45+
'notice I put a space after hello otherwise > hellohellohellohellohello
46+
? "... this line needs to be finsihed."
47+
48+
pause 'now we do need the pause! to see the screen before returning to editor
49+
50+
# note for those not reading this from On-Line samples
51+
# comment out the PAUSE above, and the output screen will flash and return here
52+
# GET POPUP and select Show Output and you can veiw it from editor
53+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
2+
'002 Numeric variables.bas SmallBASIC 0.12.6 [B+=MGA] 2016-06-08
3+
4+
? "!!! Right click mouse or tap 3 vertical bars (Android)"
5+
? "!!! to access the popup menu that gives access to vital"
6+
? "!!! functions. Call this GET POPUP."
7+
?
8+
? "GET POPUP now and select View Source to see this code!"
9+
?
10+
? "Numeric variables:"
11+
?
12+
? "Variables are containers. The variable/container has a"
13+
? "name and the variable's value is the contents found under"
14+
? "the name. They are called variables because the contents,"
15+
? "the values, are or can be switched."
16+
?
17+
? "With SmallBASIC the name must start with a letter or _ "
18+
? "and may be followed by more letters, _ or digits."
19+
?
20+
? "In SmallBASIC letters are not case sensitive so:"
21+
? "MyVariable = myvariable = MYVARIABLE = MYvariable"
22+
? "just spell them the same (no spaces)."
23+
?
24+
? "... press any to continue" : pause : cls
25+
26+
' Here are Two typical variable assignments,
27+
' loading a value into a named variable
28+
a = 5.05 '<== you can assign a number directly
29+
30+
' or you can assign values from numeric expressions
31+
b_1 = 2 * 2 * a / 1.01 '<== should be 20
32+
33+
? "Here are two typical variable assignments just made:
34+
?
35+
? "Name:", "Value:",, "Name:", "Value:"
36+
? "a ", A,, "b_1 ", B_1
37+
?
38+
? "Here is look at arithmatic operators +, -,"
39+
? "* multiplication, / division."
40+
? "a + b_1 = ";A + b_1;" a - b_1 = ";A - B_1
41+
? "a * b_1 = ";a * b_1;" a / b_1 = ";a / b_1
42+
?
43+
? "For Powers use ^:"
44+
? "a squared is a ^ 2 = ";a^2
45+
? "b_1 cubed is b_1 ^ 3 = ";b_1^3
46+
? "The square root of a number n is n ^ .5 or n ^ (1/2)"
47+
? "The cubed root of a number n is n ^ (1/3)"
48+
? "So square root of a is a ^ .5 = ";a ^ .5
49+
? "and cube root of b_1 is b_1 ^ (1/3) = ";b_1 ^ (1/3)
50+
?
51+
? "Integer division uses \ the slash that goes the other way."
52+
? "With Integer division the fractional part is just dropped."
53+
? "7 / 2 = ";7/2;" but 7 \ 2 = "; 7 \ 2
54+
? "7 / 8 = ";7/8;" but 7 \ 8 = "; 7 \ 8
55+
?
56+
? "Modulus returns the remainder, 5/3 has a remainder = 2"
57+
? "so 5 MOD 3 = 2 (or 5 % 3 = 2)."
58+
? "MOD or % work with integers (no decimal in number)."
59+
? "2 hours past 12 o'clock is 2 o'clock but what is"
60+
? "49 hours past 12 o'clock ?"
61+
? "It is 49 mod 12 or "; 49 mod 12;" o clock"
62+
?
63+
? "... press any to continue" : pause : cls
64+
65+
'123456789012345678901234567890123456789012345678901234567890
66+
? "Now that we have some variables and numeric operators,"
67+
? "Let's try input of a radius and calculation of a circle's"
68+
? "Area = pi * radius ^ 2
69+
?
70+
? "pi is a built in constant in SmallBASIC = ";pi
71+
?
72+
? "Next we will see INPUT keyword assigning the variable
73+
? "radius with a number you enter after a prompt enclosed"
74+
? "with double quotes:"
75+
?
76+
' The INPUT statement structure or syntax:
77+
' INPUT "prompt"; inputVARIABLE
78+
' the V's are pointing to parts
79+
' V key word V "prompt" semi-colon V Variable
80+
input "So please enter a radius now > "; radius
81+
? "We have assigned the value ";radius;" to radius,"
82+
? "using an INPUT statement, a second way to assign"
83+
? "values to variables. Normally we would check INPUT"
84+
? "values but we haven't discussed IF THEN structure."
85+
?
86+
area = pi * radius ^ 2
87+
? "A circle with radius ";radius;" has an area of ";area
88+
89+
?
90+
? "... press any to continue" : pause : cls
91+
92+
? "OK now is a good time to discuss the order operators"
93+
? "are handled, since it does not go from left to right."
94+
? "The main thing to remember is that + and - are done"
95+
? "last, next to last are * and / (mult. and divide) so:
96+
? "7 - 3 * 5 won't be 4 * 5 == 20 but 7 - 15 == -8."
97+
? " (I will start using == to mean equals)"
98+
? "When in doubt use () as the operations inside are"
99+
? "handled first: (7 - 3) * 5 == 4 * 5 == 20
100+
?
101+
? "Remember the quadratic equation?
102+
?
103+
? "Here is a case where getting the math order correct"
104+
? "is vital specially when expressing the two x values"
105+
? "possible directly from the A, B, C constants for the"
106+
? "equations:"
107+
?
108+
? "For x^2 + 2*x - 3 = 0
109+
? "if A = 1, B = 2, C = -3"
110+
? "then x = (-B + ( B^2 - 4*A*C)^.5 )/(2*A)"
111+
? " and x = (-B - ( B^2 - 4*A*C)^.5 )/(2*A)"
112+
rem do that in code:
113+
rem Next line is 3 variable assignments on one line,
114+
A = 1 : B = 2 : C = -3
115+
' a colon : separates statements in Basic
116+
? "x = ";(-B + (B^2 - 4*A*C)^.5)/(2*A);
117+
? " and x = ";(-B - (B^2 - 4*A*C)^.5)/(2*A)
118+
?
119+
? "and for x^2 - 99.1*x - 202.2 = 0
120+
? "let A = 1, B = -99.1, C = -202.2
121+
A = 1 : B = -99.1 : C = -202.2
122+
? "x = ";(-B + (B^2 - 4*A*C)^.5)/(2*A);
123+
?" and x = ";(-B - (B^2 - 4*A*C)^.5)/(2*A)
124+
?
125+
? "BASIC makes formula or equation handling easy!"
126+
?
127+
pause

0 commit comments

Comments
 (0)