Is (function): Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
JwellsNB (talk | contribs)
Add javascript snippet
Line 15: Line 15:
The Is functions return TRUE if a variable type corresponds to the function call, FALSE is returned otherwise. The required parameter, expression, is the variable whose type status is being determined.
The Is functions return TRUE if a variable type corresponds to the function call, FALSE is returned otherwise. The required parameter, expression, is the variable whose type status is being determined.


== Example ==
== Example (Basic) ==


<pre>
<pre>
Line 34: Line 34:
   End If
   End If
End Sub
End Sub
</pre>
== Example (JavaScript) ==
<pre>
// Is Functions Example
var TestVariable=function(x) {
  if (!Array.isArray) {
    Array.isArray = function (x) {
      return Object.prototype.toString.call(x) === "[object Array]";
    };
  }
  IsDate = function(x) {
    return (null != x) && !isNaN(x) && ("undefined" !== typeof x.getDate);
  };
  IsNumeric = function(n) {
    return !isNaN(parseFloat(n)) && isFinite(n);
  };
  if (Array.isArray(x)) {
    document.write(("The variable is an array.") + "<br>");
  } else if (IsDate(x) ) {
    document.write(("The variable is a date.") + "<br>");
  } else if (IsNumeric(x) ) {
    document.write(("The variable is a number.") + "<br>");
  }
}
var  Children=new Array(3), Chef, When;
TestVariable(Children);
Chef = 1;
TestVariable(Chef);
When = new Date();
TestVariable(When);
</pre>
</pre>



Revision as of 21:36, 27 May 2013

IsArray(expression)

IsDate(expression)

IsEmpty(expression)

IsNull(expression)

IsNumeric(expression)

IsObject(expression)

Description

The Is functions return TRUE if a variable type corresponds to the function call, FALSE is returned otherwise. The required parameter, expression, is the variable whose type status is being determined.

Example (Basic)

Rem Is Functions Example
Dim Children(3), Chef, When
TestVariable Children
Chef = 1
TestVariable Chef
When = Now
TestVariable When
Sub TestVariable(x)
  If IsArray(x) Then
    Print "The variable is an array."
  ElseIf IsDate(x) Then
    Print "The variable is a date."
  ElseIf IsNumeric(x) Then
    Print "The variable is a number."
  End If
End Sub

Example (JavaScript)

// Is Functions Example

var TestVariable=function(x) {
  if (!Array.isArray) {
    Array.isArray = function (x) {
      return Object.prototype.toString.call(x) === "[object Array]";
    };
  }

  IsDate = function(x) {
    return (null != x) && !isNaN(x) && ("undefined" !== typeof x.getDate);
  };

  IsNumeric = function(n) {
    return !isNaN(parseFloat(n)) && isFinite(n);
  };

  if (Array.isArray(x)) {
    document.write(("The variable is an array.") + "<br>");
  } else if (IsDate(x) ) {
    document.write(("The variable is a date.") + "<br>");
  } else if (IsNumeric(x) ) {
    document.write(("The variable is a number.") + "<br>");
  }
}

var  Children=new Array(3), Chef, When;
TestVariable(Children);
Chef = 1;
TestVariable(Chef);
When = new Date();
TestVariable(When);

Output

The variable is an array.
The variable is a number.
The variable is a date.

Related Items

TypeName, VarType