Está en la página 1de 22

Ejemplos de Visual Studio 2008

EJERCICIO # 1

Public Class Form1


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butto
n1.Click
'Programa: Area de tringulo
'Fecha:
'Declaracin de variables
Dim A, B, H As Single
B = TextBox1.Text
H = TextBox2.Text
'Calculando rea de tringulo
A = (B * H) / 2
'Visualizar resultado
TextBox3.Text = A
End Sub
_________________________________________________________________________________
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.
Click
TextBox1.Text = " "
TextBox2.Text = " "
TextBox3.Text = " "
End Sub
_________________________________________________________________________________
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button
3.Click
End

End Sub
End Class
__________________________________________________________________________________
EJERCICIO # 2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.


Click
'Programa: Energa potencial
'Fecha:
'Declaracin de variables
Dim ep, m, x As Single
m = TextBox1.Text
x = TextBox2.Text
'Calcular energa potencial
ep = m * 9.8 * x
'Visualizar resultado
TextBox3.Text = ep
End Sub
_________________________________________________________________________________
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.
Click
TextBox1.Text = " "
TextBox2.Text = " "
TextBox3.Text = " "
End Sub
_________________________________________________________________________________
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.
Click
End
End Sub

_________________________________________________________________________________
EJERCICIO # 3

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.


Click
'Programa:Trabajo
'Fecha:
'Declaracin de variables
Dim w, m, vf, vi As Single
m = TextBox1.Text
vf = TextBox2.Text
vi = TextBox3.Text
'Calcular el trabajo
w = (m * (vf ^ 2) / 2) - (m * (vi ^ 2) / 2)
'visualizar resultado en cada de mensaje
MsgBox("El trabajo calculado es: " & w)
End Sub
_________________________________________________________________________________
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butto
n2.Click
TextBox1.Text = " "
TextBox2.Text = " "
TextBox3.Text = " "
End Sub
_________________________________________________________________________________
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butto
n3.Click
End
End Sub

_________________________________________________________________________________
EJERCICIO # 4

Public Class Form1


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.
Click
Dim a, b, c As Single
a = TextBox1.Text
b = TextBox2.Text
c=a+b
TextBox3.Text = c
End Sub
_________________________________________________________________________________
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butto
n2.Click
Dim a, b, c As Single
a = TextBox1.Text
b = TextBox2.Text
c=a-b
TextBox3.Text = c
End Sub
_________________________________________________________________________________
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.
Click
Dim a, b, c As Single
a = TextBox1.Text
b = TextBox2.Text
c=a*b
TextBox3.Text = c
End Sub
_________________________________________________________________________________
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.
Click
Dim a, b, c As Single

a = TextBox1.Text
b = TextBox2.Text
c=a/b
TextBox3.Text = c
End Sub
_________________________________________________________________________________
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.
Click
Dim a, b, c As Single
a = TextBox1.Text
b = TextBox2.Text
c=a^b
TextBox3.Text = c
End Sub
_________________________________________________________________________________
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butto
n6.Click
TextBox1.Text = " "
TextBox2.Text = " "
TextBox3.Text = " "
End Sub
_________________________________________________________________________________
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butto
n7.Click
End
End Sub
End Class
_________________________________________________________________________________
EJERCICIO # 5

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.


Click
'Programa: Area de cilindro
'Fecha:

'Declaracin de variables
Dim a, r, h As Single
r = TextBox1.Text
h = TextBox2.Text
'Calculando rea de cilindro
a = 2 * 3.141592 * (r + h + r ^ 2)
'Visualizando resultado
TextBox3.Text = a
End Sub
_________________________________________________________________________________
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butto
n2.Click
TextBox1.Text = " "
TextBox2.Text = " "
TextBox3.Text = " "
End Sub
_________________________________________________________________________________
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butto
n3.Click
End
End Sub
_________________________________________________________________________________
EJERCICIO # 6

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.


Click
'Programa: Conversin a radianes
'Fecha:
'Declaracin de variables
Dim rad, dato As Single
dato = TextBox1.Text
'Calculando radianes
rad = (2 * 3.141592 * dato) / 360

