Re: test if a string is a valid 'number'?



"It works" is one of the weakest justifications for bad code I have had to put up with in
my career. Not only is the solution baroque, horribly inefficient, and non-portable, to
start with its major flaws, but is completely unnecessary because you can write the FSM
parser in a fairly minimal amount of effort, vastly less effort than was required to
conjure this off-the-wall solution!

joe
On Wed, 30 May 2007 13:43:16 -0700, "Ashot Geodakov" <a_geodakov@xxxxxxxxxxxxxxxxxx>
wrote:

"Doug Harrison [MVP]" <dsh@xxxxxxxx> wrote in message
news:88or53ddfip8v2bcdud4jqh8m4lge0q1lg@xxxxxxxxxx
On Wed, 30 May 2007 13:28:16 -0700, "Ashot Geodakov"
<a_geodakov@xxxxxxxxxxxxxxxxxx> wrote:

#include <windows.h>

typedef long ( *ISNUMERIC )( VARIANT* );

BOOL IsNumeric( LPTSTR szString )
{
HINSTANCE hinstLib;
ISNUMERIC ProcAdd;

hinstLib = LoadLibrary( TEXT( "C:\\Program Files\\Common
Files\\Microsoft Shared\\VBA\\VBA6\\vbe6.dll" ) );

if( hinstLib != NULL )
{
long lNumeric = 0;
ProcAdd = (ISNUMERIC)GetProcAddress( hinstLib, "rtcIsNumeric" );

if( NULL != ProcAdd )
{
VARIANT vtExpression;
vtExpression.vt = VT_BSTR;
vtExpression.bstrVal = SysAllocString( szString );
__asm
{
lea eax, [vtExpression]
push eax
call (ProcAdd)
mov lNumeric, eax
}
SysFreeString( vtExpression.bstrVal );
}

FreeLibrary( hinstLib );
return ( lNumeric != 0 );
}
else return FALSE;
}

void main( void )
{
BOOL bNumeric = IsNumeric( TEXT( "1245789.00" ) );
bNumeric = IsNumeric( TEXT( "sdf1245789.00" ) );
bNumeric = IsNumeric( TEXT( "+234.43E-24" ) );
bNumeric = IsNumeric( TEXT( "12,234,345.00" ) );
bNumeric = IsNumeric( TEXT( "sdf1245789.00" ) );
}

Shirley you're just kiddin' around.

Why? It works...

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages


Loading