Variable comparison
  • Neil Garvie
    Variable comparison

    by Neil Garvie » Mon Jan 30, 2006 5:08 pm

    In Visual Builder are Variables acceptable in the Body “All Rules must be True” Rules section

    Declare YY Type Char
    YY := "StAux000->Generic"
    Echo(YY)
    YY = "Y"
    Echo(YY)


    Is there an obvious reason why the Variable YY

    Will not substitute in the line 4 to read

    StAux000->Generic = “Y”.

    The variable echoes pre and post line 4.

    If StAux000->Generic = “Y” is “hard coded in line 4

    The report works OK.
  • COBS Tech Support
    Posts:683
    Joined:Fri Sep 09, 2005 8:23 am

    by COBS Tech Support » Mon Jan 30, 2006 5:10 pm

    When you execute:

    YY = "Y"

    You are just asking the computer to compare the string YY to the string "Y". These strings do not match so this expression will always evaluate to FALSE. The contents of YY may reference a database expression, but unless you specify this explicitly, the computer will just interpret it as a series of characters.

    CBS does not provide a function to translate a string of characters into the result of an evaluation of an expression contained in a string. Although if such a function was added to the language, it would run slowly since a lot of work would be involved in evaluating the expression, so placing such an expression inside the Rules section of Visual Builder would not be ideal. A related function, called ScriptRun() does exist. But again, it would not be recommended to try to use it inside the Rules section of a report for performance reasons.
  • Neil C
    Posts:10
    Joined:Thu Dec 15, 2005 2:15 pm
    Location:Central Coast

    by Neil C » Wed Feb 01, 2006 1:42 pm

    G'day Neil

    your line 2, which reads:

    YY := "StAux000->Generic"
    assigns the quoted string to YY, not the value in the table.

    If you're trying to compare a value in the database you need to use
    YY := StAux000->Generic
    which will actually access the database rather than just a string.

    if the idea is to have a softcoded reference to your database, like a field which says which field to use for an operation; but only within a hard coded table, like this:
    StAux000->(getField(YY))
    where YY is the string from before

    As far as i'm aware you cannot substitute the table with a soft coded alternative.
    Hope that might help a bit.
  • Neil C
    Posts:10
    Joined:Thu Dec 15, 2005 2:15 pm
    Location:Central Coast

    by Neil C » Wed Feb 01, 2006 2:05 pm

    Haha, i'm such a liar..
    You can softcode your table and pass it to the same function, which has an overloaded form that takes the field and the table, like so:

    Code: Select all

    Declare cField type char
    Declare cTable type char

    cField := "general"
    cTable := "staux000"

    return GetField(cField, cTable) = "Y"


    GetField in the help files anyhoo

    Also, just for your info, there's no case sensitivity in capital business script, so capital doesn't care as long as it's spelt properly :D
  • COBS Tech Support
    Posts:683
    Joined:Fri Sep 09, 2005 8:23 am

    by COBS Tech Support » Wed Feb 01, 2006 2:47 pm

    That's a very nice way to solve the problem and relatively fast. Wish we'd thought of it first. :P

Who is online

Users browsing this forum: No registered users and 23 guests