Resumen Manejo del MaskEdit con decimales

Mensaje enviado por "Ariel Fernando Alvarez" <afatronik@yahoo.com> el 1/04/2002

Tengo una pequeña Rutina que La baje de MS para hacer que un maskeditbox que este formateado por ejemplo ####,## no haya necesidad de tipear los ceros delante.
Sino que al ir presionando los numeros, cuando se presiona la coma, pasa el cursor a los decimales.

La rutina es la siguiente

en un VBP nuevo, creen 1 Form con 2 maskedbox.
les paso el codigo VB para poner dentro de ese form.
salu2



--------------------
Add two Masked Edit controls (MaskedEdit1 and MaskedEdit2) to Form1, and assign these properties:


   Default Name Mask Format PromptChar
   -------------------------------------------------
   MaskedEdit1 #####.## $####0.00 (Space)
   MaskedEdit2 #####.## $####0.00 (Space)

Add the following code to the GotFocus event of MaskedEdit1:


   Sub MaskedEdit1_GotFocus ()
      maskededit1.SelStart = 0
      maskededit1.SelLength = Len(maskededit1)
   End Sub

Add the following code to the KeyPress event of MaskedEdit1:

   Sub MaskedEdit1_KeyPress (keyascii As Integer)
      Call Masked_Key_Press(MaskedEdit1, keyascii)
      If keyascii = 13 Then SendKeys "{tab}"
   End Sub

Add the following code to the GotFocus event of MaskedEdit2:

   Sub MaskedEdit2_GotFocus ()
      maskededit2.SelStart = 0
      maskededit2.SelLength = Len(MaskedEdit2)
   End Sub

Add the following code to the Keypress event of MaskedEdit2:

   Sub MaskedEdit2_KeyPress (keyascii As Integer)
      Call Masked_Key_Press(MaskedEdit2, keyascii)
      If keyascii = 13 Then SendKeys "{tab}"
   End Sub

Add the following Sub procedure to the general declarations section of the form:

   Sub Masked_Key_Press (MskEdit As MaskEdBox, keyascii As Integer)

      ' Calculate the location of the decimal point in the mask:
      mask_cents_pos = InStr(MskEdit.Mask, ".")
      mask_dollars = mask_cents_pos - 1

      ' Check for period keypress:
      If keyascii = 46 And MskEdit.SelStart < 6 Then
         tlen = MskEdit.SelStart + 1 ' Store current location.
         MskEdit.SelStart = 0
         MskEdit.SelLength = tlen ' Highlight up to the current
         tempo = MskEdit.SelText ' position & save selected text.
         MskEdit.SelLength = mask_dollars
         MskEdit.SelText = "" ' Clear to the left of decimal.
         MskEdit.SelStart = mask_cents_pos - tlen
         MskEdit.SelLength = tlen ' Reposition caret
         MskEdit.SelText = tempo ' and paste copied data.
         MskEdit.SelStart = mask_cents_pos ' Position caret after cents.
      End If
   End Sub
----------------------------
Ariel Alvarez



Resumen Resumen

Visual Basic Página de Visual Basic

Página principal Página principal

www.jrubi.com