Sub EditFCaducidad_TextChanged (Old As String, New As String)
Dim Edit = Sender As EditText
MascaraFecha(Edit, Old, New)
End Sub
Sub EditFAlbaran_TextChanged (Old As String, New As String)
Dim Edit = Sender As EditText
MascaraFecha(Edit, Old, New)
End Sub
Sub MascaraFecha(Edit As EditText, Old As String, New As String)
Log("Old: " & Old & " - New: " & New)
If New.Length > Old.Length And "01234567890/".IndexOf(New.CharAt(New.Length-1)) = -1 Then Edit.Text = Old
If (New.Length = 3) And (New.CharAt(2) <> "/") Then Edit.Text = Edit.text.SubString2(0,2) & "/" & New.CharAt(2)
If (New.Length = 6) And (New.CharAt(5) <> "/") Then Edit.Text = Edit.text.SubString2(0,5) & "/" & New.CharAt(5)
If (New.Length = 8) And (New.Length > Old.Length) Then
If IsValidDate(New) Then
DateTime.DateFormat="dd/MM/yy"
Dim DateAux = DateTime.DateParse(New) As Long
DateTime.DateFormat="dd/MM/yyyy"
Edit.Text = DateTime.Date(DateAux)
Else
Msgbox("Fecha incorrecta", "Aviso")
End If
End If
Edit.SelectionStart = Edit.Text.Length
ime1.SetCustomFilter(Edit, Edit.INPUT_TYPE_NUMBERS, "0123456789/")
End Sub
Sub IsValidDate(Date As String) As Boolean
Try
DateTime.DateParse(Date)
Return True
Catch
Return False
End Try
End Sub