PDA

View Full Version : Operators as variables



SonHouse
02-20-2004, 09:23 PM
How do I assign an operator symbol like "+" to a variable without the engine thinking that I'm trying to perform a mathematical operation. I'm just needing the character "+" to be placed in particular areas throughout the program. I tried assigning it like this

operator = +;

but it wont compile due to the operator character. I thought I read somewhere that you can preface it with a "\" like this

operator = \+;

but I tried that and it didn't work either. any ideas?

thanks

Corey
02-20-2004, 09:52 PM
operator = "+"; will create a string named operator with the plus sign in there.

If you are trying to do dynamic math then try using:

operator = "plus";

and the later us an if statement to act accordingly, i.e.

if operator == "plus" then
result = x + y;
end

if operator == "minus" then
result = x - y;
end

And so forth, or at least that's one way to do it anyhow. :)

Corey Milner
Creative Director, Indigo Rose Software (http://www.indigorose.com)

SonHouse
02-20-2004, 09:59 PM
Corey,

Thanks for your help again....

Dave

Corey
02-20-2004, 10:18 PM
:)

Corey Milner
Creative Director, Indigo Rose Software (http://www.indigorose.com)

TJ_Tigger
02-20-2004, 11:04 PM
Originally posted by SonHouse
Corey,

Thanks for your help again....

Dave

Boy if I had a nickel for everytime someone said that here on the forums . . .

Corey
02-20-2004, 11:17 PM
Pah! *You* "da man"... :o

Corey Milner
Creative Director, Indigo Rose Software (http://www.indigorose.com)