/ Forums / Advansys Formativ / Formativ Creator / documentation / Reply To: documentation

#5506
Support 1a
Participant

Further to the above, because the masked edit controls don’t inherently know anything about what the data they collect represents, you need to write your own validation code. Here’s a simple example to get you started.

Sub Main(Client, GWEvent)
  Dlg.rzMaskEditTime.editmask = "!90:00;1;_"
  Dlg.showmodal
End Sub

' Validate the time when OK button pressed
sub btnOkClick(Sender)
  dim iPos
  dim iHour
  dim iMinutes

  iPos = instr(1, Dlg.rzMaskEditTime.text, ":", vbTextCompare)

  ' Make sure we have the seperator character exists
  if (iPos = 0) then
    exit sub
  end if

  ' Get the hour portion from the value
  iHour = trim(mid(Dlg.rzMaskEditTime.text, 1, iPos-1))

  ' Exit if the hour value not entered
  if (len(iHour) = 0) then
    msgbox("Enter hour.")
    exit sub
  end if

  iHour = cint(iHour)

  ' Exit, if the hour not in the valid range
  if (iHour >= 24) then
    msgbox("Enter valid hour.")
    exit sub
  end if

  ' Get the minute portion from the value
  iMinutes = trim(mid(Dlg.rzMaskEditTime.text, iPos + 1))

  ' Exit if the minute value not entered
  if (len(iMinutes) = 0) then
    msgbox("Enter minute.")
    exit sub
  end if

  iMinutes = cint(iMinutes)

  ' Exit, if the minute not in the valid range
  if (iMinutes >= 60) then
    msgbox("Enter valid minutes.")
    exit sub
  end if

  msgbox "Time entered: " & TimeSerial(iHour, iMinutes, 0)
End Sub

Advansys Support