Creating Tables?
Author |
Message |
Vissar
|
Posted: Thu Oct 12, 2006 10:03 am Post subject: Creating Tables? |
|
|
I'm in a programming class that uses nothing but Turing, something I have virtually no experiance with. I managed to catch onto SOME of the very basic concepts but my greater expertice is with html and other forms of web design, not programming.
My current mission is to create a "Report Card" type program that asks for classes and grades and displays them in a good looking way.
I was thinking of creating a talbe with the suject varriables on one side and the mark variable on the other side.
Is it possibl to make tables in Turing?
Also is it possible to get and/or put varriables with the font.draw feature? It seems to reject the line if a variable is put in it.
Any ideas greatly appreciated. |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
Tony

|
Posted: Thu Oct 12, 2006 11:47 am Post subject: (No subject) |
|
|
pseudo-tables can be generated with
code: |
put "text":width, "another"
|
where :width is an integer for the minimum width of the string preceeding it. It will not trancate the text, but will add enough spaces to reach that length, thus making aligned (table like) output possible.
I think there are also length(string) and repeat(string, num) functions that could come in handy, but you'd have to consult the reference file.
As for Font.Draw, it accepts string type only, and should say so in the error message if it doesn't work. If you have another type of variable you would like to display, you need to convert it to a string first.
will change 1 to "1"
code: |
Font.Draw(intstr(42), x, y, font_id, blue)
|
|
Tony's programming blog. DWITE - a programming contest. |
|
|
|
 |
neufelni
|
Posted: Thu Oct 12, 2006 3:15 pm Post subject: (No subject) |
|
|
You can't make tables in Turing like you do in HTML but you can create your own table using Draw.Box(x1, y1, x2, y2, colour), or Draw.Line(x1, y1, x2, y2, colour). To make a table you would do something like this.
code: | Draw.Box(100, 100, 200, 200, 7)
Draw.Line(150, 100, 150, 200, 7)
Draw.Line(100, 125, 200, 125, 7)
Draw.Line(100, 150, 200, 150, 7)
Draw.Line(100, 175, 200, 175, 7) |
And to output integer variables with Font.Draw you have to first convert the variable to a string, like this.
code: | Font.Draw(intstr(mark), 10, 10, fontID, 7) |
If you want to get input using Font.Draw, it is a bit more complicated. You have to get one letter at a time using a loop.
code: | View.Set ("noecho, nocursor") % this makes it so that you can't see the user's input in the normal font.
var letter : string (1)
var fullword : string := ""
var font : int := Font.New ("Arial:12")
loop
getch (letter)
cls
exit when letter = (KEY_ENTER)
if letter = (KEY_BACKSPACE) and length (fullword) > 0 then
fullword := fullword (1 .. length (fullword) - 1)
else
fullword := fullword + letter
end if
Font.Draw (fullword, 10, 10, font, 7)
end loop |
I don't haveTuring on this computer so this code is untested, so there may be some mistakes.
EDIT: There were a few mistakes in my code and they are now fixed. |
|
|
|
|
 |
BenLi

|
Posted: Thu Oct 12, 2006 3:39 pm Post subject: (No subject) |
|
|
Quote:
Also is it possible to get and/or put varriables with the font.draw feature? It seems to reject the line if a variable is put in it.
well if you're trying to output a integer or real with Font.Draw, you need to use intstr to make it a string |
|
|
|
|
 |
Vissar
|
Posted: Tue Oct 17, 2006 9:07 am Post subject: (No subject) |
|
|
What if the variable is already a string or a real? How do you display those with font.draw? |
|
|
|
|
 |
neufelni
|
Posted: Tue Oct 17, 2006 10:58 am Post subject: (No subject) |
|
|
If you want to display a string variable with Font.Draw, it is the same but without the intstr. To display a real number you use realstr rather than intstr:
code: |
var word : string := "Hello"
var num : real := 1234.56789
var font : int := Font.New("Arial:12")
Font.Draw(word, 10, 10, font, 7)
Font.Draw(realstr(num, 1), 10, 100, font, 7)
|
|
|
|
|
|
 |
|
|