Page 1 of 1
subroutines
Posted: 25 May 2010, 17:00 PM
by Paul Lamar
I am confused. I did not go to programming school.
What happened to simple subroutines?
What is the simplest form of a Call
to replace an old fashion subroutine?
I don't need to pass anything.
if x is true gosub fixit
fixit:
stuff
return
Paul Lamar
Paul Lamar
Re: subroutines
Posted: 25 May 2010, 17:34 PM
by dkinzer
Paul Lamar wrote:What happened to simple subroutines?
They are alive and well. The syntax that you referred to is the original Dartmouth Basic syntax (circa 1964) for calling subroutines. As you know, Dartmouth Basic did not allow parameters; data was "passed" to a subroutine by setting global variables (a practice very much frowned upon today - and for good reason). Later, the Basic language was made significantly more powerful when modern structured programming elements were introduced, at least as early as 1991 with the introduction of Visual Basic. (There could be earlier examples of Basic with structured programming elements.)
The simple program below shows how to define and invoke a parameterless subroutine.
Code: Select all
Dim v as Integer
Sub Main()
If (v > 3) Then
Call foo()
End If
End Sub
Sub foo()
v = 10
End Sub
Note that you can omit the Call if you wish but its use is recommended. If the subroutine takes no parameters, you may also eliminate the parentheses. Consequently, the example program below is also legal but not recommended.
Code: Select all
Dim v as Integer
Sub Main()
If (v > 3) Then
foo
End If
End Sub
Sub foo()
v = 10
End Sub
There are microcontrollers that utilize the antiquated Dartmouth Basic syntax including PBasic used on the Basic Stamp.
Posted: 25 May 2010, 21:37 PM
by Paul Lamar
Thanks Don.
Looks simple enough.
Take a look at QB.
It had some nice features.
It was real time under DOS. I wrote a GPS driven moving map
program in it back in 1989. Of course it had all the file name
size and memory size limitations of DOS.
It was smart enough to automatically figure out data types.
Reduced the need for Dim. Memory is getting cheaper.
I still love it.
I like your ZBasic feature of 0.0 dimensioning Single.
BTW you could use a lot more examples in the
ZBasic Language Reference Manual for us Dick and Jane types.
Paul Lamar
Posted: 26 May 2010, 1:37 AM
by FFMan
Quickbasic was a favourite of mine too - ran real quick too.
I have used so many dialects of basic over the years the syntax can be confusing. I still get caught out with MID not being MID$ a convention Vax basic used to signify which fucntions returned a string. If you are as old as me you may have played with Basic+ running under RSTS or pre-PC we had a compiler called BASCOM running on a Sirius and Apricot !
The Zbasic version is good and does a good job of picking up programming errors.
Posted: 26 May 2010, 15:33 PM
by stevech
Paul Lamar wrote:
BTW you could use a lot more examples in the
ZBasic Language Reference Manual for us Dick and Jane types.
Paul Lamar
I think you'll find that ZBasic is so similar to Microsoft's wildly popular Visual Basic 6 (not VB.net) that most texts and examples for that can be used.