comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Testing validity of numerical content of a string
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Testing validity of numerical content of a string [message #51821 is a reply to message #51744] Thu, 07 December 2006 10:18 Go to previous messageGo to previous message
Brian Larsen is currently offline  Brian Larsen
Messages: 270
Registered: June 2006
Senior Member
Excellent solution. I haven't played with on_ioerror but certainly
will now.

Funny how you get stuck in a rut of how you normally do things even if
its not the best, in fact probably never the best way :)

Brian



mgalloy@gmail.com wrote:
> Sven Geier wrote:
>> In a pinch one might just force the conversion and catch any resulting
>> error-messages with ON_ERROR -- that's ugly, but might be a lot easier than
>> trying to parse strings...
>
> So here's some code that does that:
>
> function validate_numeric, value
> compile_opt strictarr
>
> on_ioerror, badValue
>
> f = float(value)
> return, 1B
>
> badValue: return, 0B
> end
>
> The odd thing about this is what IDL will do without complaining. IDL
> will do this without any error:
>
> IDL> help, float('0.0hello5')
> <Expression> FLOAT = 0.00000
>
> but draws the line at:
>
> IDL> help, float('hello5')
> % Type conversion error: Unable to convert given STRING to Float.
> % Detected at: $MAIN$
> <Expression> FLOAT = 0.00000
>
> Mike
> --
> www.michaelgalloy.com
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: creating MPEG in IDL
Next Topic: changing widget_button values can be very slow

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Fri Nov 28 14:45:58 PST 2025

Total time taken to generate the page: 0.48092 seconds