Centerin text with Len

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
User avatar
lurah-
Veteran
Posts: 206
Joined: Mon Nov 01, 2004 10:47 am
Location: Finland
Contact:

Centerin text with Len

Post 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
User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

Post 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...
"But...It was so beutifully done"
User avatar
lurah-
Veteran
Posts: 206
Joined: Mon Nov 01, 2004 10:47 am
Location: Finland
Contact:

Post by lurah- »

Yah, Mitth. You are DA MAN 8) thx a lot.
User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

Post by Mitth'raw'nuruodo »

Glad to help, your welcome.
"But...It was so beutifully done"
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post 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
Last edited by Rattrapmax6 on Sat Feb 19, 2005 1:54 pm, edited 1 time in total.
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

Post 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.
"But...It was so beutifully done"
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post 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:
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
User avatar
Mitth'raw'nuruodo
Veteran
Posts: 839
Joined: Sat Jan 22, 2005 11:04 am
Location: Eastern Coast of US
Contact:

Post by Mitth'raw'nuruodo »

Oh that a back space, your right!

Well thats just another optimization for my program to do...
"But...It was so beutifully done"
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post by Rattrapmax6 »

:) Heh heh, yep... :wink:
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re »

/ is floating point division
\ is integer division, it does NOT round, it IGNORES any decimals.
I have left this dump.
Rattrapmax6
Veteran
Posts: 1055
Joined: Sun Jan 02, 2005 2:11 pm
Location: At my computer
Contact:

Post by Rattrapmax6 »

:) Okay, not round, I'm misstaken.. but still, the effects are close to the same... :)
-Kevin (aka:Rattra)
(x.t.r.GRAPHICS)
Post Reply