Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Simple question about fonts
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
nmr123321




PostPosted: Tue Jan 24, 2006 9:25 pm   Post subject: Simple question about fonts

code:

var font1 : int
var fontSize : int
for i : 1 .. 25
    font1 := Font.New ("Arial:fontSize:bold")
    Font.Draw ("Hello", maxx div 2, maxy div 2, font1, red)
    delay (100)
    Font.Draw ("Hello", maxx div 2, maxy div 2, font1, white)
    fontSize := fontSize + 1
end for

Is it possible to replace the size in a Font.New statement with a variable?
any help will be appreciated
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Tue Jan 24, 2006 9:29 pm   Post subject: (No subject)

Sure it is. In this case, you've considered 'fontSize' as a string and not a variable.
- "fontSize" vs. fontSize
You'll have to catenate the value of 'fontSize' to the rest of the string.
So, for instance:
code:

var temp : string := "#"
put "a+temp"   %--> a+temp
put "a" + temp %--> a#

See the difference?

- type-casts
Right now, you have fontSize as an int. To catenate, you have to have all types the same. You could consider redeclaring fontSize as a string instead, or you could just type-cast it. E.g.
code:

put 1, " is a number"
put intstr(1) + " is actually a string"

See the difference? strint() and intstr() are useful, very (simple, acronymical names, too).

Post up your code when you're done so we can see how well you fared.
nmr123321




PostPosted: Tue Jan 24, 2006 9:49 pm   Post subject: (No subject)

never seen this before, thanks .But do i put this instr(fontSize)+' outside the font statement. I am getting this error
Bad font size'instr(fontSize)+' in font selection string

code:

var font1 : int
var fontSize : int:=10

for i : 1 .. 10
   
    font1 := Font.New ("Arial:intstr (fontSize)+")
    Font.Draw ("Hello", maxx div 2, maxy div 2, font1, red)
    delay (100)
    Font.Draw ("Hello", maxx div 2, maxy div 2, font1, white)
    fontSize := fontSize + 1
end for



[/code]
Clayton




PostPosted: Wed Jan 25, 2006 8:22 am   Post subject: (No subject)

you dont put the + after your intstr(fontSize), you put that before instr(fontSize), then close the brackets. see if thats wat your prob is
Clayton




PostPosted: Wed Jan 25, 2006 8:23 am   Post subject: (No subject)

also close the quotes befor your variable otherwise turing wont recognize fontSize as a variable
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: