28Jan2008
Archivado en: Programaci贸n, Visual Basic
Autor: Angel L贸pez
Hola amigos:
Ahora continuare con los programas hechos en Visual Basic .Net 2005 los cuales hoy en d铆a si son de mucha utilidad ya que este entorno de desarrollo se esta utilizando mucho y por lo tanto estos programas te pueden sacar de alguna duda as铆 que los publicare
Este programa es una calculadora muy similar a la que viene con el Windows XP o el Windows Vista. Contiene los mismos botones y funciona muy parecido.
Al correrlo, el programa luce as铆:

y el c贸digo es este (al final puedes descargar los archivos):
VB.NET:
-
Public Class Form1
-
Function buscar(ByVal txtval As String, ByVal car As Char) As Boolean
-
Dim b As Integer
-
For b = 1 To txtval.Length
-
If Convert.ToChar(Mid(txtval, b, 1)) = car Then
-
Return False
-
End If
-
Next
-
Return True
-
End Function
-
Dim val1, val2 As Double
-
Dim banR, ban, ban_br As Integer
-
Dim oper As String
-
Private Sub txt0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt0.Click
-
If banR = 0 Then
-
r.Text &= "0"
-
Else
-
r.Text = "0"
-
End If
-
End Sub
-
-
Private Sub txt1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt1.Click
-
If banR = 0 Then
-
r.Text &= "1"
-
Else
-
r.Text = "1"
-
End If
-
End Sub
-
-
Private Sub txt2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt2.Click
-
If banR = 0 Then
-
r.Text &= "2"
-
Else
-
r.Text = "2"
-
End If
-
End Sub
-
-
Private Sub txt3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt3.Click
-
If banR = 0 Then
-
r.Text &= "3"
-
Else
-
r.Text = "3"
-
End If
-
End Sub
-
-
Private Sub txt4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt4.Click
-
If banR = 0 Then
-
r.Text &= "4"
-
Else
-
r.Text = "4"
-
End If
-
End Sub
-
-
Private Sub txt5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt5.Click
-
If banR = 0 Then
-
r.Text &= "5"
-
Else
-
r.Text = "5"
-
End If
-
End Sub
-
-
Private Sub txt6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt6.Click
-
If banR = 0 Then
-
r.Text &= "6"
-
Else
-
r.Text = "6"
-
End If
-
End Sub
-
-
Private Sub txt7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt7.Click
-
If banR = 0 Then
-
r.Text &= "7"
-
Else
-
r.Text = "7"
-
End If
-
End Sub
-
-
Private Sub txt8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt8.Click
-
If banR = 0 Then
-
r.Text &= "8"
-
Else
-
r.Text = "8"
-
End If
-
End Sub
-
-
Private Sub txt9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt9.Click
-
If banR = 0 Then
-
r.Text &= "9"
-
Else
-
r.Text = "9"
-
End If
-
End Sub
-
-
Private Sub txtce_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtce.Click
-
oper = ""
-
val2 = 0
-
r.Text = ""
-
banR = 0
-
ban_br = 0
-
r.Focus()
-
End Sub
-
-
Private Sub txtc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtc.Click
-
banR = 0
-
ban = 0
-
ban_br = 0
-
oper = ""
-
val1 = 0
-
val2 = 0
-
r.Text = ""
-
r.Focus()
-
End Sub
-
-
Private Sub txtigual_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtigual.Click
-
val2 = Val(r.Text)
-
Select Case oper
-
Case "+"
-
val1 += val2
-
Case "-"
-
val1 -= val2
-
Case "*"
-
val1 *= val2
-
Case "/"
-
val1 /= val2
-
End Select
-
r.Text = val1
-
banR = 1
-
ban = 1
-
ban_br = 1
-
End Sub
-
-
Private Sub txtadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtadd.Click
-
If ban = 0 Then
-
val1 = Val(r.Text)
-
oper = "+"
-
r.Text = ""
-
r.Focus()
-
ban = 1
-
Else
-
val2 = Val(r.Text)
-
If ban_br = 1 Then 'si ya presiono el boton de =
-
ban_br = 0
-
Else
-
Select Case oper
-
Case "+"
-
val1 += val2
-
Case "-"
-
Case "*"
-
Case "/"
-
End Select
-
End If
-
oper = "+"
-
r.Text = val1
-
banR = 1
-
End If
-
End Sub
-
-
Private Sub txtsub_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtsub.Click
-
If ban = 0 Then
-
val1 = Val(r.Text)
-
oper = "-"
-
r.Text = ""
-
r.Focus()
-
ban = 1
-
Else
-
val2 = Val(r.Text)
-
If ban_br = 1 Then 'si ya presiono el boton de =
-
ban_br = 0
-
Else
-
Select Case oper
-
Case "+"
-
val1 += val2
-
Case "-"
-
Case "*"
-
Case "/"
-
End Select
-
End If
-
oper = "-"
-
r.Text = val1
-
banR = 1
-
End If
-
End Sub
-
-
Private Sub txtmul_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtmul.Click
-
If ban = 0 Then
-
val1 = Val(r.Text)
-
oper = "*"
-
r.Text = ""
-
r.Focus()
-
ban = 1
-
Else
-
val2 = Val(r.Text)
-
If ban_br = 1 Then 'si ya presiono el boton de =
-
ban_br = 0
-
Else
-
Select Case oper
-
Case "+"
-
val1 += val2
-
Case "-"
-
Case "*"
-
Case "/"
-
End Select
-
End If
-
oper = "*"
-
r.Text = val1
-
banR = 1
-
End If
-
End Sub
-
-
Private Sub txtdiv_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtdiv.Click
-
If ban = 0 Then
-
val1 = Val(r.Text)
-
oper = "/"
-
r.Text = ""
-
r.Focus()
-
ban = 1
-
Else
-
val2 = Val(r.Text)
-
If ban_br = 1 Then 'si ya presiono el boton de =
-
ban_br = 0
-
Else
-
Select Case oper
-
Case "+"
-
val1 += val2
-
Case "-"
-
Case "*"
-
Case "/"
-
End Select
-
End If
-
oper = "/"
-
r.Text = val1
-
banR = 1
-
End If
-
End Sub
-
-
Private Sub txtpunto_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtpunto.Click
-
If buscar(r.Text, ".") = True Then
-
r.Text &= "."
-
End If
-
End Sub
-
End Class
Descarga
humebert
February 5th, 2008 at 3:04 pm
cuando le doy correr me esta dando errores en todos los que son:
Ejemplo
txt8.Click(谩usula WithEvents requiere una variable definida en el tipo o que contengan una de sus base de los tipos)
r.Tex [me dice que la r no esta declarada)
Angel L贸pez
February 5th, 2008 at 8:03 pm
Seguro que lo estas corriendo en Visual Basic .Net 2005??? lo acabo de ejecutar y no me marc贸 ningun error :S
al cuadro de texto del resultado le tienes que poner en la propiedad “name” = r
copiaste el codigo a un nuevo formulario tuyo? o abriste toda la carpeta que puse como descarga?? abre toda la carpeta y corre el proyecto entero, presiona doble clic en el archivo “calculadora.vbproj”, entonces despues de eso ahora si correlo y veras que no te marcar谩 ningun error… saludos
humberto
February 6th, 2008 at 7:45 am
Gracias ya descubri el problema!!!
antonio
March 6th, 2008 at 3:45 pm
ps no le entendi pero esta chido路-路
victorino perez hernandez
May 29th, 2008 at 9:33 am
programas elaborados en visual Basic 6
Ismael Mendoza Garc铆a
June 5th, 2008 at 12:10 pm
Crees que si la creo en Visual Studio.NET 2003 me lo correra = que como en el 2005? por que estoy haciendo una en la escuela y solo estamos viendo la version 2003.
Angel L贸pez
June 6th, 2008 at 6:10 am
Hola @Ismael Mendoza Garc铆a: si creo que si corre… si acaso ha de cambiar algun detallito pero de ahi en mas, me imagino que es igual
saludos