FormattedHeight - problems

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Traxgeek
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Wed Jan 09, 2013 10:11 am

FormattedHeight - problems

Post by Traxgeek » Wed Apr 10, 2013 8:24 am

Hi,

Seems a little basic but I'm missing something I think...

I'm trying to use the 'formattedheight' property for a field to set its required height after updating the field with some text. This is important to me because the field contains data of varying length and I'm trying (playing?) with adjustring the field height so that all the data may be seen without having to use a scroll bar.

So, I'm using a code line like :

Code: Select all

 
local nHt, nNextTop                                                     --just declare my vars
set the text of field "fldMyField" to "The quick brown fox jumped" & cr & "over that darn lazy dog"    --put some text in the field
--set the text of field "fldMyField" to  "The fox jumped over the dog"  --or put some other text in the field
put the formattedheight of field "fldMyText" into nHt                   --get the height of MyField with the varying texts in it
if nHt > the height of field "fldMyText" then                           --check to see if the text is 'too tall' for the standard field height
   set the height of field "fldMyField" to nHt                          --change the height of fldMyField
   put the top of field "fldMyField" into nNextTop                      --get the 'Y' loc of the field and then...
   add nHt to nNextTop                                                  --add the new required height to it
   add 6 to nNextTop                                                    --add any height offset / spacing required between successive fields
else
   put 0 into nNextTop                                                  --Not, no change in height, therefore, no change required to next field top
end if
Seems simple enough and, indeed works well as long as the script using the command resides on the card the script is handling...

However, my problem :
I have a generic / stack-side handler that populates the card (with fldMyField" on it) which is passed the name of the card to update and the DataBase ID for the data records to add...

Code: Select all

Populate_Card sCard, nID
In this case, the line

Code: Select all

put the formattedheight of field "fldMyText" into nHt 
reports zero... Aha - noted... I need to add the name of the card on which the filed resides... so the code line changes to :

Code: Select all

put the formattedheight of field "fldMyText" of card sCard into nHt 
Still doesn't work ! Baffled...

If I enclose my target with brackets like :

Code: Select all

put the formattedheight of (field "fldMyText" of card sCard) into nHt 
I get some very strange, comma separtated, numbers in nHT but none seem to bear any resemblance to the formattedheight I'd like...

If I try, on a card-side script (a script that resides on the card it pertains to - rather than a stack-side script which then references the card)

Code: Select all

put the formattedheight of field "fldMyText" of this card into nHt 
I get the correct result. I also get the correct result with this card-side script :

Code: Select all

put "crdMyCard" into sCard
put the formattedheight of field "fldMyText" of sCard into nHt 
So... I'm stumped... I've also tried brackets in various other locations etc but all to no avail.
It seems that the code lines work when the script resides on the card it pertains to (and even accepts all the additional 'on card...' statements but refuses (for me) to run on a stack-side srcipt.

Anyone able to shed some light on whether this is this a bug with LC :? or me :evil: ?
Better still, is there a work-around / way to fix my problem ?

Thanks.

Regards.
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: FormattedHeight - problems

Post by bn » Wed Apr 10, 2013 9:11 am

Hi Traxgeek,

from the dictionary:
Value:
The formattedHeight of an object is a positive integer. The object must be on the current card of an open stack.
Livecode has to render the text to be able to report the formattedHeight.

The workaround is to go the the card where your field is and get the formattedHeight and go back to your original card

Code: Select all

       
         lock screen
         push card
         go card "sCard"
         put the formattedHeight of field "fldMyField" into nHT
         pop card
         unlock screen
kind regards

Bernd

Traxgeek
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 281
Joined: Wed Jan 09, 2013 10:11 am

Re: FormattedHeight - problems

Post by Traxgeek » Thu Apr 11, 2013 8:43 am

Bernd, I'm a dope !
Many, many thanks. I promise I did read the dictionary (more than once, I may add) ! but, quite obviously, not well enough :oops:
Again, thanks a mil.
Regards.
I'm 'getting there'... just far too slowly !
Mac (Siera) and PC (Win7)
LiveCode 8.1.2 / 7.1.1

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Re: FormattedHeight - problems

Post by bn » Thu Apr 11, 2013 8:59 am

Hi Traxgeek,
Bernd, I'm a dope !
don't feel bad, this happens to me all the time,
well, I could use that as my tag line :)
Kind regards
Bernd

Post Reply