Results 1 to 3 of 3

Thread: VBScript CSng() Type Mismatch

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140

    VBScript CSng() Type Mismatch

    Code:
    Dim sngFoo
        sngFoo = CSng(someVar)
    Am I the only one who thinks that the above code should set sngFoo to 0. or Null and not return a Type Mismatch error if someVar is not numeric?

    I guess I have to use this?

    Code:
    Dim sngFoo
        sngFoo = Null
    
    If IsNumeric(someVar) Then sngFoo = CSng(someVar)
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

  2. #2
    Fanatic Member punkpie_uk's Avatar
    Join Date
    Sep 2001
    Location
    UK
    Posts
    645
    VB Script always returns a type mismatch error if it doesnt like what you are doing. You could try

    Code:
    sngFoo = CSng(cInt(someVar))
    but I doubt that'll even work...
    SPREAD THE WORD!!! Are You Lee McCormick? Because I Am



    Lee M McCormick
    [email protected]

    Lee McCormick.com - Live
    Dynamically Webbed.com - In development but live

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2001
    Posts
    1,140
    I've never noticed if CInt() would return a Type Mismatch error, too. But nesting the CInt() in the CSng() will loose precision, as n.n would become n and then n..
    Travis, Kung Foo Journeyman
    As always, RTFM.

    WWW Standards: HTML 4.01, CSS Level 2, ECMA 262 Bindings to DOM Level 1, JavaScript 1.3 Guide and Reference
    Perl: Learn Perl, Llama, Camel, Cookbook, Perl Monks, Perl Mongers, O'Reilly's Perl.com, ActiveState, CPAN, TPJ, and use Perl;
    YBMS, but Mozilla doesn't.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width