'Code module
'Subs in this code module will be accessible from all modules.
Sub Process_Globals
'...
'                                            I created a Type structure to hold more than the allowed 2 parameters in the Callsub back to MAIN
 Type TxtItem(Old As String, New As String, Tag As B4XPrefItem)
'                                            I update the B4xPrefItem to contain the new information
Type B4XPrefItem (Title As String, ItemType As Int, Extra As Map, _
      Key As String, Required As Boolean, _
      Default As Object, Mask As String, _
      Link As String, ToolTip As String, Options As List)
'...
'                                            In loadfromJSON, I added parameters to the JSON file
'...
 For Each item As Map In items
  Dim key As String = item.Get("key")
  Dim Link As String = item.Get("link")
  Dim ToolTip As String = item.Get("tooltip")
  Dim title As String = item.Get("title")
  Dim required As Boolean = item.Get("required")
  Dim options As List = item.Get("options")
  If options.IsInitialized = False Then
   options.Initialize
  End If
  Dim itemType As String = item.Get("type")
  Dim default As String = item.Get("default")
  Dim mask As String = item.Get("mask")
      'Title As string, ItemType As Int, Key As String, Default As String, Mask As String, Required As Boolean, Options As List
  Dim pi As B4XPrefItem = CreatePrefItem(title, key, default, mask, required, Link, ToolTip, options)
'                                                I built the prefitems at the top instead of repeatedly within the Select Case for convenience
  Select itemType
   Case "Separator"
    pi.ItemType = TYPE_SEPARATOR
    AddSeparator(pi)
   Case "Boolean"
    pi.ItemType = TYPE_BOOLEAN
    AddBooleanItem(pi)
'...
'                                                  in CreatePrefItem, I added the new items to the B4xPrefItem Type structure
Private Sub CreatePrefItem(Title As String, Key As String, _
      Default As String, Mask As String, Required As Boolean, _
      Link As String, ToolTip As String, _
      Options As List) As B4XPrefItem
    Dim pi As B4XPrefItem
    pi.Initialize
    pi.Link = Link
    pi.ToolTip = ToolTip
    pi.Title = Title
    pi.Key = Key
    pi.Default = Default
    pi.Mask = Mask
    pi.Required = Required
    pi.Options = Options
    Return pi
End Sub
'                                                 add the events that call MAIN validation subs
Private Sub B4XFloatTextField1_EnterPressed
    Dim B4xFld As B4XFloatTextField
    B4xFld = Sender
    Dim edtText As EditText = B4xFld.TextField
    Dim p As B4XView = B4xFld.TextField.Parent.parent
    Dim tg As B4XPrefItem = p.Tag
    If SubExists(Main, "Text_EnterPressed") Then
        CallSub3(Main, "Text_EnterPressed", edtText, tg)
    End If
End Sub
private Sub B4XFloatTextField1_TextChanged (Old As String, New As String)  'text/multiline text
    Dim B4xFld As B4XFloatTextField
    B4xFld = Sender
    Dim p As B4XView = B4xFld.TextField.Parent.parent
    Dim This As TxtItem
    This.Tag = p.Tag
    This.Old = Old
    This.New = New
    Log("TEXT CHANGED " & Old & "   new " & New)  'also password
    If SubExists(Main, "Text_Changing") Then
        CallSub2(Main, "Text_Changing", This)
    End If
End Sub
'                    The below have not been coded yet, they are here as placeholders for now...
Private Sub B4XSwitch1_ValueChanged (Value As Boolean) 'boolean
    If SubExists(Main, "Boolean_Changed") Then
        CallSub2(Main, "Boolean_Changed", Value)
    End If
End Sub
Private Sub PM_ValueChanged (Value As Object)   'Plus Minus/range
    If SubExists(Main, "PM_Changed") Then
        CallSub2(Main, "PM_Changed", Value)
    End If
End Sub
Private Sub pmHours_ValueChanged (Value As Object)
    If SubExists(Main, "PMHours_Changed") Then
        CallSub2(Main, "PMHours_Changed", Value)
    End If
End Sub
Private Sub pmMinutes_ValueChanged (Value As Object)
    If SubExists(Main, "PMMinutes_Changed") Then
        CallSub2(Main, "PMMinutes_Changed", Value)
    End If
End Sub
Private Sub pmAMPM_ValueChanged (Value As Object)
    If SubExists(Main, "PMAMPM_Changed") Then
        CallSub2(Main, "PMAMPM_Changed", Value)
    End If
End Sub
Private Sub B4XComboBox1_SelectedIndexChanged (Index As Int)
    If SubExists(Main, "B4xComboBox_Changed") Then
        Dim Value As String = B4XComboBox1.GetItem(Index)
        CallSub3(Main, "B4xComboBox_Changed", Index, Value)
    End If
End Sub