
Basic Data Operation

This is a basic data operation. It represents a fundamental action on a basic data type.
You may see other such operations in the Basic Data Operations category, or:


Integer Operations
Arithmetic |
Comparison
Boolean Operations
Bitwise |
Logical
String Operations
Concatenation |
Interpolation |
Comparison |
Matching
Memory Operations
Pointers & references |
Addresses


Get two integers from the user.

Then,   display a message if the first integer is:

   less than, 
   equal to,   or 
   greater than
the second integer.



Test the condition   for each case separately,   so that   all three comparison operators are used   in the code.



Related task

   String comparison


_window = 1
begin enum 1
  _integer1Fld
  _integer2Fld
  _compareBtn
  _messageLabel
end enum
 
local fn BuildWindow
  window _window, @"Integer Comparison", (0,0,356,85)
 
  textfield _integer1Fld,,, (20,44,112,21)
  TextFieldSetPlaceholderString( _integer1Fld, @"Integer 1" )
 
  textfield _integer2Fld,,, (140,44,112,21)
  TextFieldSetPlaceholderString( _integer2Fld, @"Integer 2" )
 
  button _compareBtn,,, @"Compare", (253,38,90,32)
 
  textlabel _messageLabel,, (18,20,320,16)
  ControlSetAlignment( _messageLabel, NSTextAlignmentCenter )
end fn
 
local fn DoDialog( ev as long, tag as long )
  long int1, int2
 
  select ( ev )
    case _btnClick
      select ( tag )
        case _compareBtn
          int1 = fn ControlIntegerValue( _integer1Fld )
          int2 = fn ControlIntegerValue( _integer2Fld )
 
          if ( int1 < int2 ) then textlabel _messageLabel, @"The first integer is less than the second integer."
          if ( int1 == int2 ) then textlabel _messageLabel, @"The first integer is equal to the second integer."
          if ( int1 > int2 ) then textlabel _messageLabel, @"The first integer is greater than the second integer."
 
      end select
 
    case _controlTextDidChange
      textlabel _messageLabel, @""
  end select
end fn
 
fn BuildWindow
 
on dialog fn DoDialog
 
HandleEvents