Calculos com textbo...
 
Notifications
Clear all

Calculos com textbox.

4 Posts
1 Usuários
0 Reactions
979 Visualizações
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Senhores, Boa tarde!

Alguém pode me ajudar no código abaixo? não sei onde está meu erro.

está gerando um erro em tempo de execução 6.

Private Sub fatorCaO_AfterUpdate()
Dim valor1 As Double
Dim valor2 As Double
Dim valor3 As Double
valor1 = 0
valor2 = 0
valor3 = 0

If Me.mlCaO = Empty Then
Else
valor1 = Me.mlCaO.Value
End If
If Me.fatorCaO = Empty Then
Else
valor2 = Me.fatorCaO.Value
End If
If Me.massaamostra = Empty Then
Else
valor3 = Me.massaamostra.Value
End If
Me.resultadoCaO.Value = Format((CDbl(valor1) * CDbl(valor2)) / CDbl(valor3), "##,##0.0")

End Sub
Private Sub mlCaO_AfterUpdate()
Dim valor1 As Double
Dim valor2 As Double
Dim valor3 As Double
valor1 = 0
valor2 = 0
valor3 = 0

If Me.mlCaO = Empty Then
Else
valor1 = Me.mlCaO.Value
End If
If Me.fatorCaO = Empty Then
Else
valor2 = Me.fatorCaO.Value
End If
If Me.massaamostra = Empty Then
Else
valor3 = Me.massaamostra.Value
End If
Me.resultadoCaO.Value = Format(CDbl(valor1) * CDbl(valor2) / CDbl(valor3), "##,##0.0")

End Sub

Private Sub massaamostra_AfterUpdate()
Dim valor1 As Double
Dim valor2 As Double
Dim valor3 As Double
valor1 = 0
valor2 = 0
valor3 = 0

If Me.mlCaO = Empty Then
Else
valor1 = Me.mlCaO.Value
End If
If Me.fatorCaO = Empty Then
Else
valor2 = Me.fatorCaO.Value
End If
If Me.massaamostra = Empty Then
Else
valor3 = Me.massaamostra.Value
End If
Me.resultadoCaO.Value = Format(CDbl(valor1) * CDbl(valor2) / CDbl(valor3), "##,##0.0")

End Sub
 
Postado : 21/10/2015 10:36 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Doni, voce mostrou a rotina referentes a 3 textbox e todos no evento AfterUpdate e o resultado de qualquer um deles é mostrado no mesmo textbox "Me.resultadoCaO".

Só pelas rotinas não da para avaliar, o ideal seria indicar em qual delas acontece o erro e em qual linha, apesar que pelo que já deste tipo de erro pode ser referente as definições de variáveis como Zero ou em branco.
Se não conseguir identificar a linha de erro, anexe um modelo reduzido para uma melhor analise.

[]s

 
Postado : 21/10/2015 11:35 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Mauro, bom dia!

O erro sempre acontece nessa linha do código:

Private Sub fatorCaO_AfterUpdate()
Dim valor1 As Double
Dim valor2 As Double
Dim valor3 As Double
valor1 = 0
valor2 = 0
valor3 = 0

If Me.mlCaO = Empty Then
Else
valor1 = Me.mlCaO.Value
End If
If Me.fatorCaO = Empty Then
Else
valor2 = Me.fatorCaO.Value
End If
If Me.massaamostra = Empty Then
Else
valor3 = Me.massaamostra.Value
End If

*****Me.resultadoCaO.Value = Format((CDbl(valor1) * CDbl(valor2)) / CDbl(valor3), "##,##0.0")*****
End Sub
Private Sub mlCaO_AfterUpdate()
Dim valor1 As Double
Dim valor2 As Double
Dim valor3 As Double
valor1 = 0
valor2 = 0
valor3 = 0

If Me.mlCaO = Empty Then
Else
valor1 = Me.mlCaO.Value
End If
If Me.fatorCaO = Empty Then
Else
valor2 = Me.fatorCaO.Value
End If
If Me.massaamostra = Empty Then
Else
valor3 = Me.massaamostra.Value
End If
Me.resultadoCaO.Value = Format(CDbl(valor1) * CDbl(valor2) / CDbl(valor3), "##,##0.0")

End Sub

Private Sub massaamostra_AfterUpdate()
Dim valor1 As Double
Dim valor2 As Double
Dim valor3 As Double
valor1 = 0
valor2 = 0
valor3 = 0

If Me.mlCaO = Empty Then
Else
valor1 = Me.mlCaO.Value
End If
If Me.fatorCaO = Empty Then
Else
valor2 = Me.fatorCaO.Value
End If
If Me.massaamostra = Empty Then
Else
valor3 = Me.massaamostra.Value
End If
Me.resultadoCaO.Value = Format(CDbl(valor1) * CDbl(valor2) / CDbl(valor3), "##,##0.0")

End Sub

Na verdade eu gostaria que toda vez que o formulário fosse carregado a textbox fatorCaO já viesse com o valor 3,5, e quando eu digitar nas outras textbox o resultado do calculo seja apresentado na textbox resultadoCaO.

Doni

 
Postado : 22/10/2015 6:19 am
(@fernandofernandes)
Posts: 43750
Illustrious Member
Topic starter
 

Obrigado, já consegui resolver com o seguinte código:

Private Sub fatorCaO_Change()
    If fatorCaO.Value = "" Then Exit Sub
    If mlCaO.Value = "" Then Exit Sub
    If massaamostra.Value = "" Then Exit Sub
    resultadoCaO.Value = Format(CDbl(fatorCaO.Value) * CDbl(mlCaO.Value) / CDbl(massaamostra.Value), "0.0")
End Sub
 
Private Sub mlCaO_Change()
    If fatorCaO.Value = "" Then Exit Sub
    If mlCaO.Value = "" Then Exit Sub
    If massaamostra.Value = "" Then Exit Sub
    resultadoCaO.Value = Format(CDbl(fatorCaO.Value) * CDbl(mlCaO.Value) / CDbl(massaamostra.Value), "0.0")
    End Sub
Private Sub massaamostra_Change()
    If fatorCaO.Value = "" Then Exit Sub
    If mlCaO.Value = "" Then Exit Sub
    If massaamostra.Value = "" Then Exit Sub
    resultadoCaO.Value = Format(CDbl(fatorCaO.Value) * CDbl(mlCaO.Value) / CDbl(massaamostra.Value), "0.0")
End Sub

Doni

 
Postado : 22/10/2015 9:31 am