Results 1 to 3 of 3

Thread: CR 8.5: Help With Formula

  1. #1

    Thread Starter
    Addicted Member Sanko's Avatar
    Join Date
    Mar 2000
    Location
    Argentina
    Posts
    128

    Question CR 8.5: Help With Formula

    HI
    I have 5 Fields in the DB:
    CON_AFM.AFM_DIABETES, CON_AFM.AFM_TENSION, CON_AFM.AFM_STRESS, CON_AFM.AFM_HIV and CON_AFM.AFM_TIROIDE
    every field can have the value 1 or 0. Now i want to look for every field that have the value 1 and change to a string.

    if CON_AFM.AFM_DIABETES value is 1 then the string to show is "Diabetes"
    if CON_AFM.AFM_TENSION value is 1 then the string to show is "Hipertension"
    if CON_AFM.AFM_STRESS value is 1 then the string to show is "Stress"
    if CON_AFM.AFM_HIV value is 1 then the string to show is "HIV"
    if CON_AFM.AFM_TIROIDE value is 1 then the string to show is "Tiroides"

    But if the value is 0 i don´t show a string

    Example:

    DB Fields with Values

    CON_AFM.AFM_DIABETES 1
    CON_AFM.AFM_TENSION 1
    CON_AFM.AFM_STRESS 0
    CON_AFM.AFM_HIV 0
    CON_AFM.AFM_TIROIDE 1

    The formula must return a string like
    "Diabetes, Hipertension, Tiroides"

  2. #2
    Hyperactive Member ARPRINCE's Avatar
    Join Date
    Mar 2003
    Location
    Pinoy in NJ
    Posts
    381
    There might be a better way but you can try something like creating a formula and using the formula editor, have something like this:

    VB Code:
    1. '--CRYSTAL SYNTAX BELOW
    2. stringVar strTEST;
    3.  
    4. if {RAMain.VPApproved}=true then
    5.     strTEST := "VP"
    6. else strTEST := "";
    7.  
    8. if {RAMain.CRApproved}=True then
    9.     strTEST := strTEST + ",CR"
    10. else strTEST := strTEST;
    11.  
    12. if {RAMain.Void}=true then
    13.     strTEST := strTEST + ",VO"
    14. else strTEST := strTEST;
    15.  
    16. if left(strTEST,1) ="," then   'this removes a comma if the first check is false
    17.     strTEST := MID(strTEST,2,LEN(strTEST)-1);

  3. #3

    Thread Starter
    Addicted Member Sanko's Avatar
    Join Date
    Mar 2000
    Location
    Argentina
    Posts
    128

    Talking

    Thanks Arprince for your code works perfect.

    Here is the code if anybody need for help

    VB Code:
    1. // crystal syntax
    2.  
    3. stringVar STR;
    4. if {CON_AFM.AFM_DIABETES} = 1 then STR = "Diabetes" else STR = "";
    5. if {CON_AFM.AFM_TENSION} = 1 then STR := STR + ", Hipertensión" else STR := STR;
    6. if {CON_AFM.AFM_STRESS} = 1 then STR := STR + ", Stress" else STR := STR;
    7. if {CON_AFM.AFM_HIV} = 1 then STR := STR + ", HIV" else STR := STR;
    8. if {CON_AFM.AFM_TIROIDE} = 1 then STR := STR + ", Tiroides" else STR := STR;
    9. // Esto elimina la coma si el primero es falso
    10. if left(STR,1) ="," then STR := MID(STR,2,LEN(STR)-1);

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