changing real type data to word type 
Author Message
 changing real type data to word type

I want to instruct the computer to delay 3 seconds minus the value of a
reaction time variable.  The problem is that the delay function is of
word type and the RT variable is of real type.  I've tried creating a
function to make this conversion, as follows:

function get_delay (RTvar : real) : word;
   begin
   get_delay:=RTvar;
   end;
But I still get the type mismatch error.  I also tried using an
undefined variable to take the value of the RT variable, but htat didn't
work either.  There must be an easier way!

THanks,
Jon



Wed, 18 Jun 1902 08:00:00 GMT  
 changing real type data to word type



Quote:
>I want to instruct the computer to delay 3 seconds minus the value of a
>reaction time variable.  The problem is that the delay function is of
>word type and the RT variable is of real type.  I've tried creating a
>function to make this conversion, as follows:
>function get_delay (RTvar : real) : word;
>   begin
>   get_delay:=RTvar;
>   end;
>But I still get the type mismatch error.  I also tried using an
>undefined variable to take the value of the RT variable, but htat didn't
>work either.  There must be an easier way!

>THanks,
>Jon

Just use the round function.
Hope this helps,
Jochen


Wed, 18 Jun 1902 08:00:00 GMT  
 changing real type data to word type

Quote:

> function get_delay (RTvar : real) : word;
>    begin
>    get_delay:=RTvar;
>    end;
> But I still get the type mismatch error.  I also tried using an
> undefined variable to take the value of the RT variable, but htat didn't
> work either.  There must be an easier way!

there are *two* easy ways:
get_delay:=round(RTvar);
get_delay:=trunc(RTvar);

of course you'll have to check if RTVar is in the 0..65536 range;

--
Otavio Exel /<\oo/>\



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. "word" data type

2. FPC and real data type

3. Real data type

4. Converting Data Types (Real <-> Integer)

5. Money field type same as Currency data type??

6. Change data type of colomn during execution

7. Change data types of a field programmatically

8. How to change a variables data type?

9. Dynamic Filter on TCustomADODataset where filter field data type change

10. Changing a Long Data Type To AutoIncrement

11. TASM data structures to Pascal data types

12. Variable Type Word

 

 
Powered by phpBB® Forum Software