Simple Compare String - Cannot Get it To Work

Hi all,

real simple question here, i have four values, which i am trying to check against each other. I have written the following:

if CurrentWeightPoundsBox.Text and CurrentWeightStonesBox.Text = AimPoundsBox.Text and AimStonesBox.Text then MsgBox "same" else MsgBox "not same" end if

and also tried:

[code] dim warningcurrentpounds as Integer
dim warningcurrentstones as Integer
dim warningaimpounds as Integer
dim warningaimstones as Integer

warningcurrentpounds = val(CurrentWeightPoundsBox.Text)
warningcurrentstones = val(CurrentWeightStonesBox.Text)
warningaimpounds = val(AimPoundsBox.Text)
warningaimstones = val(AimStonesBox.Text)

if warningcurrentpounds and warningcurrentstones = warningaimpounds and warningaimstones then
MsgBox “same”
else
MsgBox “not same”
end if[/code]

Each time i run it i get told it expected a Boolean… Can someone please point out the error of my ways.

if CurrentWeightPoundsBox.Text and CurrentWeightStonesBox.Text = AimPoundsBox.Text and AimStonesBox.Text then

CurrentWeightPoundsBox.Text is not a boolean
nor is AimStonesBox.Text

are you trying to see if these two contain the same text & are not empty ?

if ( CurrentWeightPoundsBox.Text <> “” ) and (AimStonesBox.Text <> “” ) and (CurrentWeightStonesBox.Text = AimPoundsBox.Text) then

Hi Norman,

just checking if they match, when i use the above and both boxes have the same, i get the msgbox returning “not the same”

Norm is right though.
if CurrentWeightPoundsBox.Text and CurrentWeightStonesBox.Text = AimPoundsBox.Text and AimStonesBox.Text

can be seen as
if (something) and (something = something else) and (something else) then

each of these is evaluated as a boolean: true or false
There aren’t being tested as strings apart from the bit in the middle.

What you want is

if (CurrentWeightStonesBox.Text = AimPoundsBox.Text) and (AimStonesBox.Text > "") then

because now you have 2 separate true/false things to evaluate.
The first says ‘are they the same’
The second says ‘and greater than an empty string’

(Obviously if they are the same and one is greater than “” there is no need to check the other)

Just an aside: Get used to using “not equal to” instead of “greater than” or “less than” where appropriate, so:

… and (AimStonesBox.Text <> "") then

“<>” runs slightly faster.

[quote=57415:@Jay maxted]
just checking if they match, when i use the above and both boxes have the same, i get the msgbox returning “not the same”[/quote]

Not sure why you’d include CurrentWeightPoundsBox.Text as in

  [quote]if CurrentWeightPoundsBox.Text[/quote]

Just

if CurrentWeightStonesBox.Text = AimPoundsBox.Text then MsgBox "same" else MsgBox "not same" end if
will check if they hold text that is the same (ignoring case)

IF requires a boolean comparison (i.e./ the syntax is IF THEN )

Breaking down your original
if CurrentWeightPoundsBox.Text and CurrentWeightStonesBox.Text = AimPoundsBox.Text and AimStonesBox.Text then

CurrentWeightPoundsBox.Text return a string - that in itself is NOT a problem
AND takes EITHER 2 booleans ( boolean AND boolean ) or bitwise operations ( number AND number which gives a number )
see http://documentation.xojo.com/index.php/And
So STRING (CurrentWeightPoundsBox.Text) AND
makes no sense

I believe your problem is that you are trying to compare A=B and C=D by using If A and C = B and D Then
You can’t do that. You have to code as

If (A = B) AND (C = D) Then