Jump to content

valor monetario


zaion35
 Share

Recommended Posts

tente esse

Dim Valor As Double
ValorTextBox.Text = Valor.ToString(ValorTextBox.Text)("N2")

depois

Dim Valor As Double
ValorTextBox.Text = Valor.ToString("N2", Globalization.CultureInfo.InvariantCulture)

e por fim esse

ValorTextBox.Text = Double.Parse(ValorTextBox.Text).ToString("c")

que me da a moeda corrente, mas este é no evento  lostfocus

EDIT: GeSHi adicionado

Link to comment
Share on other sites

Boas

Crias uma variável fora dos eventos.

Depois no evento KeyPress, adicionas o valor pressionado a essa variável

Dim valor_final As String
Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
     valor_final &= e.KeyChar
End Sub

No evento KeyUP, formatas a textbox, com o valor que o utilizador já tinha inserido

Private Sub TextBox1_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
     TextBox1.Text = Double.Parse(valor_final).ToString("N2")
End Sub

Quando voltar a entrar na textbox, limpas o valor da variavel, e metes a textbox vazia

Private Sub TextBox1_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.Enter
     valor_final = 0
     TextBox1.Text = String.Empty
End Sub

A informática chegou para resolver problemas que antes não existiam

Quem ri por último é porque está conectado a 52 Kbs.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.