# Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
 It is currently Wed Jan 16, 2019 9:55 am

 All times are UTC - 5 hours

 Page 1 of 1 [ 7 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: type of variablePosted: Wed Dec 14, 2011 11:28 am

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

 Post subject: Re: type of variablePosted: Wed Dec 14, 2011 11:54 am

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

 Post subject: Re: type of variablePosted: Wed Dec 14, 2011 12:19 pm

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

 Post subject: Re: type of variablePosted: Wed Dec 14, 2011 12:23 pm

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

 Post subject: Re: type of variablePosted: Thu Dec 15, 2011 5:12 am

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

 Post subject: Re: type of variablePosted: Mon Apr 23, 2012 6:09 am

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

 Post subject: Re: type of variablePosted: Mon Apr 23, 2012 7:17 am

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

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 7 posts ]

 All times are UTC - 5 hours

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

Search for:
 Jump to:  Select a forum ------------------ General    General    Getting Started    Networking    Databases    Visual Basic to REAL Studio Conversion    Games    Plugins    Tips    Web Control SDK Platform Specific    Windows    Macintosh    Linux    Web Other Topics    Announcements    Off-Topic    Third Party Add-ons