anant desai
29th April 2012, 15:49
How do I convert a string to an enum?

bdittmar
29th April 2012, 17:53
How do I convert a string to an enum?

Hello,

explain what do you want to achieve ?

From BaanERP Programmers Guide

Enumerates overview and synopsis
--------------------------------------------------------------------------
Overview
Use these functions for handling enumerated domains and table fields.

Synopsis
domain ask.enum
( string quescode(14), domain default_enumvalue [, arg ] ... )
string enum.descr$
( string domain code(12), enum_expr [, string language_code] )
long etol
( domain domain_value )
domain ltoe
( long long_value )
void set.enum.values
( enum_constant, ... )
void set.ask.enum.values
( enum_constant, ... )
void set.enum.values.for.field
( const string field.name.string, [ALL_ENUMS_EXCEPT], enum_value, ... )
void set.initial.enum.values.for.field
( const string field.name.string, [ALL_ENUMS_EXCEPT], enum_value, ... )

Regards

mark_h
30th April 2012, 15:37
This is the correct forum for posts like this.

Thanks

Hitesh Shah
1st May 2012, 20:10
How do I convert a string to an enum?

U need to check enum.descr$ function for each enum option and compare the string with string input . If it matches case insensitive , the option is the enum number . U can use RDI functions for this entire function.

younes74
19th November 2019, 23:54
You use
ltoe(val(YOURSTRING)))

OmeLuuk
30th November 2019, 22:18
You use
ltoe(val(YOURSTRING)))only in case your "text" has the form of "tcyesno.no" for value (text) "No" (enum.descr$). When you want to start with the "No" word you need more code, to find the enum descriptions for the field, put them in an array, compare the input string with the stored values (may be all to.upper$) and use the array index as the value for ltoe(). But be aware that you should do this for all used languages, because the "tcyesno.no" is language independent, the "No" part is not.