Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Tue Dec 12, 2017 3:38 am
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: type of variable
PostPosted: Wed Dec 14, 2011 11:28 am 
Offline

Joined: Sun Oct 07, 2007 8:06 am
Posts: 25
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: type of variable
PostPosted: Wed Dec 14, 2011 11:54 am 
Offline
User avatar

Joined: Fri Nov 10, 2006 4:10 pm
Posts: 1855
Location: Michigan, USA
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. :)

_________________
Windows 8 x64
Windows XP Pro SP3
Ubuntu 11.04 via Virtual Box
RS Enterprise 2012r1.1

Programming Tutorials & Free Projects: http://www.JasonTheAdams.com
"Christianity has not been tried and found wanting; it has been found difficult and not tried." - G.K. Chesterton


Top
 Profile  
Reply with quote  
 Post subject: Re: type of variable
PostPosted: Wed Dec 14, 2011 12:19 pm 
Offline

Joined: Sun Oct 07, 2007 8:06 am
Posts: 25
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 ?


Top
 Profile  
Reply with quote  
 Post subject: Re: type of variable
PostPosted: Wed Dec 14, 2011 12:23 pm 
Offline
User avatar

Joined: Fri Nov 10, 2006 4:10 pm
Posts: 1855
Location: Michigan, USA
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

_________________
Windows 8 x64
Windows XP Pro SP3
Ubuntu 11.04 via Virtual Box
RS Enterprise 2012r1.1

Programming Tutorials & Free Projects: http://www.JasonTheAdams.com
"Christianity has not been tried and found wanting; it has been found difficult and not tried." - G.K. Chesterton


Top
 Profile  
Reply with quote  
 Post subject: Re: type of variable
PostPosted: Thu Dec 15, 2011 5:12 am 
Offline

Joined: Sun Oct 07, 2007 8:06 am
Posts: 25
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


Top
 Profile  
Reply with quote  
 Post subject: Re: type of variable
PostPosted: Mon Apr 23, 2012 6:09 am 
Offline

Joined: Thu Dec 01, 2011 2:13 pm
Posts: 288
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).

_________________
Mac OS X 10.3-10.8
Windows 2000 (I know it sucks)
Windows Server 2007

You want a bunch of new classes and web styles? realstudiodevspot.com (search there for Web Styles Plugin)
Folderitem is too hard? File Bin Class
I hate cows.


Top
 Profile  
Reply with quote  
 Post subject: Re: type of variable
PostPosted: Mon Apr 23, 2012 7:17 am 
Offline

Joined: Tue Feb 14, 2012 5:39 am
Posts: 99
Location: Austria
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.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group