Qbasicnews.com

Full Version: Centreing variables
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
After i the user has inputed data into an INPUT function
IE.
INPUT "hi, what is your name?";username$

how do i take a variable, and center it?
Mathematics.

Code:
SCREEN 9
var$ = "centered bla"
max.length% = 80
len.var% = LEN(var$)
LOCATE , (max.length% - len.var%) \ 2: PRINT var$
that doesn't work, i really dont get it
That does work.

Screen width / 2 - text width / 2. It is not hard to figure out.
Of course it doesn't work...

If you're doing this:

Code:
INPUT "hi, what is your name?";username$
SCREEN 9
var$ = "centered bla"
max.length% = 80
len.var% = LEN(var$)
LOCATE , (max.length% - len.var%) \ 2: PRINT var$

:roll:
Actually, it should work fine. It's factoring, ya doof.

screenwidth / 2 - varlength / 2 =
.5 * screenwidth - .5 * varlength =
.5 * (screenwidth - varlength)
ghen, what SCREEN are you using? If you are using SCREEN 7 or SCREEN 13, then change

max.length% = 80

to

max.length% = 40

since these screens are only 40 characters wide.
sorry, i just started using q basic 2 days ago! Thanks
Quote:Of course it doesn't work...

If you're doing this:

Code:
INPUT "hi, what is your name?";username$
SCREEN 9
var$ = "centered bla"
max.length% = 80
len.var% = LEN(var$)
LOCATE , (max.length% - len.var%) \ 2: PRINT var$

:roll:

It doesn't, im getting the "illegal function call error" message. HELP PLEASE!
Code:
INPUT "What's your name ";a$
LOCATE ,40-LEN(a$)\2: PRINT a$
Pages: 1 2