How to get the text of an enumeration field (Manipula)?

Please login to reply  Page: « < 1 of 1 > »
05 Aug 2010 - 20:12713
How to get the text of an enumeration field (Manipula)?

Hi,

Given this example of an enumeration field:

Datamodel XYZ
...
Fields
Activity : (School (1) "Going to school",
            Working (2) "Working",
            HousKeep (5) "Housekeeping",
            Other (7) "Something else")
...

I can get the numeric value of this field using the ORD method:

Manipulate
    tmp := Activity.ORD
    { In this case if Activity is set to Working I get tmp = 2 }

But what if I want to get the text of this enumeration? In this example getting tmp = 'Working'. What should I do? I tryed tmp := STR(Activity) but it didn't work.

Thanks.



10 Aug 2010 - 23:00720
Use GETFIELDINFO

Hi Arthur

To extract the metadata from your datamodel in Manipula you need to use the GETFIELDINFO method.

Here is a sample questionnaire using your question.

{**********************************************************************
 Module   : MyQuestionnaire.BLA
 Overview :

    Sample questionnaire containing simple questions 

 Author   : fred.wensing@softscape.net.au

 Update History:
 Vsn   dd/mm/yyyy Person Change
 ----- ---------- ------ ------
 1.010 24/03/2009 Fred   -Initial version
**********************************************************************}

DATAMODEL MyQuestionnaire

FIELDS
    Name "What is your name?" / "Name" : STRING[20]
    Favourite "Which of these colours do you like the most?"
        / "Colour"
        : (Red, Green, Blue, Yellow, Purple, Black, Crimson)
    Activity "What is your main activity?"
        / "Activity"
        : (School (1) "Going to school"
          ,Working (2) "Working"
          ,HousKeep (5) "Housekeeping"
          ,Other (7) "Something else"
          )
RULES
    Name
    Favourite
    Activity
ENDMODEL 

Compile the datamodel and Enter a few cases.

Here is some Manipula which extracts the answer names and displays them on the screen for you to see.

{**********************************************************************
 Module   : ShowAnswers.MAN
 Overview :

    Manipula program showing extraction of metadata from fields 
    using the GETFIELDINFO method

 Author   : fred.wensing@softscape.net.au

 Update History:
 Vsn   dd/mm/yyyy Person Change
 ----- ---------- ------ ------
 1.010 11/08/2010 Fred   -Initial version
**********************************************************************}

USES
    MyQuestionnaire
INPUTFILE
    Infile : MyQuestionnaire ('MyQuestionnaire',BLAISE)
AUXFIELDS
    aFavourite : STRING
    aActivity : STRING
    x : INTEGER
MANIPULATE
    x:=ORD(Favourite)
    aFavourite := Infile.GETFIELDINFO ('Favourite','CATEGORIES['+STR(x)+'].NAME')
    x:=ORD(Activity)
    aActivity := Infile.GETFIELDINFO ('Activity','CATEGORIES['+STR(x)+'].NAME')
    {display the values on screen for the operator}
    DISPLAY ('The favourite colour for '+Name+' was '+aFavourite
            +' and activity '+aActivity,WAIT)

Good luck

Fred



12 Aug 2010 - 15:21721
It works!

Thank you! It worked fine. I did the trick with this abbreviated code:

    BlaiseData.GETFIELDINFO ('Activity','CATTEXT')
    { Blaise help states that 'CATTEXT' is the same of 'CATEGORIES[x].DEFINEDTEXT' }


Please login to reply  Page: « < 1 of 1 > »