case statement in function

sarathbabu
2012-09-27
2012-10-02
  • sarathbabu - 2012-09-27

    hi

    how to put up a case statement in a function for this case

    case temp of

    0:test:=trig(it will return bool)

    1:tester:=trigg(it will return int)

    2:testerhw:=trigrrw(it will return float)

    end_case

    and one more thing can we use case for a string as need for string operations

    Thanks

     
  • sarathbabu - 2012-09-28

    Hi,

    just convert STRING_TO_INT and u can use in Case statement too.

    But still am wondering how to implement in function for the above requirement.

     
  • shooter - 2012-10-01

    No case can only be used with a INT as selector.

    If the var used is a number in stringformat you can simply convert it to an integer
    if the var is 'anystring' then you first must check them with an IF statement
    so IF var='anystring'then caseselctor :=1;
    IF var = 'anystring1'then caseselctor :=2;
    etc
    next question is

    case temp of

    0:test:=STRING_TO_BOOL (trig) ;(it will return bool)
    (test must be declared as bool obvious)
    1:tester:=STRING_TO_INT (trigg); (it will return int)

    2:testerhw:=STRING_TO_REAL(trigrrw);(it will return float)

    end_case

     
  • sarathbabu - 2012-10-02

    Hi

    Steps you said can be a proper way to do

    I used STRING_TO_INTEGER it is working fine

    Any thing is wrong with this

    Regards,
    Sarath

     
  • shooter - 2012-10-02

    This means your string must be an integer like '123'
    it can not be 'onehundredtwentythree'
    in that case you will have to use my solution with the IF statements.

     

Log in to post a comment.