print function

Please use this Board for QBasic related requests ( file research, programming, etc.)

Moderators:Administrator, Global Moderator

Post Reply
Guest
print function

Post by Guest » Mon Mar 08, 2004 5:20 am

I am just starting to learn quick basic and am having trouble with a print function. I am trying to print the alphabet in alternating order, such as A, b, C, d....
Also I need to know how to get it to print on one line. At this point I have no problem getting it to print in the alternating order, but it isnt all on the one line.

Any help would be greatly appreciated.
Thanks

Artie
Jr. Member
Posts:23
Joined:Fri Feb 06, 2004 12:48 am
Location:Florida
Contact:

Re: print function

Post by Artie » Mon Mar 08, 2004 2:14 pm

There's a couple different ways you could do this.  One way would be to build a string before you print;

-----------------------------------------------------------
FOR x = 1 to 52
 READ a$
 alphabet$ = alphabet$ + a$
NEXT x
PRINT alphabet$
. . .
' your code
. . .
DATA A,a,B,b,C,c, . . . .
-----------------------------------------------------------

If you want a space between the letters, do: alphabet$ = alphabet$ + a$ + " "

or, use the "LOCATE" function

-----------------------------------------------------------
row = 10
col = 4
FOR x = 1 to 52
 READ a$
 LOCATE row, col + x: PRINT a$
NEXT x
. . .
' your code
. . .
DATA A,a,B,b,C,c, . . .
-----------------------------------------------------------

I always prefer using the LOCATE statement myself, but there are other ways.

Guest

Re: print function

Post by Guest » Mon Mar 08, 2004 5:23 pm

Thanks for the help.

What if I want them to alternate between capital and lower case.

Ex. A, b, C, d, E, f, G, h....

Artie
Jr. Member
Posts:23
Joined:Fri Feb 06, 2004 12:48 am
Location:Florida
Contact:

Re: print function

Post by Artie » Mon Mar 08, 2004 8:32 pm

You can put anything you want into a DATA statement:

DATA A,b,C,d,E,my poo don't stink,f,G,h, . . .

Just make sure the "FOR x = . . ." has the correct number of elements.

FOR x = 1 to 26   if you're going to use one letter of the alphabet each.

Artie
Jr. Member
Posts:23
Joined:Fri Feb 06, 2004 12:48 am
Location:Florida
Contact:

Re: print function

Post by Artie » Mon Mar 08, 2004 9:23 pm

Or better yet, try this code:

---------------------------------------------
CLS
a$=""
FOR x = 1 to 26
IF x MOD 2 > 0 THEN a = x + 64 else a = x + 96
a$ = a$ + CHR$(a)
NEXT x
LOCATE 10, 10: PRINT a$
END
-----------------------------------------------

The two 10's can be anywhere you want on the screen.

Guest

Re: print function

Post by Guest » Tue Mar 09, 2004 12:21 am

Hey, thanks a lot for the help. As I said earlier this is my first time working with quick basic or anyother programming language and I'm still trying to catch on to all the concepts.

Thanks again. :)

Artie
Jr. Member
Posts:23
Joined:Fri Feb 06, 2004 12:48 am
Location:Florida
Contact:

Re: print function

Post by Artie » Tue Mar 09, 2004 3:13 am

You're welcome.    ;D

I'm in the intermediate stage.  I know more than beginners, but not as much as the experts.

When I get stuck, I go over to: QuickBasicNews.Com

Another great QB forum.   ;)

Guest

Re: print function

Post by Guest » Tue Mar 09, 2004 5:33 pm

Hi,

To print om the same line put a
  ;
after the print statement

ie.

PRINT "A";
PRINT "b";
PRINT "C";
.
.
.
PRINT "z"

Pappy

 

Post Reply