×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Library subs and functions

Library subs and functions

Library subs and functions

(OP)
Would there be any way too let the user use a command and omit some arguments like qbasic's original commands do?

RE: Library subs and functions

You mean if a user inputs "SIN 3.1415" you want the computer to spit out 0?  You'd have to make a scripter.

RE: Library subs and functions

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.

RE: Library subs and functions

(OP)
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.

RE: Library subs and functions

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.

RE: Library subs and functions

(OP)
Well i meant that it didn't give me the argument count mismatch.

RE: Library subs and functions

(OP)
ok i'll try the common shared thing thx

RE: Library subs and functions

(OP)
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.

RE: Library subs and functions

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.

RE: Library subs and functions

(OP)
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?

RE: Library subs and functions

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.

RE: Library subs and functions

(OP)
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

RE: Library subs and functions

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?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close