sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private ed As EditText
Private maxSize As Int = 5
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Activity.LoadLayout ("My_layout")
ed.Initialize("ed")
Activity.AddView(ed,0,0,100%x,30dip)
End Sub
Sub ed_TextChanged (Old As String, New As String)
If New.Length > maxSize Then
ed.Text = Old
End If
End Sub
Sub EditTexts_TextChanged (Old As String, New As String)
edt = Sender
ValorTex=edt.Text
Rutinas.Descompon_Tag(edt)
Select Rutinas.NombreAlf
Case "Alf_1"
If Alf_1.Text <> "" Then Rutinas.Ctrl_Longitud(Alf_1,Rutinas.MaxCaracteres,Rutinas.Numdecimales)
End Select
End Sub
Sub Descompon_Tag(edt As EditText )
PosiIni=InStr(edt.Tag,"|")
' Saco el Nombre del Text y los caracteres que tiene que llevar
If PosiIni <> 0 Then
NombreAlf=Left(edt.Tag,PosiIni-1)
' Compruebo si trae decimales
PosiPunto=InStr(edt.Tag,".")
If PosiPunto=0 Then
Numdecimales=0
Else
Numdecimales=Mid(edt.Tag,PosiPunto+1,3)
End If
If PosiPunto-1 <= 0 Then
MaxCaracteres=Mid(edt.Tag, PosiIni+1,3)
Else
MaxCaracteres=MidLargo(edt.Tag,PosiIni,PosiPunto-1)
End If
End If
Sub Ctrl_Longitud(CtrlAlf As EditText,Maxca As String,Ndecimales As Int)
Dim ControlCaracteres As Int
ControlCaracteres=Miracaraceteres(CtrlAlf.Text,MaxCaracteres,Ndecimales)
If ControlCaracteres =1 Then
CtrlAlf.Text =Poncaracteres(CtrlAlf.Text,MaxCaracteres): CtrlAlf.SelectionStart =MaxCaracteres
Else If ControlCaracteres =2 Then
CtrlAlf.Text =Poncaracteres(CtrlAlf.Text,Ndecimales): CtrlAlf.SelectionStart =InStr(CtrlAlf.Text,".")+Ndecimales
Else If ControlCaracteres =3 Then
CtrlAlf.Text =Poncaracteres(CtrlAlf.Text,(MaxCaracteres-Ndecimales-1)): CtrlAlf.SelectionStart =(MaxCaracteres-Ndecimales-1)
End If
End Sub
Sub Miracaraceteres(Text As String,Longitud As Int,Ndecimales As Int) As Int
' 0 es Correcto
' 1 se pasa de caracteres
' 2 se pasa de decimales
' 3 se pasa de enteros
If Ndecimales <> 0 Then
PosiIni=InStr(Text,".")
If PosiIni <> 0 Then
If Len(Mid(Text,PosiIni+1,3)) > Ndecimales Then
ToastMessageShow("Maximo de Decimales.: " & Ndecimales , False)
Return 2
End If
Else
If Text.Length > (Longitud-Ndecimales-1) Then
ToastMessageShow("Maximo de Caracteres.: " & (Longitud-Ndecimales-1) , False)
Return 3
End If
End If
Else If Text.Length > Longitud Then
ToastMessageShow("Maximo de Caracteres.: " & Longitud , False)
Return 1
Else
Return 0
End If
End Sub
Sub Poncaracteres(Text As String, Length As Long)As String
PosiIni=InStr(Text,".")
If PosiIni <> 0 Then
Return Text.SubString2(0, PosiIni+Length)
Else
Return Text.SubString2(0, Length)
End If
End Sub