Demonstrate how to define a type that behaves like an integer but has a lowest valid value of 1 and a highest valid value of 10. Include all bounds checking you need to write, or explain how the compiler or interpreter creates those bounds checks for you.

' FB 1.05.0 Win64
 
Type MyInteger
  Private:
    Dim i_ As Integer
  Public:
    Declare Constructor(i_ As Integer) 
    Declare Property I() As Integer 
    Declare Operator Cast() As Integer
    Declare Operator Cast() As String        
End Type
 
Constructor MyInteger(i_ As Integer)
  If i_ < 1 Then 
    i_ = 1
  ElseIf i_ > 10 Then
    i_ = 10
  End If 
  This.i_ = i_
End Constructor
 
Property MyInteger.I() As Integer
  Return i_
End Property
 
Operator MyInteger.Cast() As Integer
  Return i_
End Operator
 
Operator MyInteger.Cast() As String
  Return Str(i_)
End Operator
 
Dim i As MyInteger = 11 ' implicit constructor call;  i_ automatically limited to 10
Dim j As MyInteger = 3  ' implicit constructor call;  no adjustment needed
Dim k As Integer = 4
Print "i = "; i; "   j = " ; j; "   k = "; k; "   j + 6 ="; j.I + 6; "   j + k ="; j + k
Print
Print "Press any key to quit"
Sleep