Putting variables in the DRAW command.

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Sinuvoid
Veteran
Posts: 155
Joined: Wed Jul 25, 2007 8:20 am

Putting variables in the DRAW command.

Post by Sinuvoid »

How do I do that?? I've tried doing,

Code: Select all

 DRAW "d",a"u",b etc.. 
and I've tried

Code: Select all

 DRAW "D" + a + "U" + b + etc...
Any suggestions on how to do that? If so thanks! :P
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

That would work a lot better using strings for variables.

DRAW "U" + A$

Where A$ is a string number. To convert any number to a string use the STR$(number) function:

A$ = STR$(number)

DRAW does not care about spaces so you do not have to trim it.

Ted
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

How do you know that his a and b variables aren't strings already?
Sinuvoid
Veteran
Posts: 155
Joined: Wed Jul 25, 2007 8:20 am

Post by Sinuvoid »

Because they dont include "$" :P Thanks for noticing anyways :)
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Because your a JERK Nodvelt! That's why? Why else would Lee's code not work numbnuts?

Go finish your website! It is just another example of your laziness!
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Sinuvoid
Veteran
Posts: 155
Joined: Wed Jul 25, 2007 8:20 am

Post by Sinuvoid »

Ok, don't go crazy people xD
User avatar
BadMrBox
Veteran
Posts: 86
Joined: Tue Feb 28, 2006 12:19 pm

Post by BadMrBox »

Bring the paramedics. I think Clippy is having a seizure.
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

Code: Select all

DIM A AS STRING
A = "Clippy has fleas"
PRINT A
Type suffixing is evil.
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Most newer programmers do not DIM all of their variables, especially if they are just experimenting. There is absolutely nothing wrong with type suffixes. Look in any book on Basic!

As for the fleas, I must have got them from you! What kind of animal are you anyhow? They are easy to spot on my thin shiny body.

Still no code from Mr B I see. Call me a doctor!

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

burger2227 wrote:Call me a doctor!
You're a doctor.
burger2227 wrote:Most newer programmers do not DIM all of their variables, especially if they are just experimenting. There is absolutely nothing wrong with type suffixes. Look in any book on Basic!
That's a pretty gross assumption. You have no idea if a coder, even a "new one", has a background in C, for example, where type suffixes do not exist and are widely considered to be horrible style. Furthermore, I've probably read more books on BASIC than you ever will.
burger2227 wrote:As for the fleas, I must have got them from you! What kind of animal are you anyhow? They are easy to spot on my thin shiny body.
I'm a troll-eating dragon. But I generally use the thin ones like you as toothpicks.
Sinuvoid
Veteran
Posts: 155
Joined: Wed Jul 25, 2007 8:20 am

Post by Sinuvoid »

Nice Humor guys :P
Mac
Veteran
Posts: 151
Joined: Mon Aug 06, 2007 2:00 pm

Still with us, Lee?

Post by Mac »

Lee wrote:Because they dont include "$" :P Thanks for noticing anyways :)
Uh, did you get your answer, Lee?

As burger2227 implied, you cannot have numbers, just strings.

Demo follows.

Mac

Code: Select all

SCREEN 1
LINE INPUT "Press Enter for demo"; e$
FOR i = 1 TO 10
  DRAW "d" + STR$(INT(RND * 5))
  DRAW "r" + STR$(INT(RND * 5))
  DRAW "u" + STR$(INT(RND * 5))
  DRAW "l" + STR$(INT(RND * 5))
NEXT i
bungytheworm
Veteran
Posts: 288
Joined: Sat Feb 18, 2006 4:02 pm

Post by bungytheworm »

Maybe moderators could remove all posts that does not handle about the topic itself?
Do we have moderators here?
Sinuvoid
Veteran
Posts: 155
Joined: Wed Jul 25, 2007 8:20 am

Post by Sinuvoid »

Yeah I got my answer,but I found a better solution and jsut use LINE. (Im making a library with buttons and text boxes etc.) But im having another problem and its with the COLOR and LOCATE command.

When I type

Code: Select all

CLS
SCREEN 13
LOCATE 2,5
COLOR 15,12
PRINT "Test"
it brings a a popup saying COLOR command stynax wrong or something :? What I'm I doing wrong?! And also when I use 0 it acts like its transparent...?
Mac
Veteran
Posts: 151
Joined: Mon Aug 06, 2007 2:00 pm

Post by Mac »

Lee wrote:im having another problem and its with the COLOR
Unfortunately, each screen has rules about color. It's a pain.

SCREEN 13 only allows one operand. There is no way to change the background without stuff like OUT commands.

Mac

Code: Select all

CLS
SCREEN 13
FOR i = 0 TO 128 STEP 8
  FOR j = 0 TO 7
    COLOR i + j
    PRINT i + j;
  NEXT j
  PRINT
NEXT i
COLOR 7
P.S. As before, don't ask another question. Instead start a new thread for a new topic. You should have made a new thread about COLOR.
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

The two-argument form of COLOR doesn't work with SCREEN 13. You can only specify the foreground color.
Sinuvoid
Veteran
Posts: 155
Joined: Wed Jul 25, 2007 8:20 am

Post by Sinuvoid »

Ok, but I think the PALETTE command is going to fix my problem. Thanks! And yeah Ill start a new thread next time :P
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt »

You can set index 0 to be a different color, but that affects all the pixels of the "background" so that might not be what you want. Ultimately, what you probably would want to do is write your own text function if you want fancy text.
Sinuvoid
Veteran
Posts: 155
Joined: Wed Jul 25, 2007 8:20 am

Post by Sinuvoid »

Function? How is that going to make a differenc form doing it in teh main moduel?
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Even if Lee had the background option, ALL of the background would be changed. However, with 256 color attributes, you can always change parts to other color shades using different attribute numbers.

PRINT will still have the default black attribute 0 behind the text however.

I have an interrupt Function that can change the text background color also.

Do I hear an echo in here or did N just tell you the same thing that Mac already said?

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Post Reply