realbasic-nug
[Top] [All Lists]

Re: Graphics.Stringwidth to integer

To: Tim Jones <tjmac@tolisgroup.com>
Subject: Re: Graphics.Stringwidth to integer
From: Joe Huber <joehuber@talasoft.com>
Date: Mon, 30 Jun 2008 21:02:08 -0700
Authentication-results: mx.google.com; spf=neutral (google.com: 74.124.194.228 is neither permitted nor denied by best guess record for domain of realbasic-nug-bounces@lists.realsoftware.com) smtp.mail=realbasic-nug-bounces@lists.realsoftware.com
Cc: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Delivered-to: listarchive@realsoftware.com
In-reply-to: <FD67C277-83DC-4F7E-8565-43FEF80C82B7@tolisgroup.com>
References: <FD67C277-83DC-4F7E-8565-43FEF80C82B7@tolisgroup.com>
Reply-to: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Sender: realbasic-nug-bounces@lists.realsoftware.com
Tim

You shouldn't need to even cast it at all. RB has autoconversion between numeric types, so you can just assign a double to an integer and RB will automatically truncate the decimal part for you. This will work fine.

   Me.width = Graphics.Stringwidth(thestring)


Alternatively you may want to use the Round function to minimize the truncation error.

   Me.Width = Round(Graphics.Stringwidth(thestring))


BTW Thanks for reminding me that StringWidth now returns a double.

Regards,
Joe Huber



Hi Folks,

If a function returns a Double, but need I an integer, shouldn't I be able to simply cast the result of a call that returns a double to an integer?

  Me.Width = Integer(Graphics.Stringwidth(thestring))

The compiler informs me that it "Expected Int32, but got Double". Isn't that supposed to be resolved by the cast to Integer?

A slightly confused,
Tim


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>


<Prev in Thread] Current Thread [Next in Thread>