Page 1 of 1

Centerin text with Len

Posted: Sat Feb 19, 2005 8:53 am
by lurah-

Code: Select all


CLS
INPUT "Write text:";t$
FOR y = 1 TO LEN(t$) 
LOCATE 10, y
PRINT MID$(t$, y, 1)
NEXT 

[END]

Ok, that works but how i can LOCATE it so that it will be centerd on screen?
Some how i need to find out how long t$ is so i can place it so that finally it?s middle of screen.

LOCATE 10, 40 - y(- half of lenght of t$) something like this. Lol, hope you got my point here =)

Screen is 80,50 width

Posted: Sat Feb 19, 2005 9:01 am
by Mitth'raw'nuruodo
Ok sme thing except:
Here's your new locate statement:

LOCATE 25, (40-INT(LEN(t$)/2)+y)

Got that? Good....
I just tyoed that so it should work let me know...

Posted: Sat Feb 19, 2005 9:07 am
by lurah-
Yah, Mitth. You are DA MAN 8) thx a lot.

Posted: Sat Feb 19, 2005 10:31 am
by Mitth'raw'nuruodo
Glad to help, your welcome.

Posted: Sat Feb 19, 2005 12:02 pm
by Rattrapmax6
Yep, Mitth's code is correct, but this is shorter..

LOCATE 1, 40 - (LEN(text$) \ 2): PRINT text$

There, you can chose.. :wink:

( \ ) rounds while dividing if you want to know. :D

Posted: Sat Feb 19, 2005 12:08 pm
by Mitth'raw'nuruodo
Well I was truncating it which divide in QB doesn't do other wise it would be a decimal.

And you are right that is shorter, cause its the whole program you need no LOOP or MID$!

BUT you're partically right that even though / doesn't round in QB, the LOCATE statement does. But I didn't want to round it up I preferr down.

Posted: Sat Feb 19, 2005 12:13 pm
by Rattrapmax6
Yeah, you use this in raycasting to limit some floating points ( \ ) to encreace running speed... yours would slow it down, but applied to what larah wants, yours works, but mine will save for typing.. :wink:

Posted: Sat Feb 19, 2005 1:15 pm
by Mitth'raw'nuruodo
Oh that a back space, your right!

Well thats just another optimization for my program to do...

Posted: Sat Feb 19, 2005 1:53 pm
by Rattrapmax6
:) Heh heh, yep... :wink:

Posted: Sat Feb 19, 2005 3:27 pm
by Z!re
/ is floating point division
\ is integer division, it does NOT round, it IGNORES any decimals.

Posted: Sat Feb 19, 2005 3:30 pm
by Rattrapmax6
:) Okay, not round, I'm misstaken.. but still, the effects are close to the same... :)