IsNumeric
IsNumeric(expr)
returns true
if expr
can be evaluated as a numerical value.
add-type -assembly Microsoft.VisualBasic
[Microsoft.VisualBasic.Information]::IsNumeric( 42 ) # True
[Microsoft.VisualBasic.Information]::IsNumeric( 42.1 ) # True
[Microsoft.VisualBasic.Information]::IsNumeric(" 42.1" ) # True
[Microsoft.VisualBasic.Information]::IsNumeric(" 42.1" ) # True
[Microsoft.VisualBasic.Information]::IsNumeric(" 42.1 xyz") # False
[Microsoft.VisualBasic.Information]::IsNumeric( $true ) # True
[Microsoft.VisualBasic.Information]::IsNumeric( $false ) # True
$comObj = [System.Runtime.InteropServices.Marshal]::GetActiveObject('Excel.Application')
#
# Adding the Micrsoft.VisualBasic.Information type so that we can use its TypeName() function
#
add-type -assemblyName Microsoft.VisualBasic
#
# Alternatively, adding it with the path to the DLL:
# add-type -path 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Microsoft.VisualBasic.dll'
[Microsoft.VisualBasic.Information]::TypeName($comObj.worksheets(1).shapes(1))
#
# Creating an «alias» for the namespace:
#
$vbi = [Microsoft.VisualBasic.Information]
$vbi::TypeName($comObj.selection)
Instead of using a variable
$vbi
to refer to a the
Microsoft.VisualBasic.Information
type, it also possible to
add a type accelerator for this type (so that the
TypeName()
can be invoked like so
[vbi]::TypeName()
)