data type

If it's in a frame, you can use the data-type attribute.

def var a as char.
form a with frame f1.
display a:data-type.

You can also use it fairly generically:

def var a as char.
def var b as char.
form a b with frame f1.

on leave of a, b in frame f1 run p_self (input self:handle).
procedure p_self:
def input param inp_handle as widget-handle no-undo.
case self:data-type:
when "character" then .
when "integer" then .
end case.
end procedure.
 
Datatype is just an attribute.
The variable does NOT have to be in a frame, as suggested. If you wish to DISPLAY value then that must. Though you can access the value (data) from anywhere, at any time. It is simply an attribute. You then may wish to perform action on the type and not actually display it.
 
is it possible to find data type of a variable.
Look in the source-code :awink:
It is posible to find the data type of a field from a table or Temp-table. But AFAIK there is no way to find out the data-type of a variable in the code.
Is there any situation to think of that you want to dynamically know the data-type of a variable?
In my opinion you should know in your program which data-type a variable has.

Regards,

Casper.
 
Look in the source-code :awink:
It is posible to find the data type of a field from a table or Temp-table. But AFAIK there is no way to find out the data-type of a variable in the code.
Is there any situation to think of that you want to dynamically know the data-type of a variable?
In my opinion you should know in your program which data-type a variable has.

Regards,

Casper.

Actually i want to pass a variable (that may be any type) to a function. depanding on the data-type I want to perform a task.
 
Datatype is just an attribute.
The variable does NOT have to be in a frame, as suggested. If you wish to DISPLAY value then that must. Though you can access the value (data) from anywhere, at any time. It is simply an attribute. You then may wish to perform action on the type and not actually display it.

Well, V9 Help says:

"Applies To: Browse column, Buffer-field Object Handle, Combo-box, Editor, Fill-in, Radio-set, Rectangle, Selection-list, Slider, Text, Toggle-box"

With the exception of buffer-field they have to be in a frame to enable you to access the data-type attribute, otherwise it comes up with an error "Could not find <variable> in a frame. Try qualifying the reference with an IN FRAME phrase. (3566)".

Buffer-field doesn't really apply as the question asked about a variable.

I've got around the issue in the past by defining a temp-table with all the variables I need to access as fields in the temp-table and then creating a single record. That way I can use things like data-type in the buffer-field object. It also means that I can ASSIGN values to "variables" without using the ASSIGN statement simply by using the BUFFER-VALUE attribute.
 
Actually i want to pass a variable (that may be any type) to a function. depanding on the data-type I want to perform a task.

Since you have to define the input/output types in a function, you can only really pass a handle to the function using that.

You could define your variables as fields in a temp-table, as stated above, and pass a handle into the function.

Alternatively, if the variable is displayed in a frame, then passing the handle into a function will work, using SELF:HANDLE or variable:handle.

function f_test returns char (inp_handle as widget-handle):
def var testreturn as char no-undo.
def var datatypelist as char initial
"Buffer-field,Combo-box,Editor,Fill-in,Radio-set,Rectangle,Selection-list,Slider,Text,Toggle-box".
if lookup(inp_handle:type,datatypelist) > 0 then
case inp_handle:data-type:
when "integer" then testreturn = "integer".
when "decimal" then testreturn = "decimal".
otherwise testreturn = inp_handle:data-type + " is not a number".
end case.
return testreturn.
end function.

def var a as char.
form a with frame f1.
display f_test (a:handle in frame f1) form "x(30)".


But, you could pass the variable as a string with another parameter stating type.

def var a as char.
def var b as int.
def var c as dec.

function f_test returns char (inp_value as char, inp_type as char):
case inp_type:
when "integer" then .
when "decimal" then .
end case.
end function.

message
f_test (a,"character")
f_test (string (b),"integer")
f_test (string (c),"decimal")
view-as alert-box.
 
Back
Top