Core Function GetVarType

From Sputnik Wiki
(Difference between revisions)
Jump to: navigation, search
(Example)
m (1 revision)
 
(4 intermediate revisions by one user not shown)
Line 17: Line 17:
 
Returns the common type of a variable as a numeric value types are:
 
Returns the common type of a variable as a numeric value types are:
 
<pre>
 
<pre>
[CODE] [TYPE] [@MACRO]
+
[TYPE] [@MACRO]
0 NULL @typeNULL
+
NULL @typeNULL
1 BOOL @typeBOOL
+
BOOL @typeBOOL
2 CHAR @typeCHAR
+
CHAR @typeCHAR
3 BYTE @typeBYTE
+
BYTE @typeBYTE
4 SBYTE @typeSBYTE
+
SBYTE @typeSBYTE
5 INT16 @typeINT16
+
INT16 @typeINT16
6 INT32 @typeINT32
+
INT32 @typeINT32
7 INT64 @typeINT64
+
INT64 @typeINT64
8 UINT16 @typeUINT16
+
UINT16 @typeUINT16
9 UINT32 @typeUINT32
+
UINT32 @typeUINT32
10 UINT64 @typeUINT64
+
UINT64 @typeUINT64
11 FLOAT @typeFLOAT
+
FLOAT @typeFLOAT
12 DOUBLE @typeDOUBLE
+
DOUBLE @typeDOUBLE
13 STRING @typeSTRING
+
STRING @typeSTRING
14 REFERENCE @typeREFERENCE
+
BINARY @typeBINARY
15 ARRAY @typeARRAY
+
INTPTR @typeINTPTR
16 OBJECT @typeOBJECT
+
UINTPTR @typeUINTPTR
17 ERROR @typeERROR
+
REFERENCE @typeREFERENCE
 +
ARRAY @typeARRAY
 +
OBJECT @typeOBJECT
 +
ERROR @typeERROR
 
</pre>
 
</pre>
  
Line 45: Line 48:
  
 
Checking as numeric
 
Checking as numeric
 
<syntaxhighlight lang="sputnik">
 
$a = "My value";
 
 
if( GetVarType($a) == 12 ) // Double
 
{
 
}
 
 
switch( GetVarType($a) )
 
{
 
case 10: // UInt64
 
{
 
}
 
break;
 
case 12: // Double
 
{
 
}
 
break;
 
}
 
</syntaxhighlight>
 
  
 
Checking using @ Macro of the numeric
 
Checking using @ Macro of the numeric

Latest revision as of 12:37, 14 June 2015

GetVarType( $variable )

Contents

Description

Get the common type of a variable

Parameters

variable

The variable to check.

Return Value

Returns the common type of a variable as a numeric value types are:

[TYPE]		[@MACRO]
NULL		@typeNULL
BOOL		@typeBOOL
CHAR		@typeCHAR
BYTE		@typeBYTE
SBYTE		@typeSBYTE
INT16		@typeINT16
INT32		@typeINT32
INT64		@typeINT64
UINT16		@typeUINT16
UINT32		@typeUINT32
UINT64		@typeUINT64
FLOAT		@typeFLOAT
DOUBLE		@typeDOUBLE
STRING		@typeSTRING
BINARY		@typeBINARY
INTPTR		@typeINTPTR
UINTPTR		@typeUINTPTR
REFERENCE	@typeREFERENCE
ARRAY		@typeARRAY
OBJECT		@typeOBJECT
ERROR		@typeERROR

Remarks

None.

Example

Checking as numeric

Checking using @ Macro of the numeric

$a = "My value";
 
if( GetVarType($a) == @TypeDouble) // Double
{
}
 
switch( GetVarType($a) )
{
	case @TypeUInt64: // UInt64
	{
	}
	break;
	case @TypeDouble: // Double
	{
	}
	break;
}

Some other ways to test a variables type

if( $a Is Double) // $a is a Double
{
}
 
if( $a IsNot Double) // $a is NOT a Double
{
}
 
if( $a ~~ Double) // $a is a Double
{
}
 
if( $a !~ Double) // $a is NOT a Double
{
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox