Set OptionString of a Option variable in Code

Hi I have a variable of type Option. I want to (in code) build the OptionString of that variable. How do I do this without having a table or record from which to get this value? eg. If I wanted to get the string ‘Navision,Option,Sucks’ into the OptionString how would I do this?

Hi Lin, in the properties of your variable there is a property called optionstring which you can fill in with ‘Navision,Option,Sucks’ and then in the code you can set your variable for example on Sucks with the next command Variable := Variable::Sucks Wendy,

Thanks but I know that. I want to set that OptionString property at runtime (with Coding) not at design time.

Can’t be done, I’m afraid.

not possible I think

Hi Lin, Depending on what the code is supposed to do you can assign option values programatically. Variable := 1 is the same as Variable := Variable::Option Variable := 2 is the same as Variable := Variable::Sucks Hope this helps. If you need more helo please explain what you are trying to do in more detail… Regards, Cristi Nicola

Hi I want to have a dropdownlist on the form. For that to work the OptionString property has to be set. The control is not bound to a table or record therefore I must set the OptionString property with code. But I think that Jan Hoek and Geoffrey is correct in that it can not be done. That is what I get for wanting to do some real programming in a data-driven subset of a language.

No it can’t be done. But, perhaps, using the function STRMENU you can obtain a similar effect?

Just curious: An option is usually used together with a CASE-statement. And CASE-statements is to be handled statically. How do you want to handle variable options in your code?

That is true. The thing is I did not want to bind the dropdown to a record/data item. All I wanted was to build the OptionString dynamically. Got a work-around for it now. (hardcode the OptionString at design time) Could you see me flinch when I mentioned the word HARDCODE. That is a big no-no. Another example is a Label. You can not set the Caption of a label at runtime. How silly is that. Sure there are work-around for that too. Use a Text Box and make the Editable property False but it should not have to be this way. This is not programming. This is customizing. There is no freedom in Navision coding. You only have a handful of functionality and then you have to resort to bad programming practices (eg. Hardcoding) to achieve a work-around for your problem.

Ive been thinking about this, and one possible way of working round this without expending a table is to use temporary tables: 1) Pick out any lookup table (code/description) and declare it on your form as temporary. 2) Populate the temporary table with your options. 3) Put a new field variable on the form. 4) On the OnLookup trigger of the new field, write code to display the form for the temporary table. Im sure this could work, and using things such as setting captions on the lookup form and suitable use of noneditable fields, you can create the same effect as a dynamic option string. Regards, Edward. ps. by “any lookup table” see table 10 Shipment method as an example.