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 CrookMy program statement was L= len(name$). PRINT Tab (18 - L) name$. ThatCode: Select all
Darlene Crook< >Darlene Crook Bob Crook< >Bob Crook
didn't give me the result I wanted. Thanks for your help.
Dale
PRINT Strings
PRINT Strings
Hey guys, answer this dude's question for me, will you?
-
- Veteran
- Posts: 703
- Joined: Sun Nov 14, 2004 7:36 am
- Contact:
This should do the trick:
Expected Output:
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
Code: Select all
Stephane Richard
Pete Berg
Alice Cooper
Terry Fox
Kristian Virtanen
When God created light, so too was born, the first Shadow!
MystikShadows
Need hosting? http://www.jc-hosting.net
Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
MystikShadows
Need hosting? http://www.jc-hosting.net
Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
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
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
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."
*****
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."
*****