Alpha Video Training
Results 1 to 7 of 7

Thread: Can you confirm expression evaluation error?

  1. #1
    VAR csda1's Avatar
    Real Name
    Ira J Perlow
    Join Date
    Apr 2000
    Location
    Boston, Massachusetts, USA
    Posts
    3,530

    Default Can you confirm expression evaluation error?

    Can you confirm these results in expression evaluation in any version of A5? I can't think of any time an expression evaluation error was as simple as this, with straightforward functions failing like this. It happens in a5v8 through a5v10 and I suspect all earlier versions as well.
    text="abcdefg"

    i=3

    ?asc(substr(text,i,1),.t.)+1
    ERROR: Argument is incorrect data type

    ?1+asc(substr(text,i,1),.t.)
    = 100
    Thanks!
    Regards,

    Ira J. Perlow
    Computer Systems Design


    CSDA A5 Products
    New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
    CSDA Barcode Functions

    CSDA Code Utility
    CSDA Screen Capture



  2. #2
    "Certified" Alphaholic
    Real Name
    Mike Christensen
    Join Date
    Nov 2005
    Location
    Michigan U.P.
    Posts
    5,937

    Default Re: Can you confirm expression evaluation error?

    Hi Ira,
    Using v8, I get the same results. Using eval it comes out fine though...odd.
    Code:
    text="abcdefg"
    dim i as n
    i=3
    ?eval("asc(substr(text,i,1),.t.)")+1
    = 100
    Mike
    __________________________________________
    It is only when we forget all our learning that we begin to know.
    It's not what you look at that matters, it's what you see.
    Henry David Thoreau
    __________________________________________




  3. #3
    "Certified" Alphaholic Lance Gurd's Avatar
    Real Name
    Lance Gurd
    Join Date
    Jun 2005
    Location
    Southampton, UK
    Posts
    1,445

    Default Re: Can you confirm expression evaluation error?

    Ira,

    I get the same and have narrowed it down to the positive argument in the asc() function. Take that out and it works. Strange!

  4. #4
    VAR csda1's Avatar
    Real Name
    Ira J Perlow
    Join Date
    Apr 2000
    Location
    Boston, Massachusetts, USA
    Posts
    3,530

    Default Re: Can you confirm expression evaluation error?

    Hi Lance,

    [quote=Lance Gurd;509878]I get the same and have narrowed it down to the positive argument in the asc() function. Take that out and it works. Strange!/quote]

    Alpha evaluates an expression from the right. That is why right side portions of expression terms are related to the problem. Simplifying the failure, it is related to use of the 2nd argument in asc().
    ?asc("a",.f.)+1
    ERROR: Argument is incorrect data type
    ?asc("a",.t.)+1
    ERROR: Argument is incorrect data type
    ?asc("a",.t.)
    = 97
    ?asc("a",.f.)
    = 97
    ?asc("a")+1
    = 98
    My guess is that the "C" code that asc() is written in probably messes up the xbasic stack when used with the 2 arguments.
    Regards,

    Ira J. Perlow
    Computer Systems Design


    CSDA A5 Products
    New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
    CSDA Barcode Functions

    CSDA Code Utility
    CSDA Screen Capture



  5. #5
    "Certified" Alphaholic
    Real Name
    Mike Christensen
    Join Date
    Nov 2005
    Location
    Michigan U.P.
    Posts
    5,937

    Default Re: Can you confirm expression evaluation error?

    So Ira....Why, in your opinion, does it work when adding the numeric prior instead of after? And why does it work regardless when using Eval()?
    Mike
    __________________________________________
    It is only when we forget all our learning that we begin to know.
    It's not what you look at that matters, it's what you see.
    Henry David Thoreau
    __________________________________________




  6. #6
    VAR csda1's Avatar
    Real Name
    Ira J Perlow
    Join Date
    Apr 2000
    Location
    Boston, Massachusetts, USA
    Posts
    3,530

    Default Re: Can you confirm expression evaluation error?

    Hi Mike,

    Quote Originally Posted by MikeC View Post
    Why, in your opinion, does it work when adding the numeric prior instead of after? And why does it work regardless when using Eval()?
    Adding a number after it sets up a structure (the XBasic stack I suspect) that gets corrupted by the asc() "c" function when used with 2 parameters as the asc() function is evaluated after the number. (Terms are evaluated from right)

    When it is the last item in the expression (meaning it is evaluated 1st), it does not mess up the structure, so any expression terms to the left that are evaluated are still OK.

    When you use eval(), you are basically evaluating it in it's own space (so it has it's own structure), and returning a number to the current space, which you are adding to another number. But try the whole thing together with eval() so it's added together in the same space and you get
    ?eval("asc('a',.t.)+1")
    ERROR: Argument is incorrect data type
    This is a very rare example of a function corrupting something outside it's internal space, and probably can only happen within non-xbasic functions.

    Why has a bug like this persisted over the years? I'll bet most people have never used the 2nd parameter, nor were they adding values to the value they got (I was using it in font-mapping routines for barcoding).

    I was using this 2nd term, in hopes of speeding the code a bit (relying on an internal function to be faster than my equivalent code). After working through the bug (by rearranging terms), here are simple results.

    ?asc(chr(150),.t.)
    = 150
    ?asc(chr(150),.f.)
    = -106
    ?asc(chr(150))
    = -106
    ?asc(chr(150))+256.and.255
    = 150

    ' This takes .00036 seconds to execute
    ?1+asc(chr(150),.t.)
    = 151
    ' This takes .00029 seconds to execute. Surprisingly, faster than the built in function!
    ?1+(asc(chr(150))+256.and.255)
    = 151
    Regards,

    Ira J. Perlow
    Computer Systems Design


    CSDA A5 Products
    New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
    CSDA Barcode Functions

    CSDA Code Utility
    CSDA Screen Capture



  7. #7
    VAR csda1's Avatar
    Real Name
    Ira J Perlow
    Join Date
    Apr 2000
    Location
    Boston, Massachusetts, USA
    Posts
    3,530

    Default Re: Can you confirm expression evaluation error?

    This error has been repaired in A5v10 build 2495-3379
    Regards,

    Ira J. Perlow
    Computer Systems Design


    CSDA A5 Products
    New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
    CSDA Barcode Functions

    CSDA Code Utility
    CSDA Screen Capture



Similar Threads

  1. Expression Evaluation
    By G Gabriel in forum Alpha Five Version 8
    Replies: 5
    Last Post: 04-04-2008, 10:42 AM
  2. Evaluation error
    By John Blum in forum Alpha Four Versions 7 and 8
    Replies: 1
    Last Post: 12-01-2003, 04:40 AM
  3. Confirm error with latest build?
    By russ Boehle in forum Alpha Five Version 5
    Replies: 2
    Last Post: 09-30-2003, 12:43 PM
  4. Evaluation Error
    By Joan Hannan in forum Alpha Four Version 6 and Prior
    Replies: 3
    Last Post: 07-31-2000, 10:25 AM

Bookmarks

Posting Permissions

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