Logical Operators

ceaser

Active Member
Licensed User
Hi

It would be nice to have logical operators as part of the language:

The operators AND, OR and NOT should allow you to combine or change test conditions. . .c1 and c2 represent conditions:

1. c1 AND c2 True if both c1 and c2 are true...returns -1
False if either c1 or c2 are false...returns 0
2. c1 OR c2 True if either c1 or c2 is true...returns -1
False if both c1 and c2 are false...returns 0
3. NOT c1 True if c1 is false...returns -1
False if c1 is true...returns 0

Or maybe there is a way around this in B4PPC, which I do not know of.

Thanks
Michael
 

ceaser

Active Member
Licensed User
Hi Erel

Wow.......that was a fast reply!:)

Any chance of maybe adding this in a future version of B4PPC?

I need to find a way around this, as I need to calculate a variable when orientating a Topcon or Nikon Total Station. I am using the formulae in my older program (written in OPL) to complete the new program.

Thanks
Michael
 

agraham

Expert
Licensed User
Longtime User
Treat 1 or -1 as True and 0 as False and use the Bitwise library

B4X:
Sub Globals
   BitTrue = -1
   BitFalse = 0
End Sub

Sub App_Start
   Bit.New1
   c1 = BitTrue
   c2 = BitTrue
   c3 = BitFalse
   bitand = Bit.AND(c1, c2)
   bitor = Bit.OR(c1, c3)
   bitnot = Bit.Complement(c3) ' this is Not(c3)
   Msgbox(bitand & ", " & bitor & " , " & bitnot)
End Sub
 

ceaser

Active Member
Licensed User
Hi Agraham

Thanks for the help, but I would be most obliged if you could help me more please:sign0085:

Below is the code like I have it in B4PPC, but it does not work:(

'SD = the horizontal angle setting to be send to the Topcon Total Station (dddmmss)
Do While i9<=StrLength(SD)
q=Asc(SubString(SD,i9,1))
i9=i9+1
b1= q Bit.AND (Bit.Complement(b))
b2= b Bit.AND (Bit.Complement(q))
b = Bit.OR(b1,b2)
i9=i9+1
Loop
SD=SD & Format(Abs(b),"D3") & Chr(3)


Next I have the code in OPL, which works:

i%=1 :b%=0
WHILE i%<=LEN(SD$)
q%= ASC(MID$(SD$,i%,1))
b1%= q% AND (NOT b%)
b2%= b% AND (NOT q%)
b% = b1% OR b2%
i%=i%+1
ENDWH
RETURN(FLT(b%))


What happens is that I have my instrument set up at a known point (X,Y & Z). Next I sight the instrument on another known point. The program then calculates a correction which has to be applied to the horizontal angle on the instrument so that the instrument is orientated. The angle is donated by "SD" in the above routine. The value of "b" then gets added to the back of "SD" which gets transmitted to the instrument and changes the horizontal angle on the instrument.

I have sorted out all the instruments on the market, except for the Topcon:(

Thanks
Michael
 

agraham

Expert
Licensed User
Longtime User
q%= ASC(MID$(SD$,i%,1))

That does not look like q% ends up as a logical value :confused: it looks more like a character! Is SD an angle expressed as a numeric string and can it be fractional?

EDIT:- I've seen the format above the B4ppc code, I was looking at the OPL. That doesn't look like its calculating any sort of correction and it's not a logical algorithm - it looks more like a bitwise calculation of a checksum!
 
Last edited:

ceaser

Active Member
Licensed User
SD is a numeric string - format dddmmss. The horizontal angle gets converted elsewhere in the program to a string.

Thanks
Michael
 

ceaser

Active Member
Licensed User
Agraham, you are right. It is a checksum calculation. The actual angle calculation (SD) gets done elsewhere in the program. This calculation gets added on at the end of "SD" and gets transmitted to the instrument.

I got the routine from the Topcon reference manual and it works in OPL.

Thanks
Michael
 

agraham

Expert
Licensed User
Longtime User
I was looking at the OPL not your code. You don't say in what way it "does not work" so I assumed it was an alogrithm error but looking at your B4PPC code you've got the syntax all wrong!

B4X:
b = 0
For i = 0 To  StrLength(SD) - 1
   q=Asc(SubString(SD,i,1))
   b1= Bit.AND(q, Bit.Complement(b))
   b2= Bit.AND (b, Bit.Complement(q))
   b = Bit.OR(b1,b2)
Next
SD=SD & Format(Abs(b),"D3") & Chr(3)
 

ceaser

Active Member
Licensed User
Agraham.............IT WORKS!!:sign0188:

Thank you very much for your help.

Regards
Michael
 
Top