Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Pessoal, bom dia.
Estou tentando somar alguns valores com casas decimais que é resultado de cálculo de juros para uma textbox. Consegui fazer conforme abaixo, porém, o resultado não está considerando os valores após a virgula. Por gentileza, alguém poderia me ajudar? Obrigado!
Dim Vl1 As Double
Dim Vl2 As Double
Dim Vl3 As Double
Dim Vl4 As Double
Dim Vl5 As Double
Dim Vl6 As Double
Dim vl7 As Double
Dim vl8 As Double
Dim Soma As Double
Vl1 = val(TextBox46.text)
Vl2 = val(TextBox47.text)
Vl3 = val(TextBox48.text)
Vl4 = val(TextBox49.text)
Vl5 = val(TextBox50.text)
Vl6 = val(TextBox51.text)
vl7 = val(TextBox52.text)
vl8 = val(TextBox53.text)
Soma = Vl1 + Vl2 + Vl3 + Vl4 + Vl5 + Vl6 + vl7 + vl8
TextBox56.Value = Soma
Obrigado quintelab....
Deu certo a soma, exceto pq agora está somando o valores sem considerar as pontuações.
Dim Soma As Double
Soma = CDbl(TextBox46.text) + CDbl(TextBox47.text) + CDbl(TextBox48.text) + CDbl(TextBox49.text) + CDbl(TextBox50.text) + CDbl(TextBox51.text) + CDbl(TextBox52.text) + CDbl(TextBox53.text)
TextBox56.Value = Soma
Tive que converter para decimal americano para o Cdbl funcionar também, mas agora ele soma como se os valores fossem números inteiros.
Por exemplo:
textbox46 = 248.8
textbox47 = 250.1
total = 498.90
o resultado está dando = 4989
Obrigado. Deu certo, alterei de Cdbl para CCur e os valores estão sendo somados corretos. Isto sem a necessidade de conversão para decimal americano.
Dim Soma As Double
Soma = CCur(TextBox46.text) + CCur(TextBox47.text) + CCur(TextBox48.text) + CCur(TextBox49.text) + CCur(TextBox50.text) + CCur(TextBox51.text) + CCur(TextBox52.text) + CCur(TextBox53.text)
TextBox56.Value = Soma
O problema está no val:
>
Citar
The VAL function will stop reading the string once it encounters the first non-numeric character. This does not include spaces.
Quando encontra a virgula, para por ali. Tente usar CDbl no lugar de val