variable declaration
  STATIC designX, designY, designWidth, designHeight
  STATIC upperMessage
  STATIC XuiDialog2B

Lines 8 - 11 declare static variables.  These variables are local to the grid function and they retain their values between subsequent calls.

designX ,designY are the x,y position of the design window when it was converted into a grid function by WindowToFunction, in display coordinates, with 0,0 in upper-left corner of the display.

designWidth ,designHeight are the width and height of the design window in pixels when it was converted into a grid function.

sub[] is an array that contains a subroutine address for every message number.  In typical grid functions, most locations contain a zero, so no subroutine is executed for the corresponding message.

upperMessage holds the highest defined message number.

XuiDialog2B contains the grid type number.

kid constant definitions
  $XuiDialog2B = 0 ' kid 0
  $Label       = 1 ' kid 1
  $TextLine    = 2 ' kid 2
  $Button0     = 3 ' kid 3
  $Button1     = 4 ' kid 4

Lines 13 - 17 define kid constants to name the grid type components.

As always, the grid itself is always kid 0. The XuiLabel grid at the top of XuiDialog2B is kid 1, the XuiTextLine grid below it is kid 2, and the left and right hand XuiPushButton grids are kids 3 & 4.

Window ToFunction numbers kids in the order they are created in the Create subroutine.  This correspondence is absolutely necessary and must be maintained if you edit the Create subroutine.