Dec 202017
 
Source code that allows Exiting QuickBasic programs with an errorlevel.
File QBERRLVL.ZIP from The Programmer’s Corner in
Category BASIC Language
Source code that allows Exiting QuickBasic programs with an errorlevel.
File Name File Size Zip Size Zip Type
BASEXIT.BAS 816 419 deflated
CEXIT.OBJ 202 182 deflated
ERRLEVEL.DOC 4246 1919 deflated
TESTEXIT.BAT 328 140 deflated
TPCREAD.ME 199 165 deflated

Download File QBERRLVL.ZIP Here

Contents of the ERRLEVEL.DOC file



Exiting QuickBasic programs with an errorlevel

by Mike Janke, Kendall BBS
CIS 72105,1123


There are no guarantees associated with anything I've included in this
archive. If it works for you, and it should, great! But if not, I'm
truly sorry and there's nothing I can do about it. If you link
CEXIT.OBJ with your QuickBasic program and it causes "FORMAT C:" to
pop up on your screen when you run it, well, I'd certainly be amazed
to hear that, but there's not much I can do for ya. If it breaks, you
own both pieces.

Any misinformation in this file is purely unintentional and should be
written off as being due to inexperience.

Everything in this archives is released on an "as is" basis for you to
do with as you please. You may distribute it to anyone you like. I
wouldn't like to see anyone charge anything for this stuff, but if you
do, I'm not gonna come looking for you and would consider you to be
quite a salesman.



Because I run a BBS, most of the programs I write in QuickBasic are
utilities for the particular BBS software I use. Many of these utils
are intended for use in a daily, unattended 'cleanup' run in the batch
file that runs the system.

I've never really searched, but I've kept my eyes open for a routine
that would allow me to exit a QuickBasic program with a specific
errorlevel if something goes wrong. I've never really found anything
to do this. I've heard of kludges to obtain an errorlevel by forcing
an ERR and QuickBasic would pass this to DOS which could then be
trapped. I don't know if this really works, but it didn't sound too
useful so I never even tried it.

PROBAS has the SETERROR routine, but this doesn't work with QuickBasic
4.0 for whatever reason, and I'm not about to go back to 3.0 just to
get this feature.

I'm not a C programmer, but the function to exit with an errorlevel in
C was about as simple as I could ask for. It looks something like
this...

cexit() {
int a;
exit(a);
}

Well, even I could handle that one! Problem is, the QuickBasic manual
really stinks (in my opinion) when it comes to explaining how to CALL
a subroutine in C. Try as I might, I couldn't get it to work... until
I saw the source for a program that made a CALL to a C subroutine.

VOILA! In about 5 minutes I had a functional C subroutine to exit with
an errorlevel, and a test QuickBasic program to try it out with.
Amazingly enough, it worked!

I wanted to share this with anyone else that may be looking for such a
routine. If I've duplicated something that already exists... well, I
could never find such a thing and wish I could have long ago.

Within this archive are three files (not counting this .DOC).
BASEXIT.BAS, CEXIT.OBJ and TESTEXIT.BAT.

BASEXIT.BAS is a sample basic program to show you how the errorlevels
are accessed.

CEXIT.OBJ is the compiled C source that contains the exit() function.

TESTEXIT.BAT is just a sample batch file so you may test a couple of
errorlevels to see that it really works. I cannot include a tutorial
on batch files, so if you don't understand errorlevels I suggest you
check your dos manual. If you use the errorlevels shown in the batch
file, you'll see that it works just fine. If you use something else
and you're not familiar with batch files, you may be confused by the
results.

Compile BASEXIT.BAS with BC.EXE like this...

bc basexit/o;

Then, link the resulting Basexit.obj with Cexit.obj something like
this...

Link basexit+cexit,,,,

OR...

Link basexit+cexit

and answer the prompts that LINK will provide.

Once you have BASEXIT.EXE, run TESTEXIT.BAT and answer the prompt with
an errorlevel of 25, 10 or 0 and you'll see the result. BASEXIT is
not a very exciting program, and TESTEXIT.BAT could have contained all
255 errorlevels, but I didn't see the point in that. You should be
able to get the idea from what I've included.

So far this seems to be working just fine for me with QuickBasic 4.0
on a Tandy 1000 and a XT clone. I'm sure this will only work on
QuickBasic programs compiled as STAND-ALONE, that is, not requiring
BRUN40.EXE to run.

enjoy.



 December 20, 2017  Add comments

Leave a Reply