Showing posts with label BASIC. Show all posts
Showing posts with label BASIC. Show all posts

Wednesday, June 28, 2017


--- Structuring programs ---

2016

My big project is a software package programmed into Calc, the LibreOffice spreadsheet component. The strength of this approach is that the statistics package already has all the utilities of a powerful spreadsheet. I call it DANSYS - the Data ANalysis System.

I'll be using DANSYS to talk about how to program in LibreOffice Basic. The manual, available at the LibreOffice website, is useful but there's a lot it doesn't explain how to do, and I've picked up a lot of tricks and workarounds over time. I'm working on an expanded version of DANSYS and I'll take you along on the journey.

I had to decide whether I wanted to just keep expanding DANSYS or make two versions: a basic version that does the most common statistical procedures and the expanded version that's much bigger and clunkier but will do many, many more cool things. I decided to go with the two version plan and both will be available on my other website (http://www.theriantimeline.com/excursions/labbooks) as I develop them. Currently, DANSYS and a statistics decision tree and glossary are available. I'm working on a user's manual for DANSYS and you'll see my progress on DANSYSX here.

Programming is a lot easier if you take a structured approach. Some languages (like Python) requires you to structure your programs. Others, like modern BASIC make it easy to structure programs but do not require it. Structured programming uses indentation to indicate levels of code (that will become much clearer as we go along). It also helps if you add notes to your code as you go along. This documentation serves two big functions: it reminds you what sections of code do if you need to go back and modify the code (which you often will), and it allows other people who use your code to understand what you've done.

I will admit that I sometimes slack off when it comes to documentation, but I will try to be responsible with the code in DANSYSX.

I try to maintain a five section structure for my LibreOffice Basic programs. The first section is the header. The first line of LibreOffice Baisc code names the program, tells whether the program is a subroutine or a function, and passes all the necessary information into the program.

The second section defines all the variables I'll be using in the program using DIM (DIMension) statements. I usually precede this section with a long comment explaining the program.

The third section initializes whatever variables need to start with some specific value.

The fourth section is where all the good stuff happens. It contains the works of the program.

The fifth and last section formats and outputs the data from the program.

Flow charts are useful to some people to help plan out complicated programs. I tend more to plot the way the program is supposed to work in pseudocode. Pseudocode describes the working of a program in descriptive English, line by line. For instance, if I want to add 1 to the variable bx over and over until it reaches 15, I might describe it with the following pseudocode:

bx=0
When bx reaches 15, jump out of the following loop
Add 1 to bx
Continue looping

More often, I type a scaffold of comments before I even start programming and then fill in the code. A comment in LibreOffice Basic looks like this:

'This is a comment. Notice that it begins with an apostrophe.
'LibreOffice Basic will ignore any statement beginning with an apostrophe.

[Note: If you've tried to use any of the in-text links to the Timeline, you will have found that they don't work anymore. That will be because I've moved it to a more secure site. I keep the links in the link section at the upper right of my webpages updated, and those do work.]


Thursday, June 15, 2017

--- Ubiquitous BASIC ---

2016

I have another range - cyberspace. Specifically, I explorer the more abstract corners of the world by programming.

I originally learned to program using BASIC. "BASIC" stands for "Beginner's All-purpose Symbolic Instruction Code" and it was developed by John G. Kemeny and Thomas E. Kurtz at Dartmouth College. It was designed to be a computer language that is similar to English so that beginning programmers could easily learn to program. It quickly became a popular, all-purpose language. In fact, it is often included in other software as a macro language.

In college, I programmed for other people and never had a problem adapting to other languages (except for - shudder- COBOL). More recently, I've played around some with Python but mostly use LibreOffice's version of Basic. LibreOffice uses a trimmed down version of BASIC to allow users to program their office productivity software.


Thursday, June 8, 2017


--- Getting started in programming ---

2016

There are still plenty of reasons to program computers.

Most software products have a limited bag of tricks. The developer has tried to figure all the features that a typical user would want from their program but there is no truly typical user. Sooner or later, everyone is going to gaze dreamily into the distance and say, "I sure wish this program could....(fill in the blank.)" The answer is to be able to program the computer to do what you want it to do.

A lifelong learner has much more reason to program. Programming a concept into a computer - teaching the computer to do what you're learning how to do - requires that you take the concept apart (analysis) and then put it back together in a form a computer will understand. You get to see the inner workings of the concept. How can you help but to learn?

There are many very accessible languages available to the beginner.

In fact, BASIC stands for Beginner's All-purpose Symbolic Instruction Code. It is designed to be easy to understand and easy to use. Even better, most of the office productivity suites like Microsoft Office, LibreOffice, and WPS uses a version of BASIC as a macro language. If one of these suites doesn't do something you want it to do, you can teach it to do the task and it will happily oblige you.

I like LibreOffice Basic because LibreOffice is a free, full powered office suite and, if you are using it to look at my Excursion documents, which are LibreOffice documents, then you're already set for programming with LibreOffice Basic.

There are programs that are designed to be fun and useful.

Scratch is a programming language consisting of blocks that you snap together. It was originally designed to manipulate graphic images in a learning environment, but with Custom Blocks, you can program it to perform more typical computer tasks.

If you want to play around with Scratch, you can find it here:

https://wiki.scratch.mit.edu/wiki/Scratch_Wiki_Home

Two languages that provide instant feedback as you program are Python and LiveCode. Both show you what your statements do as you type them in.

Python is a very popular, but fairly typical language. It seems too be very easy to  learn using supplied tutorials and user guides. You can find it here:

https://www.python.org

A modern version of a cool, old language (it was way before it's time back in the 70s) is LiveCode, an update of a language called HyperCard. It's also an object oriented language that will manipulate graphic objects, but it does much, much more. It's intended to be able to work with many platforms. Look at it here:

https://livecode.com

A similar such language also designed to be multiplatform (you can write programs to be used with many different systems - they're even working to make their product compatible with smartphone operating systems) is Xojo and here is their website:

http://www.xojo.com

In future articles, I will be giving you some tips for programming in LibreOffice Basic, primarily because it is very accessible, and most of the work I'm doing now is in that language, but, certainly, if you decide you like programming, look at these other languages and you might even want to spread out and play with some of the many (many!) other languages like C, FORTRAN, or (Whoa!) the assembly language for your processor.