Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Abimael

Mascara Tipo banco eletronico.

Recommended Posts

Pessoal, resolvi tentar eu mesmo desenvolver o script que eu quero, ficou legal, porem se digitar rápido a pontuação não funciona direito, também quando eu tentei colocar um código para somente digitar números não funcionou, se alguém puder dar uma olhada no código e ver o que pode ser melhorado eu agradeceria.

 

 

 

Dim ContaDinDin As Long
Dim Monetario As String
Dim GuardaDim As String
Private Function Pontuacao()

	 Select Case ContaDinDin
	 Case 1
		Monetario = "0,0" & Text1.Text
		Text1.Text = Monetario
		Text1.SelStart = 4
	 Case 2
		Text1.Text = "0," & Mid(Text1.Text, 4, 2)
		Text1.SelStart = 4
	 Case 3
		Monetario = Right(Text1.Text, 3)  'Pega os tres ultimos numeros
		Text1.Text = Left(Monetario, 1) & "," & Right(Monetario, 2) 'Pega o primeiro numero +,+os dois ultimos
		 Text1.SelStart = 4
	 Case 4
		Monetario = Left(Text1.Text, 1) & Right(Text1.Text, 3)
		Text1.Text = Left(Monetario, 2) & "," & Right(Monetario, 2)
		Text1.SelStart = 5
	 Case 5
		Monetario = Left(Text1.Text, 2) & Right(Text1.Text, 3)
		Text1.Text = Left(Monetario, 3) & "," & Right(Monetario, 2)
		Text1.SelStart = 6
	 Case 6
		Monetario = Left(Text1.Text, 3) & Right(Text1.Text, 3)
		Text1.Text = Left(Monetario, 1) & "." & Mid(Monetario, 2, 3) & "," & Right(Monetario, 2)
		Text1.SelStart = 8
	 Case 7
		Monetario = Left(Text1.Text, 1) & Mid(Text1.Text, 3, 3) & Right(Text1.Text, 3)
		Text1.Text = Left(Monetario, 2) & "." & Mid(Monetario, 3, 3) & "," & Right(Monetario, 2)
		Text1.SelStart = 9
	 Case 8
		Monetario = Left(Text1.Text, 2) & Mid(Text1.Text, 4, 3) & Right(Text1.Text, 3)
		Text1.Text = Left(Monetario, 3) & "." & Mid(Monetario, 4, 3) & "," & Right(Monetario, 2)
		Text1.SelStart = 10
	 Case 9
		Monetario = Left(Text1.Text, 3) & Mid(Text1.Text, 5, 3) & Right(Text1.Text, 3)
		Text1.Text = Left(Monetario, 1) & "." & Mid(Monetario, 2, 3) & "." & Mid(Monetario, 5, 3) & "," & Right(Monetario, 2)
		
	   Text1.SelStart = 12
	   ' Text3.Text = Text1.Text
	 Case 10
		Monetario = Left(Text1.Text, 1) & Mid(Text1.Text, 3, 3) & Mid(Text1.Text, 7, 3) & Right(Text1.Text, 3)
		Text1.Text = Left(Monetario, 2) & "." & Mid(Monetario, 3, 3) & "." & Mid(Monetario, 6, 3) & "," & Right(Monetario, 2)
		Text1.SelStart = 13
	 Case 11
		Monetario = Left(Text1.Text, 2) & Mid(Text1.Text, 4, 3) & Mid(Text1.Text, 8, 3) & Right(Text1.Text, 3)
		Text1.Text = Left(Monetario, 3) & "." & Mid(Monetario, 4, 3) & "." & Mid(Monetario, 7, 3) & "," & Right(Monetario, 2)
		Text1.SelStart = 14
	Case 12
		Monetario = Left(Text1.Text, 3) & Mid(Text1.Text, 5, 3) & Mid(Text1.Text, 9, 3) & Right(Text1.Text, 3)
		Text1.Text = Left(Monetario, 1) & "." & Mid(Monetario, 2, 3) & "." & Mid(Monetario, 5, 3) & "." & Mid(Monetario, 8, 3) & "," & Right(Monetario, 2)
		Text1.SelStart = 16
	 End Select
   
End Function

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
	ContaDinDin = ContaDinDin + 1
	Pontuacao
End Sub

Compartilhar este post


Link para o post
Compartilhar em outros sites

Opa Abimael!

Fiz um código aqui, espero que seja isso que você queira!

Private Sub Text1_KeyUp(KeyCode As Integer, Shift As Integer)
Dim valor As String

valor = Text1.Text
valor = Replace(valor, ",", "")

For i = 1 To Len(valor)
If Left(valor, 1) = "0" Then
valor = Right(valor, Len(valor) - 1)
Else
Exit For
End If
Next

If Len(valor) < 2 Then
valor = "0,0" & valor
ElseIf Len(valor) < 3 Then
valor = "0," & valor
Else
valor = Left(valor, Len(valor) - 2) & "," & Right(valor, 2)
End If

valor = Format(valor, "#,#0.00")

Text1.Text = valor
Text1.SelStart = Len(Text1.Text)
End Sub

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.