Page 1 of 1

What does "==" mean?

Posted: Tue Jun 28, 2016 12:22 am
by Susan Smith
Hi,

I saw a line in one of Gabriel's programs that said

75264 IF (2==MSGBOX("This window ("&TRIM$(SCREENIO$(SI_SCREENCODE))&") is bigger then its parent window (#"&STR$(PARENTWINDOW)&"). Do you wish to debug?","Error","yN")) THEN

Can someone tell me what "==" means? I couldn't find it in the wiki. Could the statement also have been written like this:

75264 IF MSGBOX("This window ("&TRIM$(SCREENIO$(SI_SCREENCODE))&") is bigger then its parent window (#"&STR$(PARENTWINDOW)&"). Do you wish to debug?","Error","yN"))=2 THEN

?

-- Susan

Re: What does "==" mean?

Posted: Tue Jun 28, 2016 3:46 am
by GomezL
http://brwiki2.brulescorp.com/index.php ... Operations

== is a Boolean expression

1==2 Returns false or 0
1==1 returns true or 1

I sometimes use it in a formula

Print (a==100)*100

This example returns 100 only if a=100

Print (a>100)*100

This example returns 100 only if a>100


In the example you provided it's probably redundant.

Re: What does "==" mean?

Posted: Tue Jun 28, 2016 8:14 am
by Susan Smith
Thank you so much Luis! When I put "==" into the search box in the wiki, it didn't turn up anything. I never thought to go to the assignment operations section because I thought that the search box caught everything. I appreciate it- thank you!

-- Susan

Re: What does "==" mean?

Posted: Tue Jun 28, 2016 9:07 am
by gordon
BR (WB) has always supported two special forms of assignment in addition to the regular form.

A simple single equal sign ( = ) is context sensitive. If it occurs in a conditional clause such as IF A = B THEN, it signifies comparison. If it occurs outside of a comparison clause it signifies assignment, meaning assign the value of B to A.

Two special versions of the = operator exist that are NOT context sensitive:
  • A == B means compare A to B and return a numeric value one if they are equal, otherwise return zero.
    A := B means assign the value of B to A.
Besides being a little more readable, these operators can be quite useful. For example:

Code: Select all

IF ( X := A+B+C) > 5 then !:
   FNA( X )
This form of assignment is referred to as an embedded assignment, meaning the sum of A+B+C is assigned to X and the result is then compared to 5. Then later the value X can be used as needed. This works for both numeric and string comparison clauses (but mixing string and numeric of course is not allowed).

Embedded assignments can also be used when calling functions that require a variable parameter as in:

Code: Select all

DEF FNCONCAT$(&A$, &B$) = A$ & B$
LET C$ = FNCONCAT$(A$, DUMMY$ := "suffix")
This simple user defined function concatenates two string values. However it requires both parameters to be passed by reference. So to pass it a literal, I use an embedded assignment of the the literal to a variable when calling that function. In this case use of the := form of assignment is optional, but I find it more readable.

The == operator can also be useful as in:

Code: Select all

IF condition-1 THEN LET A$ = B$(1: 9999 * (FLAG$ == "Y") )  & C$(1: 9999 * (FLAG$ <> "Y") )
Sometimes it is inconvenient to break out IF THEN logic into separate statements, as in a LET statement that is itself part of a THEN clause. IF condition-1 is true, then the above example assigns either the value of B$ or C$ to A$, depending on whether FLAG$ is set to "Y".

Re: What does "==" mean?

Posted: Tue Jun 28, 2016 9:24 am
by Susan Smith
This is an EXCELLENT explanation of this concept. Thank you very much Gordon. I just never realized that it was in the language. It goes to show you that you have to go back to the beginning now and then and pick up things that you either missed or never noticed way back when.

-- Susan

Re: What does "==" mean?

Posted: Wed Jun 29, 2016 10:40 am
by GomezL
Knowing the answer makes it much easier.

I looked up "Boolean", and Assignment Operations was the first result.

I just noticed there is another page that is much more on point

http://brwiki2.brulescorp.com/index.php ... Expression