VERSION 5.00
Begin VB.UserControl CtrlNumber 
   ClientHeight    =   300
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   1710
   ScaleHeight     =   300
   ScaleWidth      =   1710
   ToolboxBitmap   =   "CtrlNumber.ctx":0000
   Begin VB.TextBox Text1 
      Alignment       =   1  'Right Justify
      Height          =   285
      Left            =   0
      TabIndex        =   0
      Top             =   0
      Width           =   1695
   End
End
Attribute VB_Name = "CtrlNumber"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Dim VALOR As Boolean
Dim cadcero As Boolean
Dim NroDec As Integer
Dim NroEnt As Integer
Dim Switch As Integer
Public NroValido As Boolean
Event change()
Event click()
Event KeyPress(KeyAscii As Integer)
Event KeyDown(KeyCode As Integer, Shift As Integer)
Event KeyUp(KeyCode As Integer, Shift As Integer)

Private Sub Text1_Change()
    RaiseEvent change
End Sub

Private Sub Text1_Click()
    RaiseEvent click
End Sub

Private Sub Text1_GotFocus()
    Text1.SelStart = 0
    Text1.SelLength = Len(Text1.Text)
    Text1.MaxLength = LongitudMax
End Sub

Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
RaiseEvent KeyDown(KeyCode, Shift)
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
    RaiseEvent KeyPress(KeyAscii)
    Dim ln As Integer
    Dim Pos As Integer
    Dim Pos2 As Integer
    
    Pos = InStr(1, Text1.Text, ".", vbTextCompare)
    Pos2 = InStr(1, Text1.Text, "-", vbTextCompare)
    
    ln = Len(Text1.Text)
    If (KeyAscii > 47 And KeyAscii < 58) Or KeyAscii = 46 Or KeyAscii = 8 Or KeyAscii = 45 Then
        If Text1.SelLength = Len(Text1.Text) Then
            Exit Sub
        End If
        If VALOR = False And KeyAscii = 45 Then
            KeyAscii = 0
            Exit Sub
        End If
        If VALOR = True And KeyAscii = 45 Then
            If Text1.SelStart <> 0 Or Pos2 <> 0 And Text1.SelLength <> ln Then
                KeyAscii = 0
                Exit Sub
            End If
        End If
'        If ln = LongitudMax - 1 And Pos = 0 And _
'                Text1.SelLength = Len(Text1.Text) And _
'                    KeyAscii <> 46 And KeyAscii <> 8 Then
'            Text1.Text = Trim(Str(Chr(KeyAscii)))
'            Text1.SelStart = ln
'            A = Text1.Text
'            Exit Sub
'        End If
        If KeyAscii = 46 And NroDec = 0 Then
            KeyAscii = 0
            Exit Sub
        End If
        If KeyAscii = 46 Then
            ln = Len(Text1.Text)
            If Text1.SelStart < ln - NroDec Then
                KeyAscii = 0
            End If
        End If
        If Pos <> 0 Then
            If KeyAscii <> 46 Then
                ln = Len(Text1.Text)
                If NroDec = ln - Pos Then
                    For i = 0 To ln - NroDec - 1
                        Select Case Text1.SelStart
                        Case i
                            Exit Sub
                        End Select
                    Next
                    If KeyAscii = 8 Then
                        For i = ln To Pos Step -1
                        Select Case Text1.SelStart
                            Case i
                                Exit Sub
                            End Select
                        Next
                    End If
                    KeyAscii = 0
                End If
            Else
                KeyAscii = 0
            End If
        Else
            If ln = NroEnt And NroDec <> 0 And KeyAscii <> 8 _
                    And KeyAscii <> 46 And Text1.SelStart = ln Then
                Text1.Text = Text1.Text & "."
                Text1.SelStart = ln + 1
                Exit Sub
            End If
            If ln >= LongitudMax - NroDec And Text1.SelStart >= LongitudMax - NroDec And KeyAscii <> 8 Then
                KeyAscii = 0
                Exit Sub
            End If
            If ln = LongitudMax - 1 And KeyAscii <> 46 And KeyAscii <> 8 And NroDec <> 0 Then
                KeyAscii = 0
                Exit Sub
            End If
        End If
        If KeyAscii <> 8 And Pos <> 0 And Text1.SelStart <= NroEnt And ln = LongitudMax - 1 Then
            KeyAscii = 0
            Exit Sub
        End If
    Else
       KeyAscii = 0
    End If
    Exit Sub
End Sub

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
RaiseEvent KeyUp(KeyCode, Shift)
End Sub

Private Sub Text1_LostFocus()
    On Error GoTo merror
    Dim ln As Integer
    Dim Pos As Integer
    Pos = InStr(1, Text1.Text, ".", vbTextCompare)
    ln = Len(Text1.Text)
    If NroDec <> 0 Then
        If (Pos = 0 Or Pos > NroEnt + 1) And ln > Text1.MaxLength - NroDec - 1 Then
                Text1.SetFocus
                NroValido = False
                Exit Sub
        End If
        Estado = True
    End If
    NroValido = True
    If cadcero = True Then
        If Trim(Text1.Text) = "" Then
            Exit Sub
        End If
        If Text1.Text = "0" Then
            Exit Sub
        End If
        If Val(Text1.Text) = 0 Then
            Text1.Text = ""
            Exit Sub
        End If
    End If
    Select Case NroDec
    Case 0
        Text1.Text = Format(Val(Text1.Text), "##0")
    Case 1
        Text1.Text = Format(CDbl(Text1.Text), "##0.0")
    Case 2
        Text1.Text = Format(CDbl(Text1.Text), "##0.00")
    Case 3
        Text1.Text = Format(CDbl(Text1.Text), "##0.000")
    Case 4
        Text1.Text = Format(CDbl(Text1.Text), "##0.0000")
    Case 5
        Text1.Text = Format(CDbl(Text1.Text), "##0.00000")
    Case 6
        Text1.Text = Format(CDbl(Text1.Text), "##0.000000")
    Case 7
        Text1.Text = Format(CDbl(Text1.Text), "##0.0000000")
    Case 8
        Text1.Text = Format(CDbl(Text1.Text), "##0.00000000")
    End Select
    Text1.Alignment = 1
    Exit Sub
merror:
        If cadcero = True And Trim(Text1.Text) = "" Then
            Exit Sub
        End If
        Text1.Text = "0"
        Select Case NroDec
        Case 0
            Text1.Text = Format(Val(Text1.Text), "##0")
        Case 1
            Text1.Text = Format(CDbl(Text1.Text), "##0.0")
        Case 2
            Text1.Text = Format(CDbl(Text1.Text), "##0.00")
        Case 3
            Text1.Text = Format(CDbl(Text1.Text), "##0.000")
        Case 4
            Text1.Text = Format(CDbl(Text1.Text), "##0.0000")
        Case 5
            Text1.Text = Format(CDbl(Text1.Text), "##0.00000")
        Case 6
            Text1.Text = Format(CDbl(Text1.Text), "##0.000000")
        Case 7
            Text1.Text = Format(CDbl(Text1.Text), "##0.0000000")
        Case 8
            Text1.Text = Format(CDbl(Text1.Text), "##0.00000000")
        End Select
        Text1.Alignment = 1
End Sub

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
    Text1.Alignment = PropBag.ReadProperty("Alignment", 1)
    Text1.SelStart = PropBag.ReadProperty("SelStart", 0)
    Text1.SelLength = PropBag.ReadProperty("SelLength", 0)
    Text1.BackColor = PropBag.ReadProperty("BackColor", 16777215)
    Set Text1.Font = PropBag.ReadProperty("Font", Ambient.Font)
End Sub

Private Sub UserControl_Resize()
    Text1.Width = UserControl.Width
    If UserControl.Height > 80 Then
        Text1.Height = UserControl.Height - 80
    Else
        UserControl.Height = 80
    End If
End Sub

Public Property Get Decimales() As Variant
   Decimales = NroDec
End Property

Public Property Let Decimales(ByVal vNewValue As Variant)
   NroDec = vNewValue
End Property

Public Property Get ValorPorDefectoIsNull() As Boolean
   ValorPorDefectoIsNull = cadcero
End Property

Public Property Let ValorPorDefectoIsNull(ByVal vNewValue As Boolean)
   cadcero = vNewValue
End Property

Public Property Get PermitirNegativos() As Boolean
   PermitirNegativos = VALOR
End Property

Public Property Let PermitirNegativos(ByVal vNewValue As Boolean)
   VALOR = vNewValue
End Property

Public Property Get Alignment() As Byte
   Alignment = Text1.Alignment
End Property

Public Property Let Alignment(ByVal vNewValue As Byte)
   Text1.Alignment = vNewValue
   PropertyChanged "Alignment"
End Property

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
    Call PropBag.WriteProperty("Alignment", Text1.Alignment, 1)
    Call PropBag.WriteProperty("SelStart", Text1.SelStart, 0)
    Call PropBag.WriteProperty("SelLength", Text1.SelLength, 0)
    Call PropBag.WriteProperty("BackColor", Text1.BackColor, 16777215)
    Call PropBag.WriteProperty("Font", Text1.Font, Ambient.Font)
End Sub

Public Property Get Enteros() As Variant
   Enteros = NroEnt
End Property

Public Property Let Enteros(ByVal vNewValue As Variant)
   NroEnt = vNewValue
End Property

Public Property Get SelStart() As Variant
   SelStart = Text1.SelStart
End Property

Public Property Let SelStart(ByVal vNewValue As Variant)
   Text1.SelStart = vNewValue
End Property

Public Property Get SelLength() As Variant
   SelLength = Text1.SelLength
End Property

Public Property Let SelLength(ByVal vNewValue As Variant)
   Text1.SelLength = vNewValue
End Property

Public Function LongitudMax() As Integer
    If NroDec <> 0 Then
        LongitudMax = NroEnt + NroDec + 1
    Else
        LongitudMax = NroEnt + NroDec
    End If
End Function

Public Property Get Text() As Variant
   Text = Text1.Text
End Property

Public Property Let Text(ByVal vNewValue As Variant)
    Text1.Text = vNewValue
End Property

Public Sub ValorPorDefecto()
    If cadcero = True Then
        Text1.Text = ""
        Exit Sub
    Else
        Text1.Text = "0"
    End If
    Select Case NroDec
    Case 0
        Text1.Text = Format(Val(Text1.Text), "##0")
    Case 1
        Text1.Text = Format(CDbl(Text1.Text), "##0.0")
    Case 2
        Text1.Text = Format(CDbl(Text1.Text), "##0.00")
    Case 3
        Text1.Text = Format(CDbl(Text1.Text), "##0.000")
    Case 4
        Text1.Text = Format(CDbl(Text1.Text), "##0.0000")
    Case 5
        Text1.Text = Format(CDbl(Text1.Text), "##0.00000")
    Case 6
        Text1.Text = Format(CDbl(Text1.Text), "##0.000000")
    Case 7
        Text1.Text = Format(CDbl(Text1.Text), "##0.0000000")
    Case 8
        Text1.Text = Format(CDbl(Text1.Text), "##0.00000000")
    End Select
End Sub

Public Property Get Enabled() As Boolean
   Enabled = Text1.Enabled
   Enabled = UserControl.Enabled
End Property

Public Property Let Enabled(ByVal vNewValue As Boolean)
   Text1.Enabled = vNewValue
   UserControl.Enabled = vNewValue
End Property

Public Property Get BackColor() As ColorConstants
   BackColor = Text1.BackColor
End Property

Public Property Let BackColor(ByVal vNewValue As ColorConstants)
   Text1.BackColor = vNewValue
End Property



'ADVERTENCIA: NO QUITAR NI MODIFICAR LAS SIGUIENTES LINEAS CON COMENTARIOS
'MappingInfo=Text1,Text1,-1,Font
Public Property Get Font() As Font
Attribute Font.VB_Description = "Devuelve un objeto Font."
Attribute Font.VB_UserMemId = -512
    Set Font = Text1.Font
End Property

Public Property Set Font(ByVal New_Font As Font)
    Set Text1.Font = New_Font
    PropertyChanged "Font"
End Property