'Visualizar resultado en radianes


TextBox2.Text = rad
Label3.Text = "Radianes"
End Sub
_________________________________________________________________________________
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.
Click
'Declaracin de variables
Dim grad, dato As Single
dato = TextBox1.Text
'Calculando grados
grad = (dato * 180)
'Visualizar resultado en grados
TextBox2.Text = grad
Label3.Text = "Grados"
End Sub
_________________________________________________________________________________
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.
Click
TextBox1.Text = " "
TextBox2.Text = " "
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butto
n4.Click
End
End Sub
_________________________________________________________________________________
USO DE CICLO CONDICIONAL IF-THEN-ELSE
IF-THEN-ELSE: Es un ciclo condicional que permite tomar decisiones dentro de un programa, se utiliza para
evaluar condiciones y que el programa pueda operar sobre dos alternativas.
EJERCICIO # 7

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.


Click
'Programa: rea y permetro de parbola
'Fecha
'Declaracin de variables
Dim are, p, a, b As Single
a = TextBox1.Text
b = TextBox2.Text
If RadioButton1.Checked = True Then
are = 3.141592 * a * b
MsgBox("El rea de la parbola es : " & are)
Else
If RadioButton2.Checked = True Then
p = 2 * 3.141592 * (1 / 2 * (a ^ 2 + b ^ 2)) ^ 0.5
MsgBox("El permetro de la parbola es : " & p)
End If
End If
End Sub
_________________________________________________________________________________
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butto
n2.Click
TextBox1.Text = " "
TextBox2.Text = " "
End Sub
_________________________________________________________________________________
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butto
n3.Click
End
End Sub
_________________________________________________________________________________
EJERCICIO # 8

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.


Click
'Programa: Discriminante
'Fecha: 7 /08/12
'Declaracin de variables
Dim d, b, a, c, r As Single
b = TextBox1.Text
a = TextBox2.Text
c = TextBox3.Text
'Calculando cantidad subradical
r = (b ^ 2 - 4 * a * c)
'Evaluando si se puede calcular raz cuadrada
If r > 0 Then
d = r ^ 0.5
Else
If r < 0 Then
MsgBox("No se puede calcular la raz cuadrada")
End If
End If
'Visualizar resultado
TextBox4.Text = d
End Sub
_________________________________________________________________________________
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butto
n2.Click
TextBox1.Text = " "
TextBox2.Text = " "
TextBox3.Text = " "
TextBox4.Text = " "
End Sub

_________________________________________________________________________________
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butto
n3.Click
End
End Sub
_________________________________________________________________________________
EJERCICIO # 9

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.


Click
'Programa: Calculadora_If-Then-Else
'Fecha:
'Declaracin de variables
Dim r, a, b As Single
a = TextBox1.Text
b = TextBox2.Text
'Ciclo condicional para tomar decisiones y poder elegir operacin
If RadioButton1.Checked = True Then
r=a+b
Else
If RadioButton2.Checked = True Then
r=a-b
Else
If RadioButton3.Checked = True Then
r=a*b
Else
If RadioButton4.Checked = True Then
r=a/b
Else
If RadioButton5.Checked = True Then
r=a^b
End If
End If

End If
End If
End If
MsgBox("El resultado es : " & r)
End Sub
_________________________________________________________________________________
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butto
n2.Click
TextBox1.Text = " "
TextBox2.Text = " "
End Sub
_________________________________________________________________________________
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butto
n3.Click
End
End Sub
_________________________________________________________________________________
EJERCICIO # 10

Public Class Form1


Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.Ev
entArgs)Handles ComboBox1.SelectedIndexChanged
'Programa: Conceptos
'Fecha:
'Uso de ciclo condicional IF-THEN-ELSE
If ComboBox1.Text = "Aceleracin" Then
Label1.Text = "La aceleracin es el cambio de velocidad en el tiempo para desplazar un cuerpo de
un punto A a un punto B."
Label3.Text = "a = (Vf -Vo) / t"

Label2.Text = "Ingrese velocidad final (Vf):"


Label4.Text = "Ingrese velocidad inicial (Vo):"
Label5.Text = "Ingrese el tiempo ( t ):"
Label6.Text = "La aceleracin es ( a ):"
Else
If ComboBox1.Text = "Velocidad inicial (Vo)" Then
Label1.Text = "Es la Velocidad que tiene un cuerpo al INICIAR su movimiento en un perodo de
tiempo."
Label3.Text = "Vo = Vf - a t"
Label2.Text = "Ingrese velocidad final (Vf):"
Label4.Text = "Ingrese aceleracin ( a ):"
Label5.Text = "Ingrese el tiempo ( t ):"
Label6.Text = "La velocidad inicial es (Vo):"
Else
If ComboBox1.Text = "Velocidad final (Vf)" Then
Label1.Text = "Es la Velocidad que tiene un cuerpo al FINALIZAR su movimiento en un perodo
de tiempo."
Label3.Text = "Vf = Vo + a t"
Label2.Text = "Ingrese velocidad inicial (Vo):"
Label4.Text = "Ingrese aceleracin ( a ):"
Label5.Text = "Ingrese el tiempo ( t ):"
Label6.Text = "La velocidad final es (Vf):"
End If
End If
End If
End Sub
_________________________________________________________________________________
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butto
n1.Click
If ComboBox1.Text = "Aceleracin" Then
Dim a, vf, vo, t As Single
vf = TextBox1.Text
vo = TextBox2.Text
t = TextBox3.Text
a = (vf - Vo) / t
TextBox4.Text = a
Else
If ComboBox1.Text = "Velocidad inicial (Vo)" Then
Dim vo, vf, a, t As Single
vf = TextBox1.Text
a = TextBox2.Text
t = TextBox3.Text
vo = vf - (a * t)
TextBox4.Text = vo
Else
If ComboBox1.Text = "Velocidad final (Vf)" Then
Dim vf, vo, a, t As Single
vo = TextBox1.Text
a = TextBox2.Text
t = TextBox3.Text
vf = vo + (a * t)
TextBox4.Text = vf
End If

End If
End If
End Sub
_________________________________________________________________________________
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butto
n2.Click
TextBox1.Text = " "
TextBox2.Text = " "
TextBox3.Text = " "
TextBox4.Text = " "
End Sub
_________________________________________________________________________________
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butto
n3.Click
End
End Sub
End Class
_________________________________________________________________________________

EJERCICIO # 11

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.


Click
'Programa: Funciones trigonomtricas
'Fecha:
'Declaracin de variables
Dim r, ang As Single
ang = TextBox1.Text
'Evaluando condicin, para seleccionar funcin
If RadioButton1.Checked = True Then
r = Math.Cos(ang)
Else

If RadioButton2.Checked = True Then


r = Math.Sin(ang)
Else
If RadioButton3.Checked = True Then
r = Math.Tan(ang)
End If
End If
End If
TextBox2.Text = r
End Sub
_________________________________________________________________________________
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butto
n2.Click
TextBox1.Text = " "
TextBox2.Text = " "
End Sub
_________________________________________________________________________________
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butto
n3.Click
End
End Sub
_________________________________________________________________________________

EJERCICIO # 12

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.


Click
'Programa: rea de circulo
'Fecha: 14 de Agosto de 2012
'Declaracin de variables
Dim a, r As Single

r = TextBox1.Text
'Calcular operacin rea
a = 3.141592 * r ^ 2
'Visualizar resultado
TextBox2.Text = a
End Sub
_________________________________________________________________________________
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butto
n2.Click
TextBox1.Text = " "
TextBox2.Text = " "
End Sub
_________________________________________________________________________________
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butto
n3.Click
End
End Sub
_________________________________________________________________________________

EJERCICIO # 13

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.


Click
'Programa: calculo de hipotenusa
'Fecha:
'Declaracin de variables
Dim a, b, c As Single
a = TextBox1.Text
b = TextBox2.Text

'Realizar clculo de hipotenusa


c = (a ^ 2 + b ^ 2) ^ 0.5
'Visualizar clculo de hipotenusa
TextBox3.Text = c
End Sub
________________________________________________________________________

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.


Click
TextBox1.Text = " "
TextBox2.Text = " "
TextBox3.Text = " "
End Sub
________________________________________________________________________
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butto
n3.Click
End
End Sub
________________________________________________________________________

EJERCICIO # 14

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.


Click
'Programa: Distancia entre dos puntos
'Fecha:
'Declaracin de variables
Dim x2, x1, y2, y1, d As Single
x2 = TextBox1.Text
x1 = TextBox2.Text
y2 = TextBox3.Text
y1 = TextBox4.Text
'Calculo de distancia
d = ((x2 - x1) ^ 2 + (y2 - y1) ^ 2) ^ 0.5
'Visualizar resuldo
TextBox5.Text = d
End Sub
________________________________________________________________________

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.


Click
TextBox1.Text = " "
TextBox2.Text = " "
TextBox3.Text = " "
TextBox4.Text = " "
TextBox5.Text = " "
End Sub
________________________________________________________________________
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.
Click
End
End Sub

________________________________________________________________________

EJERCICIO # 15

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.


Click
'Programa: Ciclo condicional promedio
'Fecha:
Dim nomb As String
Dim estado As String
Dim p1, p2, p3, p4, prom As Single
nomb = TextBox1.Text
p1 = TextBox2.Text
p2 = TextBox3.Text
p3 = TextBox4.Text
p4 = TextBox5.Text
prom = (p1 + p2 + p3 + p4) / 4
'Ciclo condicional para evaluar el estado
If prom >= 7 Then
estado = "Aprobado"
Else
If prom < 7 Then
estado = "R e p r o b a d o"
End If
End If
MsgBox(nomb & "su promedio es:" & prom & "Su estado actual:" & estado)

End Sub
________________________________________________________________________

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.


Click
TextBox1.Text = " "
TextBox2.Text = " "
TextBox3.Text = " "
TextBox4.Text = " "
TextBox5.Text = " "
End Sub
________________________________________________________________________
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butto
n3.Click
End
End Sub

________________________________________________________________________

EJERCICIO # 16
Estructura Select - Case

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.


Click
'Programa: Estructura de control Select Case (Meses)
'Fecha:

Dim numeromes As String


numeromes = TextBox1.Text
Select Case numeromes
Case "1"
TextBox2.Text = "Enero"
Case "2"
TextBox2.Text = "Febrero"
Case "3"
TextBox2.Text = "Marzo"
Case "4"
TextBox2.Text = "Abril"
Case "5"
TextBox2.Text = "Mayo"
Case "6"
TextBox2.Text = "Junio"
Case "7"
TextBox2.Text = "Julio"
Case "8"
TextBox2.Text = "Agosto"
Case "9"
TextBox2.Text = "Septiembre"
Case "10"
TextBox2.Text = "Octubre"
Case "11"
TextBox2.Text = "Noviembre"
Case "12"
TextBox2.Text = "Diciembre"
Case Else
TextBox2.Text = "Digite dato correctamente"
End Select
End Sub
________________________________________________________________________
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butto
n2.Click
TextBox1.Text = " "
TextBox2.Text = " "
End Sub

________________________________________________________________________
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butto
n3.Click
End
End Sub
________________________________________________________________________

EJERCICIO # 17
Formulario usando variables y caja de mensaje

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.


Click
Dim num1, num2, suma As Single
num1 = 100
num2 = 200
suma = num1 + num2
MsgBox("La suma de " & num1 & " y " & num2 & " es " & suma)
End Sub

Ejecucin

________________________________________________________________________

EJERCICIO # 18
Cdigo para cambiar el color a un formulario

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.


Click
Dim RGB1, RGB2, RGB3 As Integer
RGB1 = TextBox1.Text
RGB2 = TextBox2.Text
RGB3 = TextBox3.Text
Me.BackColor = Color.FromArgb(RGB1, RGB2, RGB3)
End Sub
________________________________________________________________________
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butto
n2.Click
TextBox1.Text = " "
TextBox2.Text = " "
TextBox3.Text = " "
End Sub
________________________________________________________________________
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Butto
n3.Click
End
End Sub

También podría gustarte