Hello Guest it is November 05, 2024, 04:43:07 AM

Author Topic: and, or ,xor  (Read 4974 times)

0 Members and 1 Guest are viewing this topic.

and, or ,xor
« on: July 26, 2007, 11:20:42 PM »
I read in the manual that you can use and, or, xor in equations. 

Has anyone done this and can you give an example?

Thanks

Dan

Offline Whacko

*
  •  239 239
  • Happy Days
Re: and, or ,xor
« Reply #1 on: July 27, 2007, 06:20:29 PM »
Yeow Dan,

That is a very broad question, those are logical operators and you can use it for so many reasons, you will have to be more specific what you want to do, or you can get some more information on the MicroSoft website VBScript help, or download the VB-Script-Commands.pdf in the download section of Art's homepage.

William
Nothing's impossible
Re: and, or ,xor
« Reply #2 on: July 28, 2007, 03:53:05 PM »
What I was referring to was referenced in the manual (see bold red below).  I am wondering if this construct can be used as a IF Then statement inside an equation.  I realize the use of these statement in VB or other programing languages can be very broad but I am thinking the way they employed in an equation is very limited.  I would be curious to see any examples if they exist.

Thanks

Dan


Quote
0.5.3.3 Expressions and Binary Operations
An expression is a set of characters starting with a left bracket [ and ending with a
balancing right bracket ]. In between the brackets are numbers, parameter values,
mathematical operations, and other expressions. An expression may be evaluated to
produce a number. The expressions on a line are evaluated when the line is read, before
anything on the line is executed. An example of an expression is:
[1+acos[0]-[#3**[4.0/2]]]
Binary operations appear only inside expressions. Nine binary operations are defined. There
are four basic mathematical operations: addition (+), subtraction (-), multiplication (*), and
division (/). There are three logical operations: non-exclusive or (OR), exclusive or (XOR),
and logical and (AND).
The eighth operation is the modulus operation (MOD). The ninth
operation is the "power" operation (**) of raising the number on the left of the operation to
the power on the right.
The binary operations are divided into three groups. The first group is: power. The second
group is: multiplication, division, and modulus. The third group is: addition, subtraction,
logical non-exclusive or, logical exclusive or, and logical and. If operations are strung
together (for example in the expression [2.0/3*1.5-5.5/11.0]), operations in the
first group are to be performed before operations in the second group and operations in the
second group before operations in the third group. If an expression contains more than one
operation from the same group (such as the first / and * in the example), the operation on
the left is performed first. Thus, the example is equivalent to: [((2.0/3)*1.5)-
(5.5/11.0)] which simplifies to [1.0-0.5] which is 0.5.
The logical operations and modulus are to be performed on any real numbers, not just on
integers. The number zero is equivalent to logical false, and any non-zero number is
equivalent to logical true.

Offline Whacko

*
  •  239 239
  • Happy Days
Re: and, or ,xor
« Reply #3 on: July 28, 2007, 04:58:26 PM »
Hi Dan,
Apologies, they say presumption is the mother of all evil. I presumed you did not know about the VB files.
This is one example. Open Mach3, and zero your X and Y DRO's
Open the VBScript utility in the Operator menu.
Copy and paste this:

Dim xpos As Variant
Dim ypos As Variant
Dim result As Variant
    GetDRO ( 0 )
    xpos = GetDRO ( 0 )
        GetDRO ( 1 )
        ypos = GetDRO ( 1 )
result = xpos Xor ypos
MsgBox (result)

(Edit) I forgot to mention, you have now a value in "result" that you can use in an if statement to test for conditions, or against other variables etc. There is actually many
ways that you can utilise logical operators in an if statement.

After the VBScript jog the x and y some distance and run the script again. You will get a value in the Msgbox. You can't do much with it, as it is just an example. As I said earlier, you can apply it to achieve something specific which depends on what your application is. The "And" operator can be used in a similar way. Experiment with it, and work out what the values mean, then you can apply it.

Best regards
William
« Last Edit: July 28, 2007, 05:07:08 PM by Whacko »
Nothing's impossible
Re: and, or ,xor
« Reply #4 on: July 28, 2007, 05:06:43 PM »
Interesting... thanks.

Dan

Offline Whacko

*
  •  239 239
  • Happy Days
Re: and, or ,xor
« Reply #5 on: July 28, 2007, 05:08:27 PM »
Hi Dan,

I did an edit to the post to answer your whole question.

William
Nothing's impossible