Page 1 of 1
PRINT Strings
Posted: Mon Oct 24, 2005 11:08 am
by Pete
Hey guys, answer this dude's question for me, will you?
Ref: Comments:
I use to be able to run the different lines seperatly in gwbasic, but
haven't been able to in qbasic. For instance the command "print L" would
give me the value of L. My qbasic does not give me that. Can you help me?
Dale Crook
``````````````````````````````````````````````````````````````````````
What I'm trying to do is print a column with different length strings,
and have the column justified on the right Dale Crook<
instead of the left. >Dale Crook
Code: Select all
Darlene Crook< >Darlene Crook
Bob Crook< >Bob Crook
My program statement was L= len(name$). PRINT Tab (18 - L) name$. That
didn't give me the result I wanted. Thanks for your help.
Dale
Posted: Mon Oct 24, 2005 11:56 am
by MystikShadows
This should do the trick:
Code: Select all
DECLARE SUB RightJustify (TextString AS STRING, ColumnWidth AS INTEGER)
DIM WorkName(1 TO 5) AS STRING
WorkName(1) = "Stephane Richard"
WorkName(2) = "Pete Berg"
WorkName(3) = "Alice Cooper"
WorkName(4) = "Terry Fox"
WorkName(5) = "Kristian Virtanen"
FOR Counter = 1 TO 5
CALL RightJustify(WorkName(Counter), 30)
NEXT Counter
SLEEP
SUB RightJustify (TextString AS STRING, ColumnWidth AS INTEGER)
Position% = ColumnWidth - LEN(TextString)
LOCATE CSRLIN, Position%
PRINT TextString
END SUB
Expected Output:
Code: Select all
Stephane Richard
Pete Berg
Alice Cooper
Terry Fox
Kristian Virtanen
Posted: Mon Oct 24, 2005 2:37 pm
by {Nathan}
Also, to run lines seperatly look at the bottom of your QBASIC screen. There is an immediate box (if you don't see it, press F6 a few times) and then you can run lines immediatly (hence the title) there. You just have to type (or copy) the line there and press enter.
Posted: Mon Oct 24, 2005 7:29 pm
by moneo
Not as elegant as Mystik's solution, but a little simpler:
Code: Select all
DIM WorkName(1 TO 5) AS STRING
WorkName(1) = "Stephane Richard"
WorkName(2) = "Pete Berg"
WorkName(3) = "Alice Cooper"
WorkName(4) = "Terry Fox"
WorkName(5) = "Kristian Virtanen"
REM Assuming that no name is greater than 30 characters.
FOR Counter = 1 TO 5
PRINT SPACE$(30-LEN(WorkName(Counter))+WorkName(Counter)
NEXT Counter
SLEEP
Posted: Tue Oct 25, 2005 1:54 pm
by Antoni
Even simpler:
Code: Select all
DIM WorkName(1 TO 5) AS STRING
WorkName(1) = "Stephane Richard"
WorkName(2) = "Pete Berg"
WorkName(3) = "Alice Cooper"
WorkName(4) = "Terry Fox"
WorkName(5) = "Kristian Virtanen"
REM Assuming that no name is greater than 30 characters.
a$=space$(30)
FOR i = 1 TO 5
rset a$="" 'in FB use rset a$, ""
rset a$=Workname(i) 'in FB use rset a$,Workname(i)
print a$
NEXT Counter
SLEEP
Posted: Tue Oct 25, 2005 7:31 pm
by moneo
Antoni,
The instruction " rset a$="" " is not needed, so I removed it.
The instruction "NEXT Counter" should be "NEXT i".
I tested it and now it runs "even simpler".
I never used the RSET and LSET statements in QB. I thought they were only for use with FIELD statements.
Thanks, like they say, "you learn something every day."
*****