How to make the text is right-justified?
Author |
Message |
8749236
|
Posted: Sun Feb 20, 2011 9:58 am Post subject: How to make the text is right-justified? |
|
|
What is it you are trying to achieve?
I'm trying to make the text is start from right side, which is right-justified...
What is the problem you are having?
the problem i have is i don't know how to make the text right-justified
Describe what you have tried to solve this problem
i have tried the way the Turing Online Manual told me but it is not working..
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
This is the program i need make it right-justified..
Turing: |
/*
2011-02-17 Thursday
Chapter 12 Excerise
*/
% declaring variables or constants
var file : int
var words : string
var count : int := 0
% open the file
open : file, "NewText.txt", get
assert file > 0
loop
% get the words from file
get : file, skip
exit when eof (file )
get : file, words : 60 % only get 60 character once..
% output the words
put words, " "
end loop
|
Please specify what version of Turing you are using
Turing 4.1.1 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Zren
|
Posted: Sun Feb 20, 2011 12:23 pm Post subject: RE:How to make the text is right-justified? |
|
|
Turing: |
% Words are written starting from the left,
% so we need to find the offset location for
% where to start writing our line.
var Width := 60
var Length := 5
var Start := Width - Length
% Useful functions
put maxcol
put length("mighty")
locate(5, 5)
put "bleh"
|
|
|
|
|
|
|
8749236
|
Posted: Mon Feb 21, 2011 11:06 pm Post subject: RE:How to make the text is right-justified? |
|
|
en, tried, not working properly, the second line replaced the first line.. |
|
|
|
|
|
Zren
|
Posted: Mon Feb 21, 2011 11:31 pm Post subject: RE:How to make the text is right-justified? |
|
|
Then you need to remember which row your writing to, and increment it as you write a line.
Line 1: Dad
Line 2: Jeff
Line 3: Donald
locate(row, column) |
|
|
|
|
|
unoho
|
Posted: Tue Feb 22, 2011 11:28 am Post subject: RE:How to make the text is right-justified? |
|
|
i had a similar assignment where we had to make right, left, center and justify. Note that i did it in C++, so it might or might not be same approach.
so input the max number of character per line and put it in a temporary string. then take the length of the line and using a forloop, u would just print extra white space at the beginning.
Now you might ask, how would i know how many spaces i need at the front. That is the number of max characters - length of the string on that line. |
|
|
|
|
|
TokenHerbz
|
Posted: Tue Feb 22, 2011 4:20 pm Post subject: RE:How to make the text is right-justified? |
|
|
You can put these into more function programing functions/procs to use. but I would suggest using Font.Draw
Turing: |
var font : int := Font.New("serif:12") %%a basic font to use
%%we need some strings to output right...
var string1 : string := "This will be Left Side"
var string2 : string := "This will be the Center Side!!"
var string3 : string := "This is Right Side"
%%The approach, Draw.Font displays a string with a type of font/size and color
%%And it has the ability to draw it where you want it to...
%%we can also see how long the font is, and use that info to place it correctly
var fontWidth : int := Font.Width(string1,font )
%%this sizes up the font size with the length of the string for a total width
%%lets now place string 1 on the "LEFT SIDE"
Font.Draw(string1, 0, 300,font, red)
%%Font.Draw(string,x,y,fontID,color)
%%Note how we didnt have to get the font width of the left axis becuase
%we already know that it starts at the 1 border and draws right...
%%but we need to use this info for the other 2!!! Lets try that now
%% % Reset Font width for right string!!!
%% %Font draw (stringX, xpos, ypos, fontID, colr)
%%The math to note %%maxx div 2 = center screen then want to minus 1/2 width.
%% % Reset Font width for right string!!!!
%% %Font draw (stringX, xpos, ypox, fontID, colr)
%%again math to note, We want to draw right side so we
%%maxx - length of the string with font (width).
%%maxx is the max number of pix in your screen horizontally. maxy is vert
|
|
|
|
|
|
|
|
|