[futurebasic] Re: [FB] Get[ing] Control Values

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : January 2008 : Group Archive : Group : All Groups

From: Bernie <fblist.bw@...>
Date: Wed, 23 Jan 2008 10:21:45 +0000
Max wrote:

>> I hate to ask without trying my best to find the answer on my own  
>> but I have pulled my hair out looking for an example of how to get  
>> the value of a control [edit field] using code like that below.
>
> I found that the following does the trick.
> ctlText = FN ButtonTextString$( _efFrequency )
> But, I would still like to use the other method if I could.
> Thanks for any suggestions.
>


I have a history of misunderstanding questions, so there's a good  
chance this is another.

'------------
// Three ways to get the contents of an edit text control

include "Tlbx HIView.incl"

// CFString.h
toolbox fn CFStringGetDoubleValue( CFStringRef str ) = double/* Skips  
whitespace; returns 0.0 on error */

dim as Str255 s
dim as Rect r
dim as double value
dim as ControlRef c
dim as CFStringRef @ string
dim as long @ actual
dim as OSErr err

window 1

SetRect( r, 150, 23, 300, 39 )
appearance button 1,,,,,, @r, _kControlEditUnicodeTextProc
c = button&(1)
s = "12.345"
err = fn SetControlData( c, _kControlEditTextPart,  
_kControlEditTextTextTag, s[0], @s[1] )

s[0] = 0

// GetControlData - Pascal string
err = fn GetControlData( c, _kControlEditTextPart,  
_kControlEditTextTextTag, 255, @s[1], @actual )
if ( actual > 255 ) then s[0] = 255 else s[0] = actual
print val(s)

// GetControlData - CFString
err = fn GetControlData( c, _kControlEditTextPart,  
_kControlEditTextCFStringTag, sizeof(CFStringRef), @string, #0 )
value = fn CFStringGetDoubleValue( string )
print value

// HIViewCopyText - CFString - [requires OS X 10.4 or later]
string = fn HIViewCopyText( c )
long if ( string )
value = fn CFStringGetDoubleValue( string )
print value
CFRelease( string )
end if

do
HandleEvents
until gFBQuit
'------------

Bernie