Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Library subs and functions

Status
Not open for further replies.

KenshinHimura

Programmer
May 8, 2003
91
US
Would there be any way too let the user use a command and omit some arguments like qbasic's original commands do?
 
You mean if a user inputs "SIN 3.1415" you want the computer to spit out 0? You'd have to make a scripter.
 
Is that what you want to do, I could show you how it's done, I jusst don't want to write it all out if I misunderstood your question.
 
No, i mean when you make a library and you have functions and subs. In qbasic when you type function or sub and you have too put in variables with the functions or subs is there a way too make it so that they don't have too type them.

For example;

PSET (x,y), c
can also be written without the c
PSET (x,y)
and it still works even tohugh i ommitted c. Thats what i want to do with my commands.
 
No that doesn't work PSET(x,y),c will give you a pixil on in the colour c, without c it will put a pixil on in colour 15, which is the default.

If you want to omit the parameters you could use SHARED variables, I don't think they are shared with the libraries though, COMMON might be.
 
Could you give me an example of using the commands to help me with my task because i can't seem to get them to work.
 
I think it's impossible in QB to use variable amount of arguments. But if you really need it - you can pass parameter in array, and it could be of different length.
 
Oh i think i get it.......I'll try that. Lol i never would have even thought of that (your smart, I dumb lol), but then it would be harder to remember all the parameters in the sub or function. You said it was impossible, but doesn't Qbasic's regular commands let you do that most of the time? And since ASM libraries are made differently and all do you think that would work?
 
Qbasic doesn't know which parameters in your SUB are essential to the SUB running correctly, so it forces you to have an input for all of them.
The basic Qbasic commands, it knows which ones it has to have, and will only give you an error if one of those is empty.
The colour of a pixil is not essential, because it has a default of 15, but say omitting the x coordinate is illegal, becuase it has no default.
 
Well then would there be any way to tell Qbasic that one of my arguments is not essential without like rewriting qb lol. Thx tsh73 and qbking for helpin me out thus far :)
 
Why not have multiple commands? I know it's not really the nicest way of doing things, but what you want to do comes under something called "overloading", a really painful to keep track of technique you can use in Object Oriented languages like C++ or Java which QB doesn't support.

So instead of having one PUT statement, you'd have two.

put x, y, colour
putw x, y

I've done that at times, and while it's not pretty, it gets the job done if you want, and even better, using shared variables, you can share information between subs. For example:

dim share shColour as integer

sub put (x,y,colour)
shColour = colour
pset(x,y),colour
end sub

sub putw(x,y)
pset (x,y),colour
end sub


Does that help at all?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top