String '5.' passed as number to ole property

Terry
2006-08-03
2012-08-14
  • Terry

    Terry - 2006-08-03

    I have written a wrapper class, vbsRe, that makes an OLE connect
    with 'VBScript.RegExp'. This wrapper class allows access to the
    VBScript regular expressions capabilities, and, indeed, enhances
    there use in Rexx.

    However, there is one problem. I hope someone knows an answer and
    will share it with me. Or if the problem is a bug, I hope that it
    is soon fixed.

    In short, when I set an pattern as the string '5.' (find 5 followed
    by any character) Rexx changes the string to the number 5. Thus,
    when I run a vbs ole method (execute(), replace(), or test())
    the single character '5' is matched in a string, not '5' followed
    by any character.

    The problem has to do with the behavior of Rexx to consider the string
    '5.' to be a number. The problem is illustrated in the script below.

    My example script, exVbsRe.rex is between the following dashed lines
    with explanatory notes and the output of the script that
    illustrates the problem.


    /
    The following pattern '5A' will find the text '5A'
    in a string like 'abc5A'
    /
    say
    RegEx = .vbsRe~new('5A')

    /
    The following pattern '5.' ('5' followed by any character)
    should NOT find anything in the string 'abc5', but it does
    because of the problem explained next.
    /
    say
    RegEx = .vbsRe~new('5.')

    /*
    The executable lines of code above,
    produces the following output:

    Before assignment:
    ?pattern - 5A CHAR
    re~pattern - CHAR
    After assignment:
    ?pattern - 5A CHAR
    re~pattern - 5A CHAR

    Before assignment:
    ?pattern - 5. NUM
    re~pattern - CHAR
    After assignment:
    ?pattern - 5. NUM
    re~pattern - 5 NUM

    Rexx passes the string '5.' to the vbs re property, pattern,
    as a number 5. Thus when vbs execute(), replace(), or test()
    is executed, the pattern found is 5, not 5 followed by a character.

    The second set of output from the say statements in the init()
    method show how the string '5.' is assigned as the number 5
    instead of the string '5.'.
    */

    ::requires "rxregexp.cls";

    -- vbsRe and its methods are stripped down here,
    -- just to demonstrate a problem

    ::class vbsRe public

    ::method init
    use arg ?pattern

    re = .OLEObject~new('VBScript.RegExp')

    say 'Before assignment:'
    say ' ?pattern -' ?pattern datatype(?pattern)
    say ' re~pattern -' re~pattern datatype(re~pattern)

    re~pattern = ?pattern

    say 'After assignment:'
    say ' ?pattern -' ?pattern datatype(?pattern)
    say ' re~pattern -' re~pattern datatype(re~pattern)

    return

     
    • Rony G. Flatscher

      Hi there,

      it seems that at times the datatype conversion from the OLE support in ooRexx to OLE picks the wrong datatype.

      In your case (as you are creating the VBS interface yourself) you could bypass this, by always prepending any value on the Rexx side with the letter "S", which then gets always stripped on the VB side.

      Hope that helps a little,

      ---rony

       
    • Terry

      Terry - 2006-08-04

      Rony,
      Thanks for the info. But I could not get this technique to work. I tried MANY variations of what you suggested, but could not get them to work. Could you provide a concrete example. Not everything, but just the line (or few lines) code having to do with the assignment of ?pattern to re~pattern ?

       
    • Rony G. Flatscher

      Hi there,

      instead of:

      RegEx = .vbsRe~new('5A')
      RegEx = .vbsRe~new('5.')

      you could use:

      RegEx = .vbsRe~new('S5A')
      RegEx = .vbsRe~new('S5.')

      And in your VB code you would throw out the first character, something like (assuming that "argSupplied" is the name of the argument in your VB function):

      argValue=mid(argSupplied, 2)


      The idea is that if prepending any character on the Rexx side will cause the OLE-support of Rexx to coerce the value to a string in any case.

      HTH,

      ---rony

       
      • Terry

        Terry - 2006-08-05

        Rony,

        Thanks for your responses. But, I am writing nothing in VB code. The wrapper I wrote is in 00Rexx code and is for use in ooRexx code. I had tried what you suggest and tried it again after you suggested. But, I have come to the conclusion that I simply cannot get around the problem in ooRexx, at least in version 3.01.

        I hope this issue will be resolved in the near future.

        I regret the misunderstanding that caused you to lose your time trying to help me out. But I do truly appreciate your efforts.

        Terry

         

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks