aqConvert.VarToBool Method

Applies to TestComplete 14.72, last modified on April 22, 2021

Description

The VarToBool method converts the variant value specified by the V parameter to a Boolean value.

Declaration

aqConvert.VarToBool(V)

V [in]    Required    Variant    
Result Boolean

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

V

Specifies the variant value to be converted. V can be a Boolean, a number, a string representing a Boolean or a number, or a date/time value (see the Remarks section for details). Otherwise, an error occurs.

Result Value

The Boolean value to which the specified variant value has been converted.

Remarks

The table below lists numeric, string and date/time values that aqConvert.VarToBool can successfully convert to corresponding Boolean values.

Value Result
"True", "true", "TRUE", "trUE" etc True
"False", "false", "FALSE", "fAlsE" etc False
0, 0.0, 0.00 etc False
1, 2, 3 etc
-1, -2, -3 etc
0.1, 0.2, 0.3 etc
-0.1, -0.2, -0.3 etc
True
"0", "00", "0.0" etc False
"1", "2", "3" etc
"-1", "-2", "-3" etc
"0.1", "0.2", "0.3" etc
"-0.1", "-0.2", "-0.3" etc
True
00:00:00 False
00:00:01, 1/1/2008 etc True

If the method cannot convert the argument's value to a Boolean value, it will log an error.

Value Result
"A sample string" Error
"1.2.3" Error

Example

The following example demonstrates how you can convert variant values to Boolean values.

JavaScript, JScript

function VarToBoolExample()
{

 // Converting strings to Boolean values
 Log.Message(aqConvert.VarToBool("TRuE"));
 Log.Message(aqConvert.VarToBool("false"));
 Log.Message(aqConvert.VarToBool("0"));
 Log.Message(aqConvert.VarToBool("142"));
 Log.Message(aqConvert.VarToBool("-0.5"));
 
 // Converting numbers to Boolean values
 Log.Message(aqConvert.VarToBool(3.5));
 Log.Message(aqConvert.VarToBool(-3.5));
 Log.Message(aqConvert.VarToBool(0.0));
 
}

/*
The routine produces the following output:
True
False
False
True
True
True
True
False
*/

Python

def VarToBoolExample():
  # Converting strings to Boolean values
  Log.Message(aqConvert.VarToBool("TRuE"))
  Log.Message(aqConvert.VarToBool("false"))
  Log.Message(aqConvert.VarToBool("0"))
  Log.Message(aqConvert.VarToBool("142"))
  Log.Message(aqConvert.VarToBool("-0.5"))
  # Converting numbers to Boolean values
  Log.Message(aqConvert.VarToBool(3.5))
  Log.Message(aqConvert.VarToBool(-3.5))
  Log.Message(aqConvert.VarToBool(0.0))
  
# The routine produces the following output:
# True
# False
# False
# True
# True
# True
# True
# False

VBScript

Sub VarToBoolExample

 ' Converting strings to Boolean values
 Call Log.Message(aqConvert.VarToBool("TRuE"))
 Call Log.Message(aqConvert.VarToBool("false"))
 Call Log.Message(aqConvert.VarToBool("0"))
 Call Log.Message(aqConvert.VarToBool("142"))
 Call Log.Message(aqConvert.VarToBool("-0.5"))
 
 ' Converting numbers to Boolean values
 Call Log.Message(aqConvert.VarToBool(3.5))
 Call Log.Message(aqConvert.VarToBool(-3.5))
 Call Log.Message(aqConvert.VarToBool(0.0))
 
End Sub

' The routine produces the following output:
' True
' False
' False
' True
' True
' True
' True
' False

DelphiScript

function VarToBoolExample;
begin

 // Converting strings to Booleanvalues
 Log.Message(aqConvert.VarToBool('TRuE'));
 Log.Message(aqConvert.VarToBool('false'));
 Log.Message(aqConvert.VarToBool('0'));
 Log.Message(aqConvert.VarToBool('142'));
 Log.Message(aqConvert.VarToBool('-0.5'));
 
 // Converting numbers to Boolean values
 Log.Message(aqConvert.VarToBool(3.5));
 Log.Message(aqConvert.VarToBool(-3.5));
 Log.Message(aqConvert.VarToBool(0.0));
 
end;

{
The routine produces the following output:
True
False
False
True
True
True
True
False
}

C++Script, C#Script

function VarToBoolExample()
{

 // Converting strings to Boolean values
 Log["Message"]( aqConvert["VarToBool"]("TRuE") );
 Log["Message"]( aqConvert["VarToBool"]("false") );
 Log["Message"]( aqConvert["VarToBool"]("0") );
 Log["Message"]( aqConvert["VarToBool"]("142") );
 Log["Message"]( aqConvert["VarToBool"]("-0.5") );
 
 // Converting numbers to Boolean values
 Log["Message"]( aqConvert["VarToBool"](3.5) );
 Log["Message"]( aqConvert["VarToBool"](-3.5) );
 Log["Message"]( aqConvert["VarToBool"](0.0) );
 
}

/*
The routine produces the following output:
True
False
False
True
True
True
True
False
*/

See Also

VarToInt Method
VarToFloat Method
VarToStr Method
GetVarType Method
VarClear Method

Highlight search results