Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

printing in a box

Status
Not open for further replies.

shanley06

Programmer
Nov 26, 2002
101
US
i have a box in screen 9 that is one quarter of the screen big and it is on the right hand side of the screen at the top. i was wondering how i could make a sub routine that would work like print only just make it so that it prints everything in the box
 
Do you have any test code you're trying out?

If not, what do you have for pseudo code?

It should be something like:

1) find row # of the box's top line (ex: line 3)
2) find row # of the Box's bottom line (ex: line 12)
3) find printable area between top and bottom line (ex: 4 [top+1] - 11 [bottom-1] = 7 lines between)
4) place cursor on line # 4 [Top+1]
5) ...
...
...

--MiggyD
 
to: shanley06
Do you wonder "how" (and going to implement it yourself) or do you just want piece of code?
If first, you'll have to write piece of code that would "cut" string into pieces - but not equal length (it would look ugly - words would wrap strange) - but by spaces. And print these pieces as item (5) of MiggyD pseudocode.
In second case - I just happen to have piece of code (dated May 2000 ;)) - so if you wish I could post it.
Not posting it immediately - won't deprive you of pleasure of inventing bicycle ;)
<btw inventing is a good thing IMHO>
 
TO tsh73:

'btw inventing is a good thing IMHO'

Absolutely!! It makes you look outside the box, when we are &quot;printing in a box&quot; (pun intended). LOL

Couldn't help it. I just had to. This post's title was just egging me on.

--MiggyD
 
i figured it out except for it cuts off some letters when i print,if you know wahts wrong please help me...this is what i have so far(note: at the beggining of your program you need LETTERY=1 so that the sub will work)

Code:
SUB BOXPRINT (STRIN$)
SHARED LETTERY
IF (LEN(STRIN$) < 40) OR (LEN(STRIN$) = 40) THEN
        LOCATE LETTERY, 40: PRINT STRIN$
        IF LETTERY < 13 THEN LETTERY = LETTERY + 1
        IF LETTERY = 13 THEN LETTERY = 1
END IF
IF (LEN(STRIN$) > 40) THEN
        FIRSTPART$ = MID$(STRIN$, 1, 40)
        SECONDPART$ = MID$(STRIN$, 40, LEN(STRIN$))
        BOXPRINT FIRSTPART$
        BOXPRINT SECONDPART$
END IF
END SUB
[/b]
[/color]
 
hmm. sounds like something i made. it's kinda a text rpg, but the story plays in a box.

first, you got to figure out how much letters your box can hold widthwise. then you have to find out how many lines it could hold. Create a variable to hold lines in. in the sub that prints the text into the box, have another variable hold the length of your text, with the len statement. there's tons more, but ihave sourcecode for you to use. just copy it to a notepad document, save it and load it up with qbasic. then run it. take it apart and experiment. this code actually runs very well. this piece of code will print these sentances letter per letter, moving the sentence to the next line if the word is too big for the box. if you want paragraphs, then just do this.

story = &quot;This is one paragraph.&quot;
storywriter
story = &quot;this is another paragraph!&quot;
storywriter

this will tell this script to make a new paragraph. this works well if you want to write a story in qbasic. and if the paragraph reaches the end of the box, it will wait for a keypress, then continue on a new page. note that this was designed in screen 9, so it should work perfectly. all you need to do is give this a few teaks.


'start code!
screen 9

LINE (250, 22)-(620, 172), , B


story = &quot;The quick brown fox jumped over the lazy dog the quick brown fox jumped over the lazy dog the quick brown fox jumped over the lazy dog the quick brown fox jumped over the lazy dog.&quot;
storywriting
LINE (250, 22)-(620, 172), , B


sub storywriting
keypress = INKEY$
storyypos = storyypos + 1
storyxpos = 33
story2 = LEN(story)
story5% = 0
story3 = 0

DO
IF storyypos = 22 THEN
storyypos = 4
storyxpos = 33
DO: LOOP UNTIL keypress <> &quot;&quot;
clearstorybox

END IF


story3 = story3 + 1
story5% = story5% + 1
story4 = MID$(story, story5%, 1)
storyxpos = storyxpos + 1
IF story3 > 37 AND story3 < 45 AND story4 = &quot; &quot; THEN
storyypos = storyypos + 1
storyxpos = 33
story3 = 0
END IF


IF INKEY$ <> &quot;&quot; THEN

ELSE
FOR i& = 1 TO 55000
NEXT i&
END IF
LOCATE storyypos, storyxpos
PRINT story4


LOOP UNTIL story5% = story2

end sub

SUB clearoptionbox
'this box displays your options
LINE (1, 23)-(119, 170), 0, BF

END SUB
 
i actually read the last part, and i know how to get rid of that nasty problem. in my code there is the solution, but i can print the code here as well.

before you print the letter at the end of the box, ask the machine: Is what it is printing a space? if it is, return the letterx to a number so it will bring the next word to the next line. actually, put the check after. then it won't seem like your indenting every line after the first line.
 
to: shanley06
After adding this main module to your sub,
Code:
LETTERY = 1
s$ = &quot;The quick brown fox jumped over the lazy dog the quick brown fox jumped over the lazy dog the quick brown fox jumped over the lazy dog the quick brown fox jumped over the lazy dog.&quot;
CLS
c = 0
DO
c = (c + 1) MOD 14
COLOR c + 1
BOXPRINT s$
a$ = INPUT$(1)
LOOP UNTIL a$ = &quot; &quot;  'loop until space pressed

I got:

The quick brown fox jumped over the lazy
y dog the quick brown fox jumped over th
he lazy dog the quick brown fox jumped o
over the lazy dog the quick brown fox ju
umped over the lazy dog.

so it _doubles_ last simbol of each line.
This could be prevented by changing line
Code:
SECONDPART$ = MID$(STRIN$, 40, LEN(STRIN$))
to
Code:
SECONDPART$ = MID$(STRIN$, 41, LEN(STRIN$))
But when we got spaces in the beginning of a line:

The quick brown fox jumped over the lazy
dog the quick brown fox jumped over the
lazy dog the quick brown fox jumped ove
r the lazy dog the quick brown fox jumpe
d over the lazy dog.

So we add LTRIM$:
Code:
SECONDPART$ = LTRIM$(MID$(STRIN$, 41, LEN(STRIN$)))
and here we a are:

The quick brown fox jumped over the lazy
dog the quick brown fox jumped over the
lazy dog the quick brown fox jumped over
the lazy dog the quick brown fox jumped
over the lazy dog.
 
that answers my question thank you to everyone who helped
 
There is another way. this checks if the letter it is printing down is a space or not, and if it is over far enough to go just about go out of the box. Then it moves the whole paragraph down one line, and back to the beginning x value. It's right there on my program.
 
also... You are using screen 9 (which is a graphics mode)
Do you want to use &quot;PRINT&quot; to write the text, which creates a solid background, and limited locations to print to...???

Or do you want to write the text with graphics?

Here is a Sub you can use to draw the Text Graphically...

Play around with it a little bit...

SUB FONT (X%, Y%, S$, C%)
A% = X%: B% = Y%
EXTX% = 8: EXTY% = 0
DEF SEG = &HFFA6
FOR I% = 1 TO LEN(S$)
ADDR% = 8 * ASC(MID$(S$, I%)) + 14
FOR J% = 0 TO 7: MASK% = PEEK(ADDR% + J%) * 128
LINE (X% + 7, Y% + J%)-(X%, Y% + J%), C%, , MASK%
NEXT
X% = X% + EXTX%: Y% = Y% + EXTY%
NEXT
DEF SEG
X% = A%: Y% = B%
END SUB


X% : graphical X coord
Y% : graphical Y coord
S$ : Text String
C% : Color

I think there may be a few issues with NT based machines...
But it does work for win 9x systems...

This way you are not limited to the &quot;Text Mode Grid&quot;

ALSO...
you can use other graphical features such as view ports to only display part of the text... if you want to add scrolling...

You can also simulate Bold, Italic, Underlined, and shadow fonts by tweaking the code...

Good Luck

Have Fun, Be Young... Code BASIC
-Josh Stribling
cubee101.gif

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top