CALCULADORA PROGRAMADA EN VISUAL BASIC
Es un programa el cual se puede crear cualquier persona. siempre y cuando tenga muy en cuanta el suncionamiento o manejo adecuado del visual basic. sirve para realizar operaciones matematicas; generalmente consta de una caja de texto, como pueden ver consta de diversos botones ..... unos de salir,limpiar ; otros con los numeros del 0 al 9 y los operadores matematicos.tambien a cada uno de los botones , y a la caja de texto debiamos cambiarle las propiedades.Ahora veremos como se programa o como se le da funcionamiento a la calculadora, a través del codigo general de este programa. El cual les presentaré a continuación:
Option Explic
Dim num1 As Double
Dim num2 As Douitble
Dim operador As String
Private Sub Command1_Click(Index As Integer)
Text = Text1.Text & Index.
BOTON +
private Sub Command2_Click()
num1 = Text1.Textoperador = "+"Text1.Text = ""
End SubBOTON -
Private Sub Command3_Click()
num1 = Text1.Textoperador = "-"
Text1.Text = ""
End sub
BOTON *
Private Sub Command4_Click()
num1 = Text1.Textoperador = "*"Text1.Text = ""
End Sub
BOTON /
Private Sub Command5_Click()
num1 = Text1.Textoperador = "/"Text1.Text = ""
End sub
BOTON modulo
Private Sub Command6_Click()
num1 = Text1.Textoperador = "mod"Text1.Text = ""
End Sub
BOTON =
Private Sub Command7_Click()
Dim res As Double
num2 = Val(Text1.Text)
If operador = "+" Then
Text1.Text = Val(num1) + Val(num2)
Exit Sub
End If
If operador = "-" Then
Text1.Text = Val(num1) - Val(num2)
Exit SubEnd If
If operador = "*" Then
Text1.Text = Val(num1) * Val(num2)
Exit Sub
End If
If num2 <> 0 And operador = "/" Then
Text1.Text = Val(num1) / Val(num2)
Else
res = MsgBox("no se puede dividir por 0 ")
End If
If operador = "mod" Then
Text1.Text = Val(num1) Mod (num2)
End If
End Sub
BOTON BORRAR
Private Sub Command8_Click()
Text1.Text = ""
End Sub
BOTON SALIR
Private Sub Command9_Click()
End
End Sub
DOS NUMEROS Y DETERMINAR CUAL ES EL MAYOR
Es un programa en el cual se ingresan dos numeros en cada una de las cajas de texto, lo cual se ve como resultado, que aperecerá en la caja de texto aparte de las anteriores el número mayor. CODIGO GENERAL:
Dim numero1 As Integer
Dim numero2 As Integer
'boton resultado'
Private Sub Command1_Click()
numero1 = Val(Text1.Text)
numero2 = Val(Text2.Text)
numero3 = Val(Text3.Text)
If numero1 > numero2 Then
Text3.Text = numero1 'numero1 es mayor'
ElseText3.Text = numero2 '
numero2 es mayor'
End If
End Sub
'boton salir'Private Sub Command2_Click()
End
End Sub
'boton borrar'
Private Sub Command3_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub
Dim numero2 As Integer
'boton resultado'
Private Sub Command1_Click()
numero1 = Val(Text1.Text)
numero2 = Val(Text2.Text)
numero3 = Val(Text3.Text)
If numero1 > numero2 Then
Text3.Text = numero1 'numero1 es mayor'
ElseText3.Text = numero2 '
numero2 es mayor'
End If
End Sub
'boton salir'Private Sub Command2_Click()
End
End Sub
'boton borrar'
Private Sub Command3_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub
DOS IMAGENES EN MOVIMIENTO
En el siguiente programa veremos dos imagenes en movimiento, con diferente movimiento.
estas imagenes despues de ser arregladas en pain se insertaron a traves de dos picture box, dos barras de desplzaminto, ver grafica.
CODIGO GENERAL
Dim cy, cx As Integer
Boton finalizar
Private Sub Command1_Click()
End
End Sub
Private Sub Form_Load()
cx = 100
cy = 100
End Sub
Barra vertical de velocidad
Private Sub tiempo1_Change()
tmpcarros.Interval = tiempo1.Value
End Sub
Barra horizontal de velocidad
Private Sub tiempo2_Change()
tmpcirculos.Interval = tiempo2.Value
End Sub
Timer1
Private Sub tmpcarros_Timer()
figcarros.Move figcarros.Left + 100
If figcarros.Left > ScaleWidth Then
figcarros.Move 0
End If
End Sub
Timer2
Private Sub tmpcirculos_Timer()
figcirculos.Move figcirculos.Left + cx, figcirculos.Top + cy
If figcirculos.Left < cx =" 100"> ScaleWidth + ScaleLeft Then
cx = -100
End If
If figcirculos.Top < cy =" 100"> ScaleHeight + ScaleTop Then
cy = -100
End If
End Sub
Boton finalizar
Private Sub Command1_Click()
End
End Sub
Private Sub Form_Load()
cx = 100
cy = 100
End Sub
Barra vertical de velocidad
Private Sub tiempo1_Change()
tmpcarros.Interval = tiempo1.Value
End Sub
Barra horizontal de velocidad
Private Sub tiempo2_Change()
tmpcirculos.Interval = tiempo2.Value
End Sub
Timer1
Private Sub tmpcarros_Timer()
figcarros.Move figcarros.Left + 100
If figcarros.Left > ScaleWidth Then
figcarros.Move 0
End If
End Sub
Timer2
Private Sub tmpcirculos_Timer()
figcirculos.Move figcirculos.Left + cx, figcirculos.Top + cy
If figcirculos.Left < cx =" 100"> ScaleWidth + ScaleLeft Then
cx = -100
End If
If figcirculos.Top < cy =" 100"> ScaleHeight + ScaleTop Then
cy = -100
End If
End Sub
EL JUEGO
Es te juego es de mucha atención y muy divertido, en cual se pueden distrare tantolos niños como los adultos. Ahora veamos como el diseño del juego en la imagel anterior.
CODIGO GENERAL:
Botón sapote
Private Sub Command1_Click()
MsgBox ("sigue jugando")
Form2.Show
form1.Hide
End Sub
Botón limón
Private Sub Command2_Click()
MsgBox ("sige intentando ")
End Sub
Botón fresa
Private Sub Command3_Click()
MsgBox ("no no es ")
End Sub
Botón manzana
Private Sub Command4_Click()
MsgBox ("no esa no es ")
End Sub
Private Sub Command1_Click()
MsgBox ("sigue jugando")
Form2.Show
form1.Hide
End Sub
Botón limón
Private Sub Command2_Click()
MsgBox ("sige intentando ")
End Sub
Botón fresa
Private Sub Command3_Click()
MsgBox ("no no es ")
End Sub
Botón manzana
Private Sub Command4_Click()
MsgBox ("no esa no es ")
End Sub

No hay comentarios:
Publicar un comentario