A smart word wrapper. This took me alot longer than I thought it would...
Not used to counting strings... or counting them invisibly. (I like pre defined values.)
So... it dynamically wraps words... or anything. it shouldn't bug... but if you put in a word that's 70 characters it might crash... o_0
Enjoy.
[pbcode]
; PROJECT : Word Wrapper
; AUTHOR : LemonWizard
; CREATED : 3/13/2009
; EDITED : 3/13/2009
; ---------------------------------------------------------------------
;edit this string however you like, I'm certain that it won't bug. ^^ make it 350 characters long for all it cares. =P
s$="happy happy happy happy happy happy happy test test test were going for 70 here a perfect word wrapper... it's very crucial to making things appear correctly you know so far nothings been cut off were going to use short short i i i i testsing the i u u "
cy=1
for temp=1 to len(s$)
if mid$(s$, temp, 1)=" "
dtemp=1
for temp2=1 to len(s$)-temp
if mid$(s$, temp2+temp, 1)=" "
exitfor
else
inc dtemp
next temp2
if dtemp >70-cx
cx=1
inc cy
dtemp=1
endif
endif
endif
setcursor cx*10, cy*10
print mid$(s$, temp, 1)
inc cx
next temp
waitkey
[/pbcode]
Hey lemon,
Quotebut if you put in a word that's 70 characters it might crash
what are meaning... do you have some example?
here it works...
But if I look deeper in your code there is a NONE NONE :)
[pbcode]
cy=1
for temp=1 to len(s$)
if mid$(s$, temp, 1)=" "
dtemp=1
for temp2=1 to len(s$)-temp
if mid$(s$, temp2+temp, 1)=" "
exitfor
else
inc dtemp
<---- ONE STOP!! WHERE IS TEH CLOSING IF-STATEMENT "ENDIF"
next temp2
if dtemp >70-cx
cx=1
inc cy
dtemp=1
endif
endif
endif
setcursor cx*10, cy*10
print mid$(s$, temp, 1)
inc cx
next temp
waitkey
[/pbcode]
so, here is the well structured code for you... I hope you see the different... ;)
[pbCode]
s$="happy happy happy happy happy happy happy test test test were going for 70 here a perfect word wrapper... it's very crucial to making things appear correctly you know so far nothings been cut off were going to use short short i i i i testsing the i u u "
cy=1
For temp=1 To Len(s$)
If Mid$(s$, temp, 1)=" "
dtemp=1
For temp2=1 To Len(s$)-temp
If Mid$(s$, temp2+temp, 1)=" "
ExitFor
Else
Inc dtemp
EndIf
Next temp2
If dtemp >70-cx
cx=1
Inc cy
dtemp=1
EndIf
EndIf
SetCursor cx*10, cy*10
Print Mid$(s$, temp, 1)
Inc cx
Next temp
WaitKey
[/pbcode]
Hi LemonWizard
Quotebut if you put in a word that's 70 characters it might crash...
No problems with a 70 character word but the first word of the message doesn't get indented. O.K otherwise.
[pbcode];edit this string however you like, I'm certain that it won't bug. ^^ make it 350 characters long for all it cares. =P
s$="Wishing you a very happyhappyhappyhappyhappyhappyhappyhappyhappyhappyhappyhappyhappyhappy New Year"
cy=1
for temp=1 to len(s$)
if mid$(s$, temp, 1)=" "
dtemp=1
for temp2=1 to len(s$)-temp
if mid$(s$, temp2+temp, 1)=" "
exitfor
else
inc dtemp
next temp2
if dtemp >70-cx
cx=1
inc cy
dtemp=1
endif
endif
endif
setcursor cx*10, cy*10
print mid$(s$, temp, 1)
inc cx
next temp
waitkey[/pbcode]
:)
geecee
hm yeah interesting.. I didn't notice that the first word isn't indented.
I wonder how I'd make it line the first word up with the next line below so you get a proper margine...
any ideas?
Hi LemonWizard
What I did was to start the message with two spaces.
s$=" Wishing you a very happyhappyhappyhappyhappyhappyhappyhappyhappyhappyhappyhappyhappyhappy New Year"
That's all I could think of.
:)
Cheers
geecee
The inner loop is malformed.
[pbcode]
for temp2=1 to len(s$)-temp
// IF / ELSE / ENDIF
if mid$(s$, temp2+temp, 1)=" "
exitfor
else
inc dtemp
// WHERE IS THE END IF ??????????
next temp2
[/pbcode]
Very interesting ...... The programme still works with a malformed inner loop.
The programme does however have three ifs and three endifs.
:)
geecee
Quote
The inner loop is malformed.
Nice... I've point this in the 2nd Post ;)
Quote
The programme still works with a malformed inner loop.
I was also surprised at that. Can that be an error?
I have no idea, most of the time when I'm doing programming I'm pretty tired and not all here =p
So, I tend to make a few mistakes.. overall the way I program is mostly through design first, trial and error.
And then, a working version.
Hi LemonWizard
Not an error on your part ....... A PB error
:)
geecee