Lithium Posted August 1, 2009 Share Posted August 1, 2009 (edited) What would be the best way to assign an operator to a variable? What I'm trying to do is assign a '+' or '-' to a variable depending on the output of a random number. Many thanks in advance. Edit:Spellcheck... Edited August 1, 2009 by Lithium Link to comment Share on other sites More sharing options...
Hawkwing Posted August 1, 2009 Share Posted August 1, 2009 (edited) What would be the best way to assign an operator to a variable? What I'm trying to do is assign a '+' or '-' to a variable depending on the output of a random number. Many thanks in advance. Edit:Spellcheck... Like this? Local $var If Random(1, 10) < 5 Then $var = "+" Else $var = "-" EndIf If $var = "+" Then MsgBox(0, "", 1 + 1) Else MsgBox(0, "", 1 - 1) EndIf You can't use a variable as an operator, so you'll have to use an If Then to check the variable and then change the operator used. Edited August 1, 2009 by Hawkwing The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again. Link to comment Share on other sites More sharing options...
Lithium Posted August 1, 2009 Author Share Posted August 1, 2009 I see. I'm trying to cut down on repetition as much as possible in my code but it looks like I'm stuck here. Thanks for answering my question >_< Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now