convert Option into string

I need to pick up the first letter of an option type. I am using Copystr which requires me to convert the option into a string. How do i convert it?

I don’t really understand what you are trying to do?

If you use an option field then this happens automatically! But I guess this is not what you are trying to do… Please explain…

I have an option data type in a table. Lets say its color and its values are : Red, Blue, Green

in a report, first i capture the value of the color field. then i determine which color it is based on the first letter. I declared a text variable and tried to copy the first letter but it errors out saying cannot assign Option to a text.

Heres the actual code i am using:

Prescription.SETFILTER(Prescription.“Sales Document No.”,“Sales Header”.“No.”);

IF Prescription.FIND(’-’) THEN

LensType:=Prescription.“R Lens Type”;

Pos:=FORMAT(LensType); // i am unable to get the value in the Pos variable. its empty.

IF Pos = ‘D’ THEN
Design := ‘Maximum Far Performance’
ELSE IF Pos =‘L’ THEN
Design:=‘Maximum Flexibility’
ELSE IF Pos = ‘S’ THEN
Design:=‘Single Vision’
ELSE
Design:=‘Progressive’;

Hope this makes sense, i am not very good at explaining. Thank you for your help.

Try:

CASE LensType OF

LensType::D:

Design := ‘Maximum Far Performance’;
LensType::L:

Design:=‘Maximum Flexibility’;
LensType::‘S’

Design:=‘Single Vision’;
ELSE
Design:=‘Progressive’;

END;

If you’re hard coding getting the first character of the option value, why not hard code the whole value in the CASE statement? That will make your code much more readable.

totally agree…
and do the CASE on the field it self, no need to copy the value into a variable first.

btw…
FORMAT on an option will give the format-value, so I think the reason that Pos-variable is empty, lies in how LensType-variable are defined.

Thank you very much, this solves my problem.

Excelent, can you indicate which post answered your question. Thanks