In addition to fundamental GUI component interaction, an application should
dynamically enable and disable GUI components, to give some guidance to the
user, and prohibit (inter)actions which are inappropriate in the current state
of the application.



Task

Similar to the task GUI component interaction, write a program
that presents a form with three components to the user:

   a numeric input field ("Value") 
   a button   ("increment")
   a button   ("decrement")


The field is initialized to zero.
The user may manually enter a new value into the field,
increment its value with the "increment" button,
or decrement the value with the "decrement" button.

The input field should be enabled only when its value is zero.
The "increment" button only as long as the field's value is less then 10:
When the value 10 is reached, the button should go into a disabled state.
Analogously, the "decrement" button should be enabled only as long as
the value is greater than zero.

Effectively, the user can now either increment up to 10, or down to zero.
Manually entering values outside that range is still legal,
but the buttons should reflect that and enable/disable accordingly.




hValueBox As ValueBox                                             'We need a ValueBox
hButton0 As Button                                                'We need a button
hButton1 As Button                                                'We need another button
 
Public Sub Form_Open()
 
With Me                                                           'Set the Form's Properties..
  .height = 95                                                    'Set the Height
  .Width = 350                                                    'Set the Width
  .Arrangement = Arrange.Vertical                                 'Arrange items vertically
  .Padding = 5                                                    'Border area
  .Title = "GUI enable/disable"                                   'Title displayed on the Form 
End With
 
hValueBox = New ValueBox(Me) As "ValBox"                          'Add a ValueBox to the Form as Event 'ValBox'
 
With hValueBox                                                    'Set the ValueBox's Properties..
  .Expand = True                                                  'Expand the ValueBox
  .Value = 0                                                      'Set it's value to 0
End With
 
hButton0 = New Button(Me) As "ButtonInc"                          'Add a Button to the form as Event "ButtonInc"
 
With hButton0                                                     'Set the Button's Properties..
  .Height = 28                                                    'Set the Height
  .Text = "&Increment"                                            'Add Text (The '&' adds a keyboard shortcut)
End With
 
hButton1 = New Button(Me) As "ButtonDec"                          'Add a Button to the form as Event "ButtonDec"
 
With hButton1                                                     'Set the Button's Properties..
  .Height = 28                                                    'Set the Height
  .Text = "&Decrement"                                            'Add Text (The '&' adds a keyboard shortcut)
  .Enabled = False                                                'Disable the button
End With
 
End
 
Public Sub ButtonInc_Click()                                      'When the 'Increment' Button is clicked..
 
hValueBox.Value += 1                                              'Increase the Value in the ValueBox by 1
Checks
 
End
 
Public Sub ButtonDec_Click()                                      'When the 'Decrement' Button is clicked..
 
hValueBox.Value -= 1                                              'Increase the Value in the ValueBox by 1
Checks
 
End
 
Public Sub Checks()                                               'Checks the values to see which controls to en/disable
 
If hValueBox.Value = 0 Then                                       'If the ValueBox = 0 then..
  hValueBox.enabled = True                                        'Enable the control
Else                                                              'Else..
  hValueBox.enabled = False                                       'Disable the control
End If
 
If hValueBox.Value > 9 Then                                       'If the ValueBox greater than 9 then..
  hButton0.enabled = False                                        'Disable the control
Else                                                              'Else..
  hButton0.enabled = True                                         'Enable the control
End If
 
If hValueBox.Value < 1 Then                                       'If the ValueBox less than 1 then..
  hButton1.enabled = False                                        'Disable the control
Else                                                              'Else..
  hButton1.enabled = True                                         'Enable the control
End If
 
End
 
Public Sub ValBox_Leave()                                         'When the mouse leaves the ValueBox.. 
 
Checks                                                            'Rune the Checks routine
 
End