Page 1 of 1

print function

Posted: Mon Mar 08, 2004 5:20 am
by Guest
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

Re: print function

Posted: Mon Mar 08, 2004 2:14 pm
by Artie
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.

Re: print function

Posted: Mon Mar 08, 2004 5:23 pm
by Guest
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....

Re: print function

Posted: Mon Mar 08, 2004 8:32 pm
by Artie
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.

Re: print function

Posted: Mon Mar 08, 2004 9:23 pm
by Artie
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.

Re: print function

Posted: Tue Mar 09, 2004 12:21 am
by Guest
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. :)

Re: print function

Posted: Tue Mar 09, 2004 3:13 am
by Artie
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.   ;)

Re: print function

Posted: Tue Mar 09, 2004 5:33 pm
by Guest
Hi,

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

ie.

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

Pappy