Invalid Option Type Error!

nvermanverma Member Posts: 396
Hi, I have a quick question.

I am trying to calculate the age of a person. Once I have a age I have to set it to appropriate Type. For example if age is less then 18, then the type would be "Child", if the age is less then 65, the type would be "Adult, and so on.

This is the code snippet that I have so far:

InputDate := TODAY;
Year := DATE2DMY(InputDate,3);

BirthDate := Customer.Birthdate;
BirthDay := DATE2DMY (BirthDate, 3);

IF (Customer.Birthdate = 0D) THEN
BEGIN
Job."Primary Consumer Type" :='';
END;

PrimaryType := (Year - BirthDay);

CASE PrimaryType OF
1..17:
BEGIN
Job."Primary Consumer Type" := 'Child';
END;

18..64:
BEGIN
Job."Primary Consumer Type" :='Adult';
END;

ELSE
BEGIN
Job."Primary Consumer Type" := 'Senior';
END;

END;

The error Message I get on this line (Job."Primary Consumer Type" :='';) is: Type conversion is not possible because 1 of the operators contains an invalid type. Option := Text

Primary Consumer Type is an Option field with the following options child, senior, adult, etc

I know the reason of the error, I just dont know how to fix it.

Comments

  • kapamaroukapamarou Member Posts: 1,152
    Job."Primary Consumer Type" := Job."Primary Consumer Type"::"Senior";
    Job."Primary Consumer Type" := Job."Primary Consumer Type"::"Child";
    Job."Primary Consumer Type" := Job."Primary Consumer Type"::"";
    etc...
  • nvermanverma Member Posts: 396
    When i tried doing the way you suggested, now I get a different error:


    "A Variable was expected. For example:

    MyVar
    Customer.Name"
  • kapamaroukapamarou Member Posts: 1,152
    Can you post your new code?
  • nvermanverma Member Posts: 396
    Actually never mind, it works. I forgot to take the single Quotations out. hehehhee...

    Thanks.

    Just for knowledge sake, what does putting the code like this (Job."Primary Consumer Type" := Job."Primary Consumer Type"::"";) actually achieve. Just in case I have similar issue some other time, I want to be able to know how to fix it myself.
  • SavatageSavatage Member Posts: 7,142
    also,for readability reasons:
    BirthDay := DATE2DMY (BirthDate, 3);
    shouldn't BirthDay actually be named BirthYear
  • SPost29SPost29 Member Posts: 148
    Options are stored as integers.
    Job."Primary Consumer Type" := 0;
    is the same as
    Job."Primary Consumer Type" := Job."Primary Consumer Type"::"";

    This is much easier to understand: option type = option type:: (of) blank.
  • nvermanverma Member Posts: 396
    Ohhh...OK. I guess that makes sense. Thnx everyone for there help.

    I really appericate it. :)
Sign In or Register to comment.