Real Software Forums
http://forums.realsoftware.com/

type of variable
http://forums.realsoftware.com/viewtopic.php?f=21&t=41832
Page 1 of 1

Author:  carmine [ Wed Dec 14, 2011 11:28 am ]
Post subject:  type of variable

Hi everyone,
How I can to define the variable's type ?
Exist a command or function to do this ?
For example, for a integer variable, I would:

type(a) -> integer

thanks.
bye.

Author:  Jason_Adams [ Wed Dec 14, 2011 11:54 am ]
Post subject:  Re: type of variable

I highly recommend reading the User's Guide.

But the syntax for a variable is: Dim VarName As VarType

For example:
Dim MyInt As Integer
Dim Name As String
Dim Choice As Boolean


Hope this helps. :)

Author:  carmine [ Wed Dec 14, 2011 12:19 pm ]
Post subject:  Re: type of variable

Jason_Adams wrote:
I highly recommend reading the User's Guide.

But the syntax for a variable is: Dim VarName As VarType

For example:
Dim MyInt As Integer
Dim Name As String
Dim Choice As Boolean


Hope this helps. :)


ok.
If I have a array of number, but I dont know if they are integer or double, how I can to do ?

Author:  Jason_Adams [ Wed Dec 14, 2011 12:23 pm ]
Post subject:  Re: type of variable

Go with Double, as a Double can handle and Integer, but an Integer cannot handle a Double:

Dim Db As Double
Dim Int As Integer

Db = 20 // Works
Db = 20.01 // Works

Int = 20 // Works
Int = 20.01 // Breaks

Author:  carmine [ Thu Dec 15, 2011 5:12 am ]
Post subject:  Re: type of variable

Jason_Adams wrote:
Go with Double, as a Double can handle and Integer, but an Integer cannot handle a Double:

Dim Db As Double
Dim Int As Integer

Db = 20 // Works
Db = 20.01 // Works

Int = 20 // Works
Int = 20.01 // Breaks


No. I resolved.
If I have a variant type, by "vartype" command I can know the variable's type.
For example:

vartype(Double) -> 5
vartype(array of Boolean) -> 4107

bye

Author:  NaNdummy [ Mon Apr 23, 2012 6:09 am ]
Post subject:  Re: type of variable

if myvariable isa integer then
mycode 1
else
mycode 2
end if

If you want something like getting it in a string, also I search a solution for that (eg. catching a runtime exception with the exception statement and displaying its name in a msgbox).

Author:  arthofer [ Mon Apr 23, 2012 7:17 am ]
Post subject:  Re: type of variable

You would need a small function:
Function VarType(val as Variant) As Integer
Return val.Type
End Function


This returns you a TypeCode for the passed Variable.

Quoted from the Language reference:
Quote:
Variant.Type
From Real Software Documentation

MethodVariant.Type ( ) As Integer
Returns an Integer, indicating the data type of the Variant. The values of each data type are given in the table in the Notes section of the VarType function.

Notes
If the Variant is an array, then Type returns TypeArray logically OR'ed with the array element type. You can get the element type by calling ArrayElementType.

An array of Dates will be designated as an array of Objects.

If the Variant is not Nil, it provides the same functionality as the VarType global function. You can use the Variant class constants instead of the integer values to determine the data type. The names are listed as Class Constants on the Variant page.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/