subroutines

Discussion about the ZBasic language including the System Library. If you're not sure where to post your message, do it here. However, do not make test posts here; that's the purpose of the Sandbox.
Post Reply
Paul Lamar
Posts: 65
Joined: 14 May 2010, 16:01 PM

subroutines

Post 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
dkinzer
Site Admin
Posts: 3120
Joined: 03 September 2005, 13:53 PM
Location: Portland, OR

Re: subroutines

Post 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.
- Don Kinzer
Paul Lamar
Posts: 65
Joined: 14 May 2010, 16:01 PM

Post 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
FFMan
Posts: 502
Joined: 09 January 2010, 12:52 PM

Post 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.
stevech
Posts: 715
Joined: 22 February 2006, 20:56 PM

Post 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.
Post Reply