Usuário com melhor resposta
Calcular porcentagem.

Pergunta
-
Boa noite. Estou com uma dúvida bem boba aqui.
Preciso calcular a margem de lucro de um produto
que seria o txtCusto + txtindice em % pra dar o resultado no txtVenda.
Coloquei o seguinte código, porém o calculo está dando errado.
Private Sub txtIndice_LostFocus(sender As Object, e As EventArgs) Handles txtIndice.LostFocus If txtCusto.Text = "" Then Exit Sub If txtIndice.Text = "" Then Exit Sub txtVenda.Text = ((txtCusto.Text) + (txtIndice.Text * 2 / 100)) End Sub
Exemplo: custo: 1.25 + 100% = 2,50
Agradeço!
Respostas
-
Bom dia Thiago Marcondes,
Como vc está calculando lucro, recomendo você fazer o seguinte, criar uma função chamada CalcuVenda, e chamar no LostFocus do txtIndice, e no LostFocus do txtCusto, assim vc consegue recalcular se mudar o custo.
Veja como ficou:
Private Sub CalculaVenda() If txtCusto.Text = "" Then Exit Sub If txtIndice.Text = "" Then Exit Sub Dim decCusto As Decimal Dim decIndice As Decimal If Decimal.TryParse(txtCusto.Text, decCusto) And Decimal.TryParse(txtIndice.Text, decIndice) Then txtVenda.Text = ((decCusto) + (decCusto * (decIndice / 100))).ToString() End If End Sub
Att, Lucio Rogerio
Espero ter ajudado, se ajudei, por favor Vote como Útil, e se resolvi seu problema, clique em Marcar como Resposta.- Marcado como Resposta Filipe B CastroModerator quinta-feira, 1 de março de 2018 16:53
quinta-feira, 1 de março de 2018 12:12 -
Bom dia.
Tente assim:
Private Sub txtIndice_LostFocus(sender As Object, e As EventArgs) Handles txtIndice.LostFocus If txtCusto.Text = "" Then Exit Sub If txtIndice.Text = "" Then Exit Sub txtVenda.Text = ( cdec(txtCusto.Text) * (1 + (cdec(txtIndice.Text) / 100))).ToString End Sub
MARIANO1776
- Marcado como Resposta Thiago Marcondes quinta-feira, 1 de março de 2018 21:42
Todas as Respostas
-
Bom dia.
Tente assim:
Private Sub txtIndice_LostFocus(sender As Object, e As EventArgs) Handles txtIndice.LostFocus If txtCusto.Text = "" Then Exit Sub If txtIndice.Text = "" Then Exit Sub txtVenda.Text = ( cdec(txtCusto.Text) * (1 + (cdec(txtIndice.Text) / 100))).ToString End Sub
MARIANO1776
- Marcado como Resposta Thiago Marcondes quinta-feira, 1 de março de 2018 21:42
-