Título: [Solucionado]Duda con decimales
Publicado por: Trane! en 13 Julio 2011, 01:11 am
Bueno me gustaria que sume decimales pero hay un problema si hago por ejemplo 5,1+5,3 = 104 y eso queria solucionar aqui va el code: Option Explicit Dim StrOper As String Dim IntVal As Double Dim IntVal2 As Double
Private Sub cmdCien_Click() If txtResultado.Text <> "" Then StrOper = "%" IntVal = txtResultado.Text txtResultado.Text = "" Else txtResultado.Text = "" End If End Sub
Private Sub cmdDel_Click(Index As Integer) txtResultado.Text = "" End Sub
Private Sub cmdDiv_Click(Index As Integer) If txtResultado.Text <> "" Then StrOper = "/" IntVal = txtResultado.Text txtResultado.Text = "" Else txtResultado.Text = "" End If End Sub
Private Sub cmdDot_Click() txtResultado.Text = txtResultado.Text & "." End Sub
Private Sub cmdIgual_Click(Index As Integer) IntVal2 = txtResultado.Text If StrOper = "+" Then txtResultado.Text = Val(IntVal) + Val(IntVal2) End If If StrOper = "-" Then txtResultado.Text = Val(IntVal) - Val(IntVal2) End If If StrOper = "*" Then txtResultado.Text = Val(IntVal) * Val(IntVal2) End If If StrOper = "/" Then txtResultado.Text = Val(IntVal) / Val(IntVal2) End If If StrOper = "%" Then txtResultado.Text = Val(IntVal) / 100 * Val(IntVal2) End If End Sub
Private Sub cmdMas_Click(Index As Integer) If txtResultado.Text <> "" Then StrOper = "+" IntVal = txtResultado.Text txtResultado.Text = "" Else txtResultado.Text = "" End If End Sub
Private Sub cmdMenos_Click(Index As Integer) If txtResultado.Text <> "" Then StrOper = "-" IntVal = txtResultado.Text txtResultado.Text = "" Else txtResultado.Text = "" End If End Sub
Private Sub cmdMul_Click(Index As Integer) If txtResultado.Text <> "" Then StrOper = "*" IntVal = txtResultado.Text txtResultado.Text = "" Else txtResultado.Text = "" End If End Sub
Private Sub cmdNum_Click(Index As Integer) txtResultado.Text = txtResultado.Text & Index End Sub
Private Sub cmdSqrt_Click() If txtResultado.Text <> "" Then StrOper = "Sqrt" IntVal = txtResultado.Text txtResultado.Text = "" If IntVal < 0 Then MsgBox "Numero negativo!" Else txtResultado.Text = Sqr(Val(IntVal)) End If End If End Sub
Private Sub Salir_Click() Beep End End Sub
Título: Re: Duda con decimales
Publicado por: seba123neo en 13 Julio 2011, 01:44 am
es porque usas Val() y la coma, entonces esto hace que te elimina los caracteres que no son numeros, pero Val() si funciona con el punto.
saludos.
Título: Re: Duda con decimales
Publicado por: Trane! en 13 Julio 2011, 01:54 am
Private Sub cmdDot_Click() txtResultado.Text = txtResultado.Text & "." End Sub Pero eso es un punto, no deberia funcionar ? o tengo que eliminar los val ?
Título: Re: Duda con decimales
Publicado por: raul338 en 13 Julio 2011, 02:03 am
Los val eliminan la coma, en su lugar usa CDbl() que trabaja con Doubles
Título: Re: Duda con decimales
Publicado por: Trane! en 13 Julio 2011, 02:23 am
Muchisimas gracias, ya esta resuelto!
|