El otro dia estaba leyando la revista HACKxCRACK y decidi hacer una calculadora.
Todo iba bien hasta que al escribir If xxxxxxxxxxxxx Then y probarlo me salia que el valor " Then" no funcionaba (me aparecia subrayado en rojo)
Alguien podria decirme como solucionarlo.
Gracias
Escribe la linea completa y te digo, aunke la estructura es simple
if 10 = 10 then
msgbox "evidente.."
end if
De todas formas leete algun tuto de VB d verdad, no te restrinjas a los de hack x crack q no aprendes nada xD
Este es el código del boton de la suma
IfStrOper = "+" Then
TxtOper = LongValor + TxtOper.Text
End if
La caja de texto se llama TxtOper y el valor que se ha dado antes es LongValor
Gracias. Espero su respuesta
If StrOper = "+" Then
TxtOper = LongValor + TxtOper.Text
End if
Da igual, ni separando el If (que fue un problema de copia) funciona.
CitarDa igual, ni separando el If (que fue un problema de copia) funciona.
Te lo sigue marcando en rojo o no te da el resultado esperado :huh:
Saludos
Pues pega el codigo completo, q sera por algun error en el tipo de variable o algo asi
Ahi va el codigo:
Private Sub boton_igual_Click()
IfStrOper="+" Then
TxtOper = LngValor + TxtOper.Text
End If
ifStrOper="-" Then
TxtOper = LongValor - TxtOper.Text
End If
IfSrOper="*" Then
TxtOper = LongValor - TxtOper.Text
End If
I StrOper="/" Then
TxtOper = LongValor / TxtOper.Text
End If
End Sub
Private Sub boton_menos_Click()
StrOper = "-"
LngValor = TxtOper.Text
TxtOper.Text = ""
End Sub
Private Sub boton_por_Click()
StrOper = "*"
LngValor = TxtOper.Text
TxtOper.Text = ""
End Sub
Private Sub boton0_Click()
TxtOper.Text = TxtOper.Text & "0"
End Sub
Private Sub boton1_Click()
TxtOper.Text = TxtOper.Text & "1"
End Sub
Private Sub boton2_Click()
TxtOper.Text = TxtOper.Text & "2"
End Sub
Private Sub boton3_Click()
TxtOper.Text = TxtOper.Text & "3"
End Sub
Private Sub boton4_Click()
TxtOper.Text = TxtOper.Text & "4"
End Sub
Private Sub boton5_Click()
TxtOper.Text = TxtOper.Text & "5"
End Sub
Private Sub boton6_Click()
TxtOper.Text = TxtOper.Text & "6"
End Sub
Private Sub boton7_Click()
TxtOper.Text = TxtOper.Text & "7"
End Sub
Private Sub boton8_Click()
TxtOper.Text = TxtOper.Text & "8"
End Sub
Private Sub boton9_Click()
TxtOper.Text = TxtOper.Text & "9"
End Sub
Private Sub Form_Load()
Var1 = "Luiggy"
MsgBox Var1
End Sub
El problema esta en las siguientes linas:
Private Sub boton_igual_Click()
IfStrOper="+" Then
TxtOper = LngValor + TxtOper.Text
End If
ifStrOper="-" Then
TxtOper = LongValor - TxtOper.Text
End If
IfSrOper="*" Then
TxtOper = LongValor - TxtOper.Text
End If
I StrOper="/" Then
TxtOper = LongValor / TxtOper.Text
End If
End Sub
Por cierto he ido probandolo segun lo he ido haciendo y me ha funcionado hasta llegar ahi (boton igual)
Gracias. espero sus rspuestas
Declara las variables por Dios!!! y prueva asi:
Dim strOper as string
Private Sub boton_igual_Click()
If StrOper = "+" Then
TxtOper = LngValor + TxtOper.Text
End If
if StrOper = "-" Then
TxtOper = LongValor - TxtOper.Text
End If
If SrOper = "*" Then
TxtOper = LongValor - TxtOper.Text
End If
If StrOper = "/" Then
TxtOper = LongValor / TxtOper.Text
End If
End Sub
Hacer un select case no estaria de mas..
tambien podrias dejar separaciones, no? no va todo junto, osea vos no escribis asi:
ifsData=2then
, o si?
asi es la manera correcta..
if sData = 2 then
y como dice E0N...
Select case StrOper
case "+"
TxtOper = LngValor + TxtOper.Text
etc...
end select
saludos!
PD: leete un manualcito que no estaria de mas :D