Variable State Change


RJE

Recommended Posts

Can't seem to find anything on state change.

I have a variable that I set to 0 or 1 depending on real world events.

Pretty much binary so I could use TestBit(x, #0) to get its state.

But how would I determine if is has transitioned. In some instances I may not care if the bit has gone from 0 to 1 but I will care if it has gone from 1 to 0?

Thanks

R.

Link to comment
Share on other sites

(I think you mean TestBit(x, 0), and truthfully, why use testbit when the only possible values are 0 and 1?)

In a normal variable, there is no history to do a comparison with the previous value, and there is no event that occurs when the variable is set. Assuming that you are changing this variable from lots of places, there are two techniques you can use:

1) use the standard get/set style variable access typically of OOP. In this case you probably just need a set(). What I mean is a function (sequence), called, maybe, setx() that takes a value and sets the x variable to that value. Then in the sequence, you can look at the current state and the new state before changing it and do something

2) In DF, you could also use a Test D to A channel instead of a variable. Its a little slower, but it can have a history and does have an Event, so you can put the code to see if the value changed in the event:

if (!x[0] && x[1])
   // do something
endif

Link to comment
Share on other sites

OOP, object orientated programming??? Tried my hand at that and just can't get the old brain wrapped around it.

V channels have history? Trying to figure a way to use that but not much luck.

If I have to use channels I would have to upgrade my unused 32 tag license (waiting Win7) to the Base 64 tag license. How would that be done?

RJE

Link to comment
Share on other sites

You don't have to use OOP, I just meant that setters and getters are typical of object in OOP. You can just create a sequence function to get or set a variable and thus add additional code.

Yes, V channels have history.

You can upgrade by going to www.azeotech.com, clicking buy, then selecting upgrades from under DAQFactory. Lite to Base I believe is $220.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.