SPONSORS:






User Tag List

Results 1 to 5 of 5
  1. #1
    Senior Member
    Join Date
    Jun 2000
    Location
    Hartford, CT, USA
    Posts
    163
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    use of string as an operator

    Is this possible? How?

    testcase CheckExec(string sVar)
    float fNo1, fNo2, fResult

    // here I would like to calculate
    fResult = Execute(fNo1 + sVar + fNo2)

    */ for example if the character passed through sVar is '+', fVal1 = 100.10 and fVal2=200.20 then it should do the following
    fResult= 100.10 + 200.20
    Value in fResult should be 300.30
    */

    Can we use Sys_execute here?
    Jaimini Bhatt

  2. #2
    Senior Member
    Join Date
    Jun 1999
    Location
    Fremont, CA, USA
    Posts
    355
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: use of string as an operator

    There is no built in function for that.

    You can write one, with a bunch of switch statments:

    </font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">switch sVar
    case &quot;+&quot;
    // do addition
    case &quot;-&quot;
    // do subtration
    case &quot;*&quot;
    // do multiplication
    default
    print (&quot;Unable to determine operation type: {sVar}&quot</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">Would something like that work for you?

  3. #3
    Senior Member
    Join Date
    Jun 1999
    Location
    Fremont, CA, USA
    Posts
    355
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: use of string as an operator

    There is no built in function for that.

    You can write one, with a bunch of switch statments:

    </font><blockquote><font size="1" face="Verdana, Arial, Helvetica">code:</font><hr /><pre style="font-size:x-small; font-family: monospace;">switch sVar
    case &quot;+&quot;
    // do addition
    case &quot;-&quot;
    // do subtration
    case &quot;*&quot;
    // do multiplication
    default
    print (&quot;Unable to determine operation type: {sVar}&quot</pre><hr /></blockquote><font size="2" face="Verdana, Arial, Helvetica">Would something like that work for you?

  4. #4
    Member
    Join Date
    Jun 2001
    Location
    Berkeley, CA, USA
    Posts
    67
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: use of string as an operator

    You could use a switch statement to handle the operator.

    switch(sVar)
    case "+"
    fResult = fNo1 + fNo2
    case "-"
    fResult = fNo1 - fNo2

    etc.

  5. #5
    Senior Member
    Join Date
    Jun 2000
    Location
    Hartford, CT, USA
    Posts
    163
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: use of string as an operator

    Thanks a lot. Lazy me was looking for a single line solution. [img]images/icons/wink.gif[/img]
    Jaimini Bhatt

 

 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

vBulletin Optimisation provided by vB Optimise v2.6.0 Beta 4 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
User Alert System provided by Advanced User Tagging v3.0.9 (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Questions / Answers Form provided by vBAnswers (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
vBNominatevBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Feedback Buttons provided by Advanced Post Thanks / Like (Pro) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
Username Changing provided by Username Change (Free) - vBulletin Mods & Addons Copyright © 2016 DragonByte Technologies Ltd.
BetaSoft Inc.
Digital Point modules: Sphinx-based search
All times are GMT -8. The time now is 10:54 PM.

Copyright BetaSoft Inc.