SmallBASIC Intro
#1
First, thank you Walter for creating a spot for SmallBasic at The QB64 Edition and thank you figosdev for encouraging this ( we met at BP.org ).

I am a Windows 10 user and have used SmallBasic for a couple years now, it has gone through some changes haven't we all?

SmallBASIC is an interpreter only and originally targeted for handheld devices Palm OS? It was around for over 10 years before I discovered it. When I first started using the Windows version, it had a conventional IDE and was working with FLTK. It has since taken an unconventional turn with code running, editing and file maintenance that might need some help getting to know. I hope to help those with questions but I don't know technical aspects of SmallBASIC nor Linux. I am a hobbiest that enjoys graphics, games and occasional math problem and I get a big kick from how easy SmallBASIC is to get an idea in my head to working on the computer.

SmallBASIC has no type declarations for variables, that is probably the biggest difference you will notice from QB code. It has a limited set of keywords with some very powerful array handling capabilities eg split a string into array, sort, insert, delete

dim a() ' tell SB a is an array and you can start filling it with
a << insertMe

dim a(n) ' or fill a with 'map' variables, Chris the developer calls them map, I call them properties.
for i = 0 to n
  a(i).x = rnd * xmax
  a(i).y = rnd * ymax
  a(i).colr = int(rnd * 16)
next

SmallBASIC has one screen size = whatever size you open SmallBASIC window, so best to keep SmallBASIC maximized. xmax, ymax are build in constants that allow access to the screen height and width in pixels. Fonts are sizeable both for editing and screen but for screen will take some explaining.

Code is case insensitive so variables and constants xmax, Xmax, XMAX are the same as pi or PI. Line numbers are optional as are line labels if you want to use goto or gosub.

? "Hello World"  ' ? shorthand for print
pause  ' wait for keypress or mouse click otherwise screen will go back to editor

Coming from QB code experience, SmallBASIC should be easy to pickup.
B += x
Reply
#2
bplus,

First, welcome to The QB64 Edition forum.

Thank you for this nice tutorial on SmallBasic (not Microsoft's SmallBasic) as it is very informative.

Quote:I am a hobbiest that enjoys graphics, games and occasional math problem

Welcome to the club! I too am a hobbyist, and I enjoy creating graphics and games. If you look around this forum, you will see the many demos I have created in QB64 over the years and all of them provided me with some great math problems to solve. I enjoy creating graphical demos and games to the point that I was nicknamed by some in the QB64 community as the "Demo Man".

However, I have eased off a bit on creating my cool little demos as I am now trying my hand at creating my own BASIC language. At this point, I am doing it as the ultimate programming challenge I have ever faced. I can't give very many details about it at this point as I am still in the planning stages, but I should be talking about it soon. However, I can give you this, the name of my new language is CrystalBASIC and I already have the domain name purchased.

I did play around with most of the demos provided with SmallBasic and was intrigued by them. I think I may create some demo in SmallBasic over the weekend and post them here on this forum. I will say this, the only thing I have an issue with so far is realizing it isn't quick and easy to start coding in SmallBasic. Once you get to the editor, then everything is fine.


Walter Whitman
The Joyful Programmer
Dedicated to empowering computer programming hobbyists, tinkerers, amateurs, and enthusiasts.
profile for Walter Whitman at Stack Overflow, Q&A for professional and enthusiast programmers


Reply
#3
Hi Walter,

I just downloaded your QB64 fork and everything seems to be working on my laptop. Thanks for the 7z link and all your efforts for keeping BASIC alive and moving forward.

My QB is very rusty, and I am a little confused where to post questions for help. Mainly I want to be able to translate QB64 code to SmallBASIC from that possibly to SdlBasic and/or Just Basic and vice versa, translate SmallBASIC to QB64, since it at least can be compiled and maybe run faster?? It does with Free Basic.

Anyway, I am wondering if you or anyone else would like to help work up cheat sheets for translating dialects between SmallBASIC and QB64. It would help me get up to speed with QB64 and I think others might like how fast you can edit and test run code in SmallBASIC.

Anyway, the number one concern on my list is all the Types for variables, are there still suffixes like %, !, !!, $ and #? Is it best to declare everything ahead? Well I can pick this up from help, unless someone has a cheat sheet ready or advice...

For SmallBASIC the $ is optional for strings and is basically treated like another letter, so string functions: mid, left and right are without $ suffix. I confess I don't miss variable typing for numbers but the $ for strings still used in JB is very OK.

Here are some handy screen console keywords:
pause or pause nSecs  'wait for keypress, click or nSecs whatever comes first
delay ms                       'wait in millisecs
showpage                     'updates screen with all graphics changes since last update
                                      'use showpage once and you will to use it to show any new change
color fore, back             'fore and back can be QB 0-15 or RGB(red, green, blue)
color fore                      'color options also available in primitive graphics like circle, rectangle, pset

Walter, you mentioned troubles getting SB going. I have bas files registered with Windows, SmallBASIC to be called when I click a .bas file, that way Windows is my file manager not SmallBASIC. I have made a shortcut to SB and pinned it to my toolbar but I never use that unless I need to reset editor font or reset the editor (versus running) a file when I click it. I do all my SB work on the desktop and have New bas file.bas, Save As bas file.bas see screen shot

Big Tip, Here is where your SmallBASIC settings file is located:

C:\Users\Mark\AppData\Roaming\SmallBASIC

Substitute your user name for where "Mark" is.
Windows 10 hides the darn thing. I keep a short cut in my SB folder to this folder because Windows does not show access to this folder from File Explorer without explicitly typing the whole thing out.

If your SmallBASIC is working fine get a copy of Settings file because sometimes SB gets stuck in a minimized Window. You can get unstuck by deleting the settings file but then you loose other settings like all your color codes for editor. (There are several to toggle through or set your own.)

In screenshot, along with New file, Save As... there is Quick test for copy/paste and then Save AS...
Tab2space to remove ? in tiny squares that represent tabs.
Also seen is Eval calc for BASIC calculator, like an immediate window
Full factor.bas for factoring numbers
Handy.bas most reused subs and functions to copy/paste from

Another tip: from editor you can glance back to the last output screen from the right mouse click popup menu, very handy for adjusting text...


Attached Files Thumbnail(s)

B += x
Reply
#4
One more very important tip:

ctrl+h   for help screen in right window of editor
fn+f1   for keyword help (by category) in right window of editor

!!! Now to get back to editing in editor, you must press esc (or enter) and disappear the right window.
Otherwise, you could type edits all day and nothing will happen except you will think SmallBASIC is broken.

You also must press esc when RUNning code and an error is encountered. You will be returned to the editor and the right window will contain an error message. Your instinct will be to start typing a correction to the error but nothing will happen until that right window is cleared.
B += x
Reply
#5
Quite right, figosdev, dynamic typing kind of spoils one away from the discipline of typing.

But, I am reminded of one application when typing was really handy, random access files. When you even fixed the length of strings and needed precision control over every byte of a record. In data processing, I imagine that saves huge amounts of time and if a clever coder, you could save huge amounts of memory space as well.

Don't look for random access files with SmallBASIC one of the few things not picked up from classic QB.
B += x
Reply
#6
FigOsDev,

I know how you feel about JavaScript, but for me personally, I absolutely love the language. Sure there are things that could of been done better with JavaScript, but that could be said with all languages.

But we all have the right to like and dislike anything and everything, because that is what real freedom is all about!


Walter Whitman
The Joyful Programmer
Dedicated to empowering computer programming hobbyists, tinkerers, amateurs, and enthusiasts.
profile for Walter Whitman at Stack Overflow, Q&A for professional and enthusiast programmers


Reply
#7
Yes, JS seems very popular with people with BASIC experience, that and Python, maybe even more popular than Windows.  ;-))

figosdev, you are right about type for random access.
I wouldn't say 100 years old but at least 22 years. It's been that long since I did anything with custom databases with random access (VB for MSDOS, anyone remember that?). At that time, the advantage was accessing a record without loading the whole file into memory and not having to wade through the file until you get the record you want. But variable length records tend to use way less space and that in itself causes a speed improvement. SmallBASIC does have tools to parse a variable length record but not sure you wouldn't have to load the whole file into memory to access records "randomly". Surely there is a way with Binary access, file formats and/or headers... honestly I was just trying to gird my loins for the task of (re)learning QB code and trying to find a bright spot in my past experience for doing the type thing again.

I was going through the QB Help for type update and couldn't help feeling that this task I set for myself feels like a real chore.

QB64 does have alpha coloring so that might help make it worth the effort.
B += x
Reply
#8
Hi caffey,

Welcome to the forum!
B += x
Reply