[Gambas-user] Searching a key in the array of gb.settings

Doriano Blengino doriano.blengino at ...1909...
Sun Nov 9 10:00:11 CET 2008


gambas at ...1938... ha scritto:
>
>> What you are trying to do could only work in true interpreted languages
>> - perhaps; 
>>     
> That's the answer why it works in Perl! :whistle:
>
>   
>> it is a total non-sense in every serious programming language. 
>>     
I have to correct myself. The distinction is not among "serious" 
languages and "not serious" ones.
I don't want to say that Bash, Tcl, Perl and probably others are not 
serious.
The difference is in compiled languages (either compiled to machine code 
or p-code) and interpreted ones.
Sorry if my previous mail offended someone ;-)

Problem is that, normally, compiled languages discard informations about 
names. So if you construct a string in program, there is no way to 
associate it directly to what was a program symbol. But often compilers 
keep, for at least a part of the program, some information about the names.

> But I'm still lost in the dark.
> How can I check, if the user entered a valid option of my servicemenu 
> (settingsfile)?
>   
I think your program offers a finite set of procedures, and the 
settings[] content is managed by your program too, so:

    1. hCFG["Action/" & sItem] can be empty (""), and so it is invalid, or
    2. it contains something your program wrote in it, and so it should 
be valid
    3. unless you take a user input and, without checking it, you use it 
verbatim. And this is no good.

Next problem is to deal with a set of strings, and associate them to the 
routines. If they are not too much, a simple (in pseudo code):

    sAction = settings[...]
    if sAction="Item1" then Item1();
    if sAction="Item2" then Item2();
    ...

or, even better,

    select sAction
      case "Item1"
      Item1()

      case "Item2"
      Item2()

      ...

      case else
      print "Unknown command"
  end select

Don't know if there are other ways to store the address of a routine 
somewhere (an array or a collection) - probably is possible by using 
object.xxxx methods, but I would stay to the clear and simple method 
depicted above.

If you want me to be more precise, you should give more information 
about your program.

Regards,
Doriano





More information about the User mailing list