Your SlideShare is downloading. ×
2013

ROYER TUESTA SALAS

EJERCICIOS RESUELTOS EN
VISUAL BASIC 2010

EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

PROYECTOS RESUELTOS EN VISUAL
BASIC.NET

Public Class Form1
Dim r, p, i, n AsIn...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

EndSub
PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e
As Syste...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

i = i – 1
EndIf
ListBox1.Items.RemoveAt(n)
TextBox2.Text = p
TextBox3.Text = i
...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

If ListBox1.Items.Count = 0 Then
Button3.Enabled = False
EndIf
EndSub
PrivateSu...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
EndIf
EndSub

ROYER TUESTA SALAS

Página 5
EJERCICIO VISUAL PERMITE EL
EJERCICIOS RESUELTOS ENQUE MEBASIC 2010 INGRESO DE INCHAS POR
MEDIO DE LOS BOTONES Y CUENTA LO...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
TextBox4.Text = ListBox1.Items.Count +
ListBox2.Items.Count
EndSub
PrivateSub Bu...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
Button2.Enabled = True
EndIf
EndSub
PrivateSub TextBox2_TextChanged(ByVal sender...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
If n + m = 0 Then
Button4.Enabled = False
Button5.Enabled = False
Else
Button4.E...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
'actualiza contadores
TextBox2.Text = ListBox1.Items.Count
TextBox3.Text = ListB...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

TextBox1.Text = ListBox1.Text
ListBox1.Items.RemoveAt(a)
TextBox1.Focus()
EndIf...
PERMITE EL VISUAL BASIC 2010
EJERCICIOS RESUELTOS EN INGRESO DE NOMBRE SUELDO CATEGORIA Y
PERMITE CALCULAR EL DESCUNETO

P...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
Text...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
PERMITE INGRESAR EL CANTIDAD, PRODUCTO, PRECIO Y CALCULA EL TOTAL, EL IGV (18%) ...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
Tex...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
EndSub
PrivateSub Form1_Click(ByVal sender AsObject, ByVal e As
System.EventArgs...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

TextBox9.Text = r
TextBox10.Text = 0.18 * r
TextBox11.Text = 1.18 * r
EndSub
Pr...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

EndIf
EndSub
EndClass

PERMITE INGRESAR UN NUMERO Y CALCULA EL AREA DE UN CUADR...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
PublicClass Form4
Dim l, area, r AsInteger
PrivateSub Button2_Click(ByVal sender...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

PERMITE INGRESAR LA CANTIDAD DE UN MONTO DE DINERO, Y CALCULAR O DA HA SABER
CU...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
'r=0 es divisible en caso contrario no lo es
If r = 0 Then
'numero de billetes d...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
PrivateSub Button12_Click(ByVal sender As System.Object, ByVal e
As System.Event...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
PrivateSub Button8_Click(ByVal sender As System.Object, ByVal e
As System.EventA...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

‘BOTON NUEVO
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox1....
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
EndSub
EndClass

PERMITE CALCULAR LA HORA HACIENDO CLICK EN EL BOTTON HORA A Y
O...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

PERMITE INGRESAR TU Nº DE CELULAR Y LUEGO ESCRIBIR TU MSM AL Nº DE DESTINO Y TE...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

If m = 9 Then
TextBox2.Enabled = True
'button12.enabled=true
Button13.Enabled =...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
TextBox2.Text = ""
TextBox3.Text = ""
EndSub
PrivateSub Button13_Click(ByVal sen...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

PrivateSub Button10_Click(ByVal sender As System.Object, ByVal e
As System.Even...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

PERMITE MOSTRAR MENSAJE SI ACTIVAS EL RADIOBUTTON MASCULINO TE
MUESTRA UN MSM (...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

PERMITE CALCULAR EL =AFP, FONAVI ES SALUD TANTO SI ES DE LOS SIGUIENTE DESCUENT...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

afp = 0.114 * TextBox3.Text
fon = 0.05 * TextBox3.Text
ess = 0.06 * TextBox3.Te...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
CheckBox4.Checked = False
CheckBox5.Checked = False
afp = 0.114 * TextBox3.Text
...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
PERMITE INGRESAR LA HORA TRABAJADA, PAGO POR HORA Y EL SUELDO

Y TIENE LAS SIGUI...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
TextBox3.Text = t1 * t2
TextBox4.Text = t2 * t1
EndIf
EndSub
PrivateSub RadioBut...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

EndSub
PrivateSub RadioButton4_CheckedChanged(ByVal sender As
System.Object, By...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
PrivateSub CheckBox1_CheckedChanged(ByVal sender As
System.Object, ByVal e As Sy...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

INGRESA EL PRODUCTO, PRECIO, CANTIDAD, MONTOY CALCULA EL DESCUENTO (10%) DEL
MO...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e
As System.Event...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

PERMITE EL INGRESO DE SU NOMBRE Y EDAD Y TE MUESTRA UN MENSAJE DE(“MAYOR”) Y
(“...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

PERMITE CONTAR DATOS CUANDO SE INGRESA Y TIENE LAS OBSIONES (“AÑADIR, BORRAR,
N...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
TextBox2.Text = ""
TextBox3.Text = ListBox1.Items.Count
EndSub
PrivateSub Button...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

MsgBox("no ha seleccionado elemento")
Else
TextBox1.Text = ListBox1.Text
ListBo...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

PERMITE EL INGRESO DEL NOMBRE Y APELLIDO Y SELECCIONAR EL NIVEL DEL COMBO,
Y PE...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
'actualiza la cantidad de socios
TextBox2.Text = ListBox2.Items.Count
TextBox3.T...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
MsgBox("socio eliminado")
'actualiza contadores
TextBox2.Text = ListBox2.Items.C...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

Else
TextBox1.Text = ListBox2.Text
ListBox2.Items.RemoveAt(a)
TextBox1.Focus()
...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

n = ListBox2.Items.Count
m = ListBox3.Items.Count
If n + m = 0 Then
Button1.Ena...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
End If
End Sub

ROYER TUESTA SALAS

Página 49
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

ROYER TUESTA SALAS

Página 50
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
PublicClass frmProforma
PublicSub Llenar_Listas()
With cboprocesador.Items
.Add(...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
Llenar_Listas()
EndSub
PrivateSub cboprocesador_SelectedIndexChanged(ByVal sende...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

Case 1
txtPrecioDisco.Text = "100"
Case 2
txtPrecioDisco.Text = "120"
EndSelect...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
PrivateSub RadioButton7_CheckedChanged(ByVal sender As System.Object,
ByVal e As...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
PrivateSub chkScanner_CheckedChanged(ByVal sender As System.Object,
ByVal e As S...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
TotPag = TotVen + TotIGV
PrecioTotalBasica.Text = TotBas.ToString
PrecioTotalAcc...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
PrivateSub Salir_Click(ByVal sender As System.Object, ByVal e As
System.EventArg...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

Sistema de Costos
PublicClass DEMO
Dim suma, subtotal, total, suma2, subtotal2,...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

Case"b"
TXTprecio2.Text = 3
Case"c"
TXTprecio2.Text = 4
Case"d"
TXTprecio2.Text...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

EndSub
PrivateSub SALIR_Click(ByVal sender As System.Object, ByVal e As
System....
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
TXTPRECIO1.Text = ""
TXTTOTAL1.Text = ""
CBOFIJOS.Focus()
EndSub
PrivateSub Butt...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

Sistema de Ventas

ROYER TUESTA SALAS

Página 62
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
PublicClass Form1
Dim suma, subtotal, total AsSingle
PrivateSub Form1_Load(ByVal...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
PrivateSub BTNAGREGAR_Click(ByVal sender As System.Object, ByVal e As
System.Eve...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
total = total + subtotal
TXTSUBTOTAL.Text = total
EndSub
PrivateSub CBOPRODUCTO_...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
PrivateSub BTNNUEVO_Click(ByVal sender As System.Object, ByVal e As
System.Event...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

PublicClass Form1
Dim d AsSingle
PrivateSub Button1_Click(ByVal sender As Syste...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

PublicClass Form2
Dim a, a1, a2 AsString
Dim b, b1, b2 AsString
Dim c, c1, c2 A...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
If TextBox7.Text = ""Then
a1 = TextBox1.Text
b1 = TextBox2.Text
c1 = Val(TextBox...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
mayor = d
MsgBox(b + " Es mayor")
If d2 > mayor Then
mayor = d2
MsgBox(b2 + " Es...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
TextBox9.Text = ""
TextBox10.Text = ""
TextBox11.Text = ""
TextBox12.Text = ""
T...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

ROYER TUESTA SALAS

Página 72
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
PublicClass Form3
Dim s, sn, sa, bon AsSingle
Dim afp, ipss AsSingle
Dim a AsInt...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
Text...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
INCORPORAR DATOS DE OTROS APLICACIONES AL SISTEMA
Primero llevamos la informació...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
Luego nos va a mostrar las tablas que contiene nuestra base de datos de Access, ...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

Y una vez tenido los resultados de la tabla de Access nos vamos a la función ac...
EJERCICIOS RESUELTOS EN VISUAL BASIC 2010

Y luego nos aparece esta siguiente ventana:

Y activamos este checkbox que mues...
Upcoming SlideShare
Loading in...5
×

Ejercicios resueltos en visual basic 2010

44,535

Published on

ESTE ES UN PROYECTO RESUELTO EN VISUAL BASIC 2010 . El proyecto está orientado hacia todas las personas que quieran disponer de ideas, conocimientos, ejemplos y una visión tecnológica de lo que concierne a lo que es un sistema, que esta codificado para soportar todo tipo de acciones del usuario en general.

Visiten mi blog y dejenme sus comentarios ai para yo responderles:

http://royerstudios.blogspot.com/

75 Comments
145 Likes
Statistics
Notes
No Downloads
Views
Total Views
44,535
On Slideshare
0
From Embeds
0
Number of Embeds
40
Actions
Shares
0
Downloads
0
Comments
75
Likes
145
Embeds 0
No embeds

No notes for slide

Transcript of "Ejercicios resueltos en visual basic 2010"

  1. 1. 2013 ROYER TUESTA SALAS EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 EJERCICIOS RESUELTOS EN VISUAL BASIC 2010
  2. 2. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 PROYECTOS RESUELTOS EN VISUAL BASIC.NET Public Class Form1 Dim r, p, i, n AsInteger PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TextBox1.Text = "" TextBox1.Focus() Button1.Enabled = False Button2.Enabled = True ROYER TUESTA SALAS Página 1
  3. 3. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 EndSub PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ListBox1.Items.Add(TextBox1.Text) r = Val(TextBox1.Text) Mod 2 If r = 0 Then p = p + 1 Else i = i + 1 EndIf TextBox2.Text = p TextBox3.Text = i TextBox4.Text = p + i TextBox1.Text = "" Button2.Enabled = False Button1.Enabled = True Button3.Enabled = True Button4.Enabled = True EndSub PrivateSub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click n = ListBox1.SelectedIndex If n = -1 Then MsgBox("no existe elemento seleccionado") Else r = Val(ListBox1.Text) Mod 2 If r = 0 Then p = p – 1 Else ROYER TUESTA SALAS Página 2
  4. 4. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 i = i – 1 EndIf ListBox1.Items.RemoveAt(n) TextBox2.Text = p TextBox3.Text = i TextBox4.Text = p + 1 EndIf If ListBox1.Items.Count = 0 Then Button3.Enabled = False EndIf EndSub PrivateSub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click n = ListBox1.SelectedIndex If n = -1 Then MsgBox("no existe elemento seleccionado") Else r = Val(ListBox1.Text) Mod 2 If r = 0 Then p = p – 1 Else i = i – 1 EndIf TextBox1.Text = ListBox1.SelectedItem ListBox1.Items.RemoveAt(n) TextBox2.Text = p TextBox3.Text = i TextBox4.Text = p + 1 EndIf ROYER TUESTA SALAS Página 3
  5. 5. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 If ListBox1.Items.Count = 0 Then Button3.Enabled = False EndIf EndSub PrivateSub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged If Len(TextBox1.Text) = 0 Then Button2.Enabled = False Else Button2.Enabled = True EndIf EndSub PrivateSub Form1_Activated(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Activated TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" Button1.Enabled = True Button2.Enabled = False Button3.Enabled = False Button4.Enabled = False Button1.Enabled = True EndSub PrivateSub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click r = MsgBox("desea cerra la ventana", MsgBoxStyle.YesNo, "cerrar") If r = 6 Then End ROYER TUESTA SALAS Página 4
  6. 6. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 EndIf EndSub ROYER TUESTA SALAS Página 5
  7. 7. EJERCICIO VISUAL PERMITE EL EJERCICIOS RESUELTOS ENQUE MEBASIC 2010 INGRESO DE INCHAS POR MEDIO DE LOS BOTONES Y CUENTA LOS EL TOTAL TANTO DE UNIVERSITARIO Y ALIANZA PublicClass Form1 Dim n, m, a, b AsInteger PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'boton permite agragar un hincha de universitario ListBox1.Items.Add(TextBox1.Text) TextBox1.Text = "" Button1.Enabled = False Button2.Enabled = False Button3.Enabled = True 'actualiza los contadores de hinchas TextBox2.Text = ListBox1.Items.Count TextBox3.Text = ListBox2.Items.Count ROYER TUESTA SALAS Página 6
  8. 8. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 TextBox4.Text = ListBox1.Items.Count + ListBox2.Items.Count EndSub PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ListBox2.Items.Add(TextBox1.Text) TextBox1.Text = "" Button1.Enabled = False Button2.Enabled = False Button3.Enabled = True 'actualiza los contadores de hinchas TextBox2.Text = ListBox1.Items.Count TextBox3.Text = ListBox2.Items.Count TextBox4.Text = ListBox1.Items.Count + ListBox2.Items.Count EndSub PrivateSub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click 'permite escribir el nombre del nuevo hincha TextBox1.Text = "" TextBox1.Focus() Button3.Enabled = False EndSub PrivateSub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged If Len(TextBox1.Text) = 0 Then Button1.Enabled = False Button2.Enabled = False Else Button1.Enabled = True ROYER TUESTA SALAS Página 7
  9. 9. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 Button2.Enabled = True EndIf EndSub PrivateSub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged n = ListBox1.Items.Count m = ListBox2.Items.Count If n + m = 0 Then Button4.Enabled = False Button5.Enabled = False Else Button4.Enabled = True Button5.Enabled = True EndIf EndSub PrivateSub Form1_Activated(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Activated Button1.Enabled = False Button2.Enabled = False Button3.Enabled = True Button4.Enabled = False Button5.Enabled = False EndSub PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load EndSub PrivateSub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged n = ListBox1.Items.Count m = ListBox2.Items.Count ROYER TUESTA SALAS Página 8
  10. 10. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 If n + m = 0 Then Button4.Enabled = False Button5.Enabled = False Else Button4.Enabled = True Button5.Enabled = True EndIf EndSub PrivateSub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click 'permite borrar hincha n = ListBox1.Items.Count m = ListBox2.Items.Count a = ListBox1.SelectedIndex b = ListBox2.SelectedIndex 'verificar y eliminar cual es la lista seleccionada para eliminar un hincha If a = -1 Then If b = -1 Then MsgBox("no se selecciono elemento a eliminar") Else ListBox2.Items.RemoveAt(b) MsgBox("hincha de alianza eliminado") EndIf Else ListBox1.Items.RemoveAt(a) MsgBox("hincha de universitario eliminado") EndIf ROYER TUESTA SALAS Página 9
  11. 11. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 'actualiza contadores TextBox2.Text = ListBox1.Items.Count TextBox3.Text = ListBox2.Items.Count TextBox4.Text = ListBox1.Items.Count + ListBox2.Items.Count If n + m = 0 Then Button4.Enabled = False Button5.Enabled = False Else Button4.Enabled = True Button5.Enabled = True EndIf EndSub PrivateSub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click 'permite editar hincha n = ListBox1.Items.Count m = ListBox2.Items.Count a = ListBox1.SelectedIndex b = ListBox2.SelectedIndex 'verificar cual es lalista seleccionada para editar un hincha If a = -1 Then If b = -1 Then MsgBox("no se seleciono elemento a editar") Else TextBox1.Text = ListBox2.Items.Count ListBox2.Items.RemoveAt(b) TextBox1.Focus() EndIf Else ROYER TUESTA SALAS Página 10
  12. 12. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 TextBox1.Text = ListBox1.Text ListBox1.Items.RemoveAt(a) TextBox1.Focus() EndIf 'actualiza contadores TextBox2.Text = ListBox1.Items.Count TextBox3.Text = ListBox2.Items.Count TextBox4.Text = ListBox1.Items.Count + ListBox2.Items.Count If n + m = 0 Then Button4.Enabled = False Button5.Enabled = False Else Button4.Enabled = True Button5.Enabled = True EndIf EndSub EndClass ROYER TUESTA SALAS Página 11
  13. 13. PERMITE EL VISUAL BASIC 2010 EJERCICIOS RESUELTOS EN INGRESO DE NOMBRE SUELDO CATEGORIA Y PERMITE CALCULAR EL DESCUNETO PublicClass Form1 PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ‘BOTON CALACULAR If Val(TextBox2.Text) Then TextBox3.Text = 0.12 * Val(TextBox2.Text) Else If Val(TextBox2.Text) Then TextBox3.Text = 0.09 * Val(TextBox2.Text) Else TextBox3.Text = 0.08 * Val(TextBox2.Text) EndIf EndIf TextBox4.Text = Val(TextBox2.Text) + Val(TextBox3.Text) EndSub PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ‘BOTON NUEVO ROYER TUESTA SALAS Página 12
  14. 14. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" TextBox1.Focus() EndSub PrivateSub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click ‘BOTON SALIR End EndSub EndClass ROYER TUESTA SALAS Página 13
  15. 15. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 PERMITE INGRESAR EL CANTIDAD, PRODUCTO, PRECIO Y CALCULA EL TOTAL, EL IGV (18%) Y EL TOTAL A PAGAR PublicClass Form1 Dim tot, r, n AsInteger PrivateSub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click GroupBox1.Enabled = True GroupBox2.Enabled = True GroupBox3.Enabled = True TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" ROYER TUESTA SALAS Página 14
  16. 16. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 TextBox4.Text = "" TextBox5.Text = "" TextBox6.Text = "" TextBox7.Text = "" TextBox8.Text = "" TextBox9.Text = "" TextBox10.Text = "" TextBox11.Text = "" RadioButton1.Checked = False RadioButton2.Checked = False ListBox1.Items.Clear() ListBox2.Items.Clear() ListBox3.Items.Clear() ListBox4.Items.Clear() TextBox1.Focus() Button4.Enabled = False EndSub PrivateSub RadioButton1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles RadioButton1.Click If RadioButton1.Checked = TrueThen TextBox2.Visible = True EndIf EndSub PrivateSub RadioButton2_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles RadioButton2.Click If RadioButton2.Checked = TrueThen TextBox2.Visible = False EndIf ROYER TUESTA SALAS Página 15
  17. 17. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 EndSub PrivateSub Form1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Click GroupBox1.Enabled = False GroupBox2.Enabled = False GroupBox3.Enabled = False Button1.Enabled = False Button2.Enabled = True Button3.Enabled = False Button4.Enabled = True Button5.Enabled = False Button6.Enabled = True EndSub PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'nuevo producto TextBox6.Focus() TextBox6.Text = "" TextBox7.Text = "" TextBox8.Text = "" EndSub PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'agregar producto ListBox1.Items.Add(TextBox6.Text) ListBox2.Items.Add(TextBox7.Text) ListBox3.Items.Add(TextBox8.Text) r = Val(TextBox6.Text) * Val(TextBox8.Text) ListBox4.Items.Add(r) tot = tot + r ROYER TUESTA SALAS Página 16
  18. 18. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 TextBox9.Text = r TextBox10.Text = 0.18 * r TextBox11.Text = 1.18 * r EndSub PrivateSub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged If Len(TextBox8.Text) = 0 Then Button1.Enabled = False Else Button1.Enabled = True EndIf EndSub PrivateSub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click 'borrar producto n = ListBox1.SelectedIndex If n = -1 Then MsgBox("seleccione elemento de la lista 1") Else r = Val(ListBox1.SelectedItem) * Val(ListBox3.Items(n)) ListBox1.Items.RemoveAt(n) ListBox2.Items.RemoveAt(n) ListBox3.Items.RemoveAt(n) ListBox4.Items.RemoveAt(n) tot = tot – r TextBox9.Text = tot TextBox10.Text = 0.18 * tot TextBox11.Text = 1.18 * tot ROYER TUESTA SALAS Página 17
  19. 19. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 EndIf EndSub EndClass PERMITE INGRESAR UN NUMERO Y CALCULA EL AREA DE UN CUADRADO ROYER TUESTA SALAS Página 18
  20. 20. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 PublicClass Form4 Dim l, area, r AsInteger PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ‘BOTON CALCULAR l = (TextBox1.Text) area = l * l TextBox2.Text = area EndSub PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ‘BOTON NUEVO TextBox1.Text = "" TextBox2.Text = "" TextBox1.Focus() EndSub PrivateSub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click ‘BOTON SALIR r = MsgBox("desea cerrar la ventana", MsgBoxStyle.YesNo, "cerrar") If r = 6 Then End EndIf EndSub EndClass ROYER TUESTA SALAS Página 19
  21. 21. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 PERMITE INGRESAR LA CANTIDAD DE UN MONTO DE DINERO, Y CALCULAR O DA HA SABER CUANTO DE BILLETES DE HA DE TENER SEGÚN LA CANTIDAD INGRESADA: BILLETES DE (50, 100,200) Y MUESTRA UN MENSAJE SI DESEA RETIRAR SU TRANSACCION (DINERO) PublicClass Form1 Dim r, m, b200, b100, b50 AsSingle PrivateSub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click 'boton ok m = Label2.Text 'verificar si el monto es divisible por 50 r = m Mod 50 ROYER TUESTA SALAS Página 20
  22. 22. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 'r=0 es divisible en caso contrario no lo es If r = 0 Then 'numero de billetes de 200 b200 = m / 200 m = m Mod 200 'numero de billetes de 100 b100 = m / 100 m = m Mod 100 'numero de billetes de 50 b50 = m / 50 m = m Mod 50 'mostrar en la caja de texto de billetes de 200 TextBox1.Text = b200 'mostrar en la caja de texto de billetes de 100 TextBox2.Text = b100 'mostrar en la caja de texto de billetes de 50 TextBox3.Text = b50 MsgBox("retire su dinero por favor") Else MsgBox("monto ingresado no es correcto") Button12.Focus() EndIf EndSub PrivateSub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click MsgBox("la transeccio ha terminado") End EndSub ROYER TUESTA SALAS Página 21
  23. 23. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 PrivateSub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click Label2.Text = "" EndSub PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Label2.Text = Label2.Text + "1" EndSub PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Label2.Text = Label2.Text + "2" EndSub PrivateSub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Label2.Text = Label2.Text + "3" EndSub PrivateSub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Label2.Text = Label2.Text + "4" EndSub PrivateSub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click Label2.Text = Label2.Text + "5" EndSub PrivateSub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click Label2.Text = Label2.Text + "6" EndSub PrivateSub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click Label2.Text = Label2.Text + "7" EndSub ROYER TUESTA SALAS Página 22
  24. 24. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 PrivateSub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click Label2.Text = Label2.Text + "8" EndSub PrivateSub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click Label2.Text = Label2.Text + "9" EndSub PrivateSub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click Label2.Text = Label2.Text + "0" EndSub EndClass PERMITE EL INGRESO DE DOS NUMEROS Y CALCULA SGUN EL CHECBOX QUE HAY (SUMA, RESTA, MULTIPLICACION Y DIVISION) PublicClass Form1 Dim n, r AsInteger PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ROYER TUESTA SALAS Página 23
  25. 25. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 ‘BOTON NUEVO TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox1.Focus() EndSub PrivateSub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged n = ComboBox1.SelectedIndex SelectCase n Case 0 : TextBox3.Text = Val(TextBox1.Text) + Val(TextBox2.Text) Case 1 : TextBox3.Text = Val(TextBox1.Text) - Val(TextBox2.Text) Case 2 : TextBox3.Text = Val(TextBox1.Text) * Val(TextBox2.Text) Case 3 : TextBox3.Text = Val(TextBox1.Text) / Val(TextBox2.Text) EndSelect EndSub PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load ComboBox1.Items.Add("suma") ComboBox1.Items.Add("resta") ComboBox1.Items.Add("producto") ComboBox1.Items.Add("division") EndSub PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ‘BOTON CERRAR r = MsgBox("desea cerrar esta ventana", MsgBoxStyle.YesNo, "cerrar") If r = 6 Then End EndIf ROYER TUESTA SALAS Página 24
  26. 26. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 EndSub EndClass PERMITE CALCULAR LA HORA HACIENDO CLICK EN EL BOTTON HORA A Y OJO SOLO SE MUESTRA CON EL RELOJ DEL COMPUTADOR PublicClass Form1 PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ‘BOTON HORA Dim hora = Hour(Now) Dim min = Minute(Now) Dim seg = Second(Now) TextBox1.Text = hora TextBox2.Text = min TextBox3.Text = seg EndSub EndClass ROYER TUESTA SALAS Página 25
  27. 27. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 PERMITE INGRESAR TU Nº DE CELULAR Y LUEGO ESCRIBIR TU MSM AL Nº DE DESTINO Y TE MOSTRARA UN MENSAJE DE (“SU MSM HA SIDO ENVIADO SATISFACTORIAMENTE”) OJO SOLO PERMITE 140 CARACTERES PublicClass Form1 Dim n, m AsInteger PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TextBox1.Text = TextBox1.Text + "1" EndSub PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click TextBox1.Text = TextBox1.Text + "2" EndSub PrivateSub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged m = Len(TextBox1.Text) ROYER TUESTA SALAS Página 26
  28. 28. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 If m = 9 Then TextBox2.Enabled = True 'button12.enabled=true Button13.Enabled = True TextBox2.Focus() EndIf EndSub PrivateSub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged n = Len(TextBox2.Text) TextBox3.Text = n If n > 0 Then Button12.Enabled = True Else Button12.Enabled = False EndIf If n >= 140 Then MsgBox("max de caracteres 140, si sigues escribiendo se borran todo") If n = 141 Then TextBox2.Text = "" EndIf EndIf EndSub PrivateSub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click ‘BOTON ENVIAR MsgBox("su mensaje ha sido enviado satisfactoriamente") TextBox1.Text = "" ROYER TUESTA SALAS Página 27
  29. 29. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 TextBox2.Text = "" TextBox3.Text = "" EndSub PrivateSub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click ‘BOTON SALIR End EndSub PrivateSub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click TextBox1.Text = TextBox1.Text + "3" EndSub PrivateSub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click TextBox1.Text = TextBox1.Text + "4" EndSub PrivateSub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click TextBox1.Text = TextBox1.Text + "5" EndSub PrivateSub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click TextBox1.Text = TextBox1.Text + "6" EndSub PrivateSub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click TextBox1.Text = TextBox1.Text + "7" EndSub PrivateSub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click TextBox1.Text = TextBox1.Text + "8" EndSub ROYER TUESTA SALAS Página 28
  30. 30. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 PrivateSub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click TextBox1.Text = TextBox1.Text + "9" EndSub PrivateSub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click If Len(TextBox1.Text) = 0 Or _ Val(TextBox1.Text) >= 1 Then TextBox1.Text = TextBox1.Text &"0" EndIf EndSub PrivateSub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click TextBox2.Text = "" EndSub EndClass ROYER TUESTA SALAS Página 29
  31. 31. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 PERMITE MOSTRAR MENSAJE SI ACTIVAS EL RADIOBUTTON MASCULINO TE MUESTRA UN MSM (“MASCULINO”) Y SI ACTIVAS EL RADIO BUTTON FEMENINO TE MUESTRA UN MSM (“FEMENINO) PublicClass Form1 PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If RadioButton1.Checked = TrueThen MsgBox("sexo Masculino") EndIf If RadioButton2.Checked = TrueThen MsgBox("sexo Femenino") EndIf EndSub EndClass ROYER TUESTA SALAS Página 30
  32. 32. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 PERMITE CALCULAR EL =AFP, FONAVI ES SALUD TANTO SI ES DE LOS SIGUIENTE DESCUENTOS (“NOMBRADO, CONTRATADO Y PRACTICANTE”) EGUN ESTA CARACTERISTICAS QUE TENEMOS =MOVILIDAD, TOTAL INGRESO, TOTAL DESCUENTO, SUELDO A PAGAR PublicClass Form1 Dim afp, fon, ess, solid, cuarta AsSingle PrivateSub RadioButton1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles RadioButton1.Click CheckBox1.Checked = True CheckBox2.Checked = True CheckBox3.Checked = True CheckBox4.Checked = False CheckBox5.Checked = False ROYER TUESTA SALAS Página 31
  33. 33. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 afp = 0.114 * TextBox3.Text fon = 0.05 * TextBox3.Text ess = 0.06 * TextBox3.Text TextBox4.Text = afp TextBox5.Text = fon TextBox6.Text = ess TextBox9.Text = 80 EndSub PrivateSub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged CheckBox1.Checked = True CheckBox2.Checked = True CheckBox3.Checked = False CheckBox4.Checked = False CheckBox5.Checked = False afp = 0.114 * TextBox3.Text fon = 0.05 * TextBox3.Text ess = 0.06 * TextBox3.Text TextBox4.Text = afp TextBox5.Text = fon TextBox6.Text = ess TextBox10.Text = 100 EndSub PrivateSub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged CheckBox1.Checked = True CheckBox2.Checked = False CheckBox3.Checked = False ROYER TUESTA SALAS Página 32
  34. 34. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 CheckBox4.Checked = False CheckBox5.Checked = False afp = 0.114 * TextBox3.Text fon = 0.05 * TextBox3.Text ess = 0.06 * TextBox3.Text TextBox4.Text = afp TextBox5.Text = fon TextBox6.Text = ess TextBox11.Text = 160 EndSub PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ‘BOTON NUEVO TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" TextBox5.Text = "" TextBox6.Text = "" TextBox7.Text = "" TextBox8.Text = "" TextBox9.Text = "" RadioButton1.Checked = False TextBox1.Focus() EndSub PrivateSub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click End EndSub EndClass ROYER TUESTA SALAS Página 33
  35. 35. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 PERMITE INGRESAR LA HORA TRABAJADA, PAGO POR HORA Y EL SUELDO Y TIENE LAS SIGUIENTE BONIFICACIONES (“UN HIJO=5%),(“DOS HIJOS=10%”),(“TRES HIJOS=15%”),(“CUATRO O MAS HIJOS=20%”) TAMBIEN TIENE ESTADO CIVIL QUE PERMITE CALCULAR SI ES SOLTERO O CASADO SEGÚN LOS MONTOS DE LOS ANTERIORES Y TAMBIEN TIENE LOS SIGUIENTES DESCUENTOS (“AFP=7%”),(“CUARTA CATEGORIA=8%”) Y POR ULTIMO MUESTRA EL NETO A PAGAR SEGÚN LAS OPCIONES (BONIFICACIONES, ESTADO CIVIL Y DESCUENTOS” PublicClass Form1 Dim t1, t2 AsInteger PrivateSub TextBox2_KeyPress(ByVal sender AsObject, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then t1 = TextBox1.Text t2 = TextBox2.Text ROYER TUESTA SALAS Página 34
  36. 36. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 TextBox3.Text = t1 * t2 TextBox4.Text = t2 * t1 EndIf EndSub PrivateSub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged If RadioButton1.Checked = TrueThen TextBox4.Text = Val(TextBox3.Text) + Val(TextBox3.Text) * 0.05 Else RadioButton1.Checked = False EndIf EndSub PrivateSub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged If RadioButton2.Checked = TrueThen TextBox4.Text = Val(TextBox3.Text) + Val(TextBox3.Text) * 0.1 Else RadioButton2.Checked = False EndIf EndSub PrivateSub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged If RadioButton3.Checked = TrueThen TextBox4.Text = Val(TextBox3.Text) + Val(TextBox3.Text) * 0.15 Else RadioButton3.Checked = False EndIf ROYER TUESTA SALAS Página 35
  37. 37. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 EndSub PrivateSub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged If RadioButton4.Checked = TrueThen TextBox4.Text = Val(TextBox3.Text) + Val(TextBox3.Text) * 0.2 Else RadioButton4.Checked = False EndIf EndSub PrivateSub RadioButton6_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton6.CheckedChanged If RadioButton6.Checked = TrueThen TextBox4.Text = Val(TextBox3.Text) + Val(TextBox3.Text) * 0.03 Else RadioButton6.Checked = False EndIf EndSub PrivateSub RadioButton5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton5.CheckedChanged If RadioButton5.Checked = TrueThen TextBox4.Text = 0 Else TextBox4.Text = Val(TextBox3.Text) RadioButton2.Checked = False EndIf EndSub ROYER TUESTA SALAS Página 36
  38. 38. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 PrivateSub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged If CheckBox1.Checked = TrueThen TextBox4.Text = Val(TextBox4.Text) Val(TextBox4.Text) * 0.07 Else CheckBox1.Enabled = False EndIf EndSub PrivateSub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged If CheckBox2.Checked = TrueThen TextBox4.Text = Val(TextBox3.Text) Val(GroupBox1.CanFocus) - Val(RadioButton6.Checked) Else CheckBox1.Enabled = False EndIf EndSub EndClass ROYER TUESTA SALAS Página 37
  39. 39. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 INGRESA EL PRODUCTO, PRECIO, CANTIDAD, MONTOY CALCULA EL DESCUENTO (10%) DEL MONTO Y CALCULA EL TOTAL A PAGAR PublicClass Form1 Dim pre, can, monto, descto, pago, r AsSingle PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ‘BOTON NUEVO TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" TextBox5.Text = "" TextBox6.Text = "" TextBox1.Focus() EndSub ROYER TUESTA SALAS Página 38
  40. 40. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ‘BOTON CALCULAR pre = (TextBox2.Text) can = (TextBox3.Text) monto = pre * can If CheckBox1.Checked = TrueThen descto = 0.1 * monto Else descto = 0 EndIf pago = monto – descto TextBox4.Text = monto TextBox5.Text = descto TextBox6.Text = pago EndSub PrivateSub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click ‘BOTON SALIR r = MsgBox("desea cerrar la ventana", MsgBoxStyle.YesNo, "cerrar") If r = 6 Then End EndIf EndSub EndClass ROYER TUESTA SALAS Página 39
  41. 41. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 PERMITE EL INGRESO DE SU NOMBRE Y EDAD Y TE MUESTRA UN MENSAJE DE(“MAYOR”) Y (“MENOR”) SEGÚN TU EDAD PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ‘BOTON NUEVO TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox1.Focus() EndSub PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ‘BOTON ACEPTAR If Val(TextBox2.Text) >= 18 Then TextBox3.Text = "mayor de edad" Else TextBox3.Text = "menor de edad" EndIf EndSub ROYER TUESTA SALAS Página 40
  42. 42. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 PERMITE CONTAR DATOS CUANDO SE INGRESA Y TIENE LAS OBSIONES (“AÑADIR, BORRAR, NUEVO, EDITAR Y INDEX”) PublicClass Form1 Dim n AsInteger PrivateSub ListBox1_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles ListBox1.Click TextBox1.Text = ListBox1.SelectedIndex EndSub PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TextBox1.Text = ListBox1.SelectedIndex EndSub PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ListBox1.Items.Add(TextBox2.Text) ROYER TUESTA SALAS Página 41
  43. 43. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 TextBox2.Text = "" TextBox3.Text = ListBox1.Items.Count EndSub PrivateSub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click ‘boton borrar n = ListBox1.SelectedIndex If n = -1 Then MsgBox("no hay elemento seleccionado") Else ListBox1.Items.RemoveAt(n) TextBox3.Text = ListBox1.Items.Count EndIf EndSub PrivateSub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click TextBox2.Focus() EndSub PrivateSub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged If Len(TextBox2.Text) = 0 Then Button2.Enabled = False Else Button2.Enabled = True EndIf EndSub PrivateSub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click n = ListBox1.SelectedIndex If n = -1 Then ROYER TUESTA SALAS Página 42
  44. 44. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 MsgBox("no ha seleccionado elemento") Else TextBox1.Text = ListBox1.Text ListBox1.Items.RemoveAt(n) TextBox2.Focus() EndIf EndSub EndClass ROYER TUESTA SALAS Página 43
  45. 45. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 PERMITE EL INGRESO DEL NOMBRE Y APELLIDO Y SELECCIONAR EL NIVEL DEL COMBO, Y PERMITE AGREGAR AL LISTBOX. SEGÚN TU NIVELQUE ES (“A”, “B”, “C”) LA CANTIDAD DE SOCIOS EMPIEZA A CONTAR ES DECIR ESO SE DA EN LA CATEGORIA DE LA ESTADISTICA DE SOCIOS Y TIENE LAS OBSIONES (“NUEVO, AGREGAR, ELEMINAR, EDITAR, ELIMINAR TODO, CERRAR”) Dim n, m, a, b, c, r As Single Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'boton permite agregar un nuevo socio ListBox2.Items.Add(TextBox1.Text) TextBox1.Text = "" Button1.Enabled = True Button2.Enabled = True Button4.Enabled = False ROYER TUESTA SALAS Página 44
  46. 46. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 'actualiza la cantidad de socios TextBox2.Text = ListBox2.Items.Count TextBox3.Text = ListBox3.Items.Count TextBox5.Text = ListBox2.Items.Count + ListBox3.Items.Count End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 'agregar socio ListBox2.Items.Add(TextBox1.Text) ListBox3.Items.Add(TextBox1.Text) r = (TextBox2.Text) + (TextBox3.Text) + (TextBox4.Text) TextBox5.Text = r End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click 'permite eliminar socio n = ListBox2.Items.Count m = ListBox3.Items.Count a = ListBox2.SelectedIndex b = ListBox3.SelectedIndex 'verifica y elimina cual es la lista seleccionada para eliminar un socio If a = -1 Then MsgBox("no se selecciono elemento a eliminar") Else ListBox3.Items.RemoveAt(b) MsgBox("socio eliminado") End If ListBox2.Items.RemoveAt(a) ROYER TUESTA SALAS Página 45
  47. 47. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 MsgBox("socio eliminado") 'actualiza contadores TextBox2.Text = ListBox2.Items.Count TextBox3.Text = ListBox3.Items.Count TextBox4.Text = ListBox2.Items.Count If n + m = 0 Then Button1.Enabled = False Button3.Enabled = False Else Button1.Enabled = True Button3.Enabled = True End If End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click 'permite editar socio n = ListBox2.Items.Count m = ListBox3.Items.Count a = ListBox2.SelectedIndex b = ListBox3.SelectedIndex 'verificar cual es la lista seleccionada para editar socio If a = -1 Then If b = -1 Then MsgBox("no se selecciono elemento a editar") Else TextBox1.Text = ListBox3.Text ListBox3.Items.RemoveAt(b) TextBox1.Focus() End If ROYER TUESTA SALAS Página 46
  48. 48. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 Else TextBox1.Text = ListBox2.Text ListBox2.Items.RemoveAt(a) TextBox1.Focus() End If 'actualiza contadores TextBox2.Text = ListBox2.Items.Count TextBox3.Text = ListBox3.Items.Count TextBox4.Text = ListBox2.Items.Count TextBox5.Text = ListBox2.Items.Count + ListBox3.Items.Count If n + m = 0 Then Button3.Enabled = False Button4.Enabled = False Else Button3.Enabled = True Button4.Enabled = True End If End Sub Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged If Len(TextBox1.Text) = 0 Then Button1.Enabled = False Button2.Enabled = False Else Button1.Enabled = True Button2.Enabled = True End If End Sub Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged ROYER TUESTA SALAS Página 47
  49. 49. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 n = ListBox2.Items.Count m = ListBox3.Items.Count If n + m = 0 Then Button1.Enabled = False Button3.Enabled = False Else Button1.Enabled = True Button3.Enabled = True End If End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load n = ComboBox1.SelectedIndex End Sub Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged n = ListBox2.Items.Count m = ListBox2.Items.Count If n + m = 0 Then Button1.Enabled = False Button3.Enabled = False Else Button1.Enabled = True Button3.Enabled = True End If End Sub Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click r = MsgBox("desea cerrar esta ventana", MsgBoxStyle.YesNo, "cerrar") If r = 6 Then End ROYER TUESTA SALAS Página 48
  50. 50. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 End If End Sub ROYER TUESTA SALAS Página 49
  51. 51. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 ROYER TUESTA SALAS Página 50
  52. 52. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 PublicClass frmProforma PublicSub Llenar_Listas() With cboprocesador.Items .Add("Pentium II 350 Mhz") .Add("Pentium III 400 Mhz") .Add("Pentium III 500 Mhz") .Add("Pentium III 700 Mhz") EndWith With Listmemoria.Items .Add("32 Mb") .Add("64 Mb") .Add("128 Mb") EndWith With Listdisco.Items .Add("10 Gb") .Add("20 Gb") .Add("30 Gb") EndWith With Listimpresora.Items .Add("Stylus Color 400") .Add("Stylus Color 500") .Add("Stylus Color 700") EndWith With Listscanner.Items .Add("Pequeño") .Add("Mediano") .Add("Grande") EndWith EndSub PrivateSub frmProforma_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load ROYER TUESTA SALAS Página 51
  53. 53. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 Llenar_Listas() EndSub PrivateSub cboprocesador_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboprocesador.SelectedIndexChanged SelectCase cboprocesador.SelectedIndex Case 0 txtPrecioProcesador.Text = "100" Case 1 txtPrecioProcesador.Text = "150" Case 2 txtPrecioProcesador.Text = "200" Case 3 txtPrecioProcesador.Text = "300" EndSelect EndSub PrivateSub Listmemoria_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Listmemoria.SelectedIndexChanged SelectCase Listmemoria.SelectedIndex Case 0 txtPrecioMemoria.Text = "30" Case 1 txtPrecioMemoria.Text = "50" Case 2 txtPrecioMemoria.Text = "70" EndSelect EndSub PrivateSub TabPage1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabPage1.Click EndSub PrivateSub Listdisco_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Listdisco.SelectedIndexChanged SelectCase Listdisco.SelectedIndex Case 0 txtPrecioDisco.Text = "80" ROYER TUESTA SALAS Página 52
  54. 54. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 Case 1 txtPrecioDisco.Text = "100" Case 2 txtPrecioDisco.Text = "120" EndSelect EndSub PrivateSub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged txtPrecioMonitor.Text = "150" EndSub PrivateSub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged txtPrecioMonitor.Text = "200" EndSub PrivateSub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged txtPrecioTeclado.Text = "15" EndSub PrivateSub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged txtPrecioTeclado.Text = "30" EndSub PrivateSub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkLectoraDisco.CheckedChanged gbxLectoraDisco.Enabled = chkLectoraDisco.Checked EndSub PrivateSub RadioButton5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton5.CheckedChanged txtPrecioLectoraDisco.Text = "20" EndSub PrivateSub RadioButton6_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton6.CheckedChanged txtPrecioLectoraDisco.Text = "40" EndSub ROYER TUESTA SALAS Página 53
  55. 55. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 PrivateSub RadioButton7_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton7.CheckedChanged txtPrecioLectoraDisco.Text = "50" EndSub PrivateSub chkLectoraCD_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkLectoraCD.CheckedChanged gbxLectoraCD.Enabled = chkLectoraCD.Checked EndSub PrivateSub RadioButton8_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton8.CheckedChanged txtPrecioLectoraCD.Text = "40" EndSub PrivateSub RadioButton9_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton9.CheckedChanged txtPrecioLectoraCD.Text = "50" EndSub PrivateSub RadioButton10_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton10.CheckedChanged txtPrecioLectoraCD.Text = "70" EndSub PrivateSub chkImpresora_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkImpresora.CheckedChanged Listimpresora.Enabled = chkImpresora.Checked EndSub PrivateSub Listimpresora_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Listimpresora.SelectedIndexChanged SelectCase Listimpresora.SelectedIndex Case 0 txtPrecioImpresora.Text = "100" Case 1 txtPrecioImpresora.Text = "200" Case 2 txtPrecioImpresora.Text = "300" EndSelect EndSub ROYER TUESTA SALAS Página 54
  56. 56. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 PrivateSub chkScanner_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkScanner.CheckedChanged Listscanner.Enabled = chkScanner.Checked EndSub PrivateSub Listscanner_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Listscanner.SelectedIndexChanged SelectCase Listscanner.SelectedIndex Case 0 txtPrecioScanner.Text = "100" Case 1 txtPrecioScanner.Text = "200" Case 3 txtPrecioScanner.Text = "400" EndSelect EndSub PrivateSub Calcular_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calcular.Click Dim PrePro, PreMem, PreDis, PreMon, PreTec AsInteger Dim PreLDi, PreLCD, PreImp, PreSca AsInteger Dim TotBas, TotAcc, TotVen, TotIGV, TotPag AsSingle PrePro = Int(txtPrecioProcesador.Text) PreMem = Int(txtPrecioMemoria.Text) PreDis = Int(txtPrecioDisco.Text) PreMon = Int(txtPrecioMonitor.Text) PreTec = Int(txtPrecioTeclado.Text) PreLDi = Int(txtPrecioLectoraDisco.Text) PreLCD = Int(txtPrecioLectoraCD.Text) PreImp = Int(txtPrecioImpresora.Text) PreSca = txtPrecioScanner.Text.ToString TotBas = PrePro + PreMem + PreDis + PreMon + PreTec TotAcc = PreLDi + PreLCD + PreImp + PreSca TotVen = TotBas + TotAcc TotIGV = Val(0.18 * TotVen) ROYER TUESTA SALAS Página 55
  57. 57. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 TotPag = TotVen + TotIGV PrecioTotalBasica.Text = TotBas.ToString PrecioTotalAccesorios.Text = TotAcc.ToString PrecioTotalVentas.Text = TotVen.ToString TotalIGV.Text = TotIGV.ToString PrecioTotalPagar.Text = TotPag.ToString EndSub PrivateSub Nuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Nuevo.Click 'Configuracion Basica cboprocesador.Text = "" txtPrecioProcesador.Text = "" txtPrecioMemoria.Text = "" txtPrecioDisco.Text = "" txtPrecioMonitor.Text = "" txtPrecioTeclado.Text = "" 'Accesorios txtPrecioLectoraDisco.Text = "" txtPrecioLectoraCD.Text = "" txtPrecioImpresora.Text = "" txtPrecioScanner.Text = "" 'Generales NombreCliente.Text = "" Telefono.Text = "" Direccion.Text = "" PrecioTotalBasica.Text = "" PrecioTotalAccesorios.Text = "" PrecioTotalVentas.Text = "" TotalIGV.Text = "" PrecioTotalPagar.Text = "" EndSub ROYER TUESTA SALAS Página 56
  58. 58. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 PrivateSub Salir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Salir.Click End EndSub EndClass ROYER TUESTA SALAS Página 57
  59. 59. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 Sistema de Costos PublicClass DEMO Dim suma, subtotal, total, suma2, subtotal2, total2 AsSingle PrivateSub DEMO_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load 'ASIGNACION DE LOS NOMBRES DEL COMBO suma = 0 subtotal = 0 total = 0 'datos del combobox del producto CBOFIJOS.Items.Add("LUZ") CBOFIJOS.Items.Add("AGUA") CBOFIJOS.Items.Add("TELEFONO") CBOFIJOS.Items.Add("d.INTERNET") 'datos del combobox del fijo CBOVARIABLES.Items.Add("a.INSUMO 1") CBOVARIABLES.Items.Add("b.INSUMO 2") CBOVARIABLES.Items.Add("c.INSUMO 3") CBOVARIABLES.Items.Add("d.INSUMO 4") CBOPRODUCTO.Items.Add("A") CBOPRODUCTO.Items.Add("B") CBOPRODUCTO.Items.Add("C") CBOPRODUCTO.Items.Add("D") EndSub PrivateSub CBOVARIABLES_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CBOVARIABLES.SelectedIndexChanged SelectCase CBOVARIABLES.Text.Substring(0, 1) Case"a" TXTprecio2.Text = 5 ROYER TUESTA SALAS Página 58
  60. 60. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 Case"b" TXTprecio2.Text = 3 Case"c" TXTprecio2.Text = 4 Case"d" TXTprecio2.Text = 6 EndSelect EndSub PrivateSub AGREGAR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btonagrgar2.Click If Val(TXTprecio2.Text) = 0 ThenExitSub If Val(txtcantidad2.Text) = 0 ThenExitSub Dim linea AsNew ListViewItem linea = LSTVARIABLE.Items.Add(CBOVARIABLES.Text) linea.SubItems.Add(TXTprecio2.Text) linea.SubItems.Add(txtcantidad2.Text) linea.SubItems.Add(txtcantidad2.Text * TXTprecio2.Text) total2 = total2 + subtotal2 txtsubtotal2.Text = total2 'suma del subtotal2 de costos TextBox11.Text = txtsubtotal2.Text EndSub PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If Val(TXTPRECIO1.Text) = 0 ThenExitSub If Val(TXTCANTIDAD1.Text) = 0 ThenExitSub Dim linea AsNew ListViewItem linea = LSTCOSTOS.Items.Add(CBOFIJOS.Text) linea.SubItems.Add(TXTPRECIO1.Text) linea.SubItems.Add(TXTCANTIDAD1.Text * TXTPRECIO1.Text) total = total + subtotal txtsubtotal1.Text = total TextBox12.Text = txtsubtotal1.Text ROYER TUESTA SALAS Página 59
  61. 61. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 EndSub PrivateSub SALIR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SALIR.Click Me.Hide() EndSub PrivateSub ok_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ok.Click TextBox13.Text = Val(TextBox11.Text) + Val(TextBox12.Text) EndSub PrivateSub TXTPRECIO_KeyPress(ByVal sender AsObject, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TXTPRECIO1.KeyPress If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then If Val(TXTPRECIO1.Text) > 0 Then subtotal = Val(TXTCANTIDAD1.Text) * Val(TXTPRECIO1.Text) TXTTOTAL1.Text() = subtotal Button1.Focus() EndIf EndIf EndSub PrivateSub txtcantidad2_KeyPress(ByVal sender AsObject, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtcantidad2.KeyPress If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then If Val(txtcantidad2.Text) > 0 Then subtotal2 = Val(txtcantidad2.Text) * Val(TXTprecio2.Text) txttotal2.Text() = subtotal2 btonagrgar2.Focus() EndIf EndIf EndSub PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click CBOFIJOS.Text = "" ROYER TUESTA SALAS Página 60
  62. 62. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 TXTPRECIO1.Text = "" TXTTOTAL1.Text = "" CBOFIJOS.Focus() EndSub PrivateSub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click CBOVARIABLES.Text = "" TXTprecio2.Text = "" txtcantidad2.Text = "" txttotal2.Text = "" CBOVARIABLES.Focus() EndSub PrivateSub CBOPRODUCTO_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CBOPRODUCTO.SelectedIndexChanged EndSub EndClass ROYER TUESTA SALAS Página 61
  63. 63. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 Sistema de Ventas ROYER TUESTA SALAS Página 62
  64. 64. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 PublicClass Form1 Dim suma, subtotal, total AsSingle PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load suma = 0 subtotal = 0 TOTAL = 0 CBOPRODUCTO.Items.Add("a.COCINA MABE AUTOMATICA") CBOPRODUCTO.Items.Add("b.COCINA MABE ELECTRICA") CBOPRODUCTO.Items.Add("c.COCINA MABE CONVENCIONAL") CBOPRODUCTO.Items.Add("d.LICUADORA 2 VEL.") CBOPRODUCTO.Items.Add("e.LICUADORA 4 VEL.") CBOPRODUCTO.Items.Add("F.LICUADORA 8 VEL.") CBOPRODUCTO.Items.Add("g.LICUADORA 16 VEL.") CBOPRODUCTO.Items.Add("h.LICUADORA PROFEXIONAL") CBOPRODUCTO.Items.Add("i.EQUIPO SONIDO PHILLIPS 500 W") CBOPRODUCTO.Items.Add("J.EQUIPO SONIDO PHILLIPS 1500 W") CBOPRODUCTO.Items.Add("k.EQUIPO SONIDO SONY 500 W") CBOPRODUCTO.Items.Add("l.EQUIPO SONIDO LG 1500 W") CBOPRODUCTO.Items.Add("m.REPRODUCTOR MP3 PHILLIPS W343") CBOPRODUCTO.Items.Add("n.REPRODUCTOR MP3 SONY SS123") EndSub PrivateSub TXTCANTIDAD_KeyPress(ByVal sender AsObject, ByVal e As System.Windows.Forms.KeyPressEventArgs) If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then If Val(TXTCANTIDAD.Text) > 0 Then subtotal = Val(TXTCANTIDAD.Text) * Val(TXTPRECIO.Text) TXTTOTAL.Text() = subtotal BTNAGREGAR.Focus() EndIf EndIf EndSub ROYER TUESTA SALAS Página 63
  65. 65. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 PrivateSub BTNAGREGAR_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) If Val(TXTPRECIO.Text) = 0 ThenExitSub If Val(TXTCANTIDAD.Text) = 0 ThenExitSub Dim linea AsNew ListViewItem linea.SubItems.Add(CBOPRODUCTO.Text) linea.SubItems.Add(TXTPRECIO.Text) linea.SubItems.Add(TXTCANTIDAD.Text) linea.SubItems.Add(TXTCANTIDAD.Text * TXTPRECIO.Text) TOTAL = TOTAL + subtotal TXTSUBTOTAL.Text = TOTAL EndSub PrivateSub TXTCANTIDAD_KeyPress1(ByVal sender AsObject, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TXTCANTIDAD.KeyPress If e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.Return) Then If Val(TXTCANTIDAD.Text) > 0 Then subtotal = Val(TXTCANTIDAD.Text) * Val(TXTPRECIO.Text) TXTTOTAL.Text() = subtotal BTNAGREGAR.Focus() EndIf EndIf EndSub PrivateSub BTNAGREGAR_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNAGREGAR.Click If Val(TXTPRECIO.Text) = 0 ThenExitSub If Val(TXTCANTIDAD.Text) = 0 ThenExitSub Dim linea AsNew ListViewItem linea = LSTCOMPRA.Items.Add(CBOPRODUCTO.Text) linea.SubItems.Add(TXTPRECIO.Text) linea.SubItems.Add(TXTCANTIDAD.Text) linea.SubItems.Add(TXTCANTIDAD.Text * TXTPRECIO.Text) ROYER TUESTA SALAS Página 64
  66. 66. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 total = total + subtotal TXTSUBTOTAL.Text = total EndSub PrivateSub CBOPRODUCTO_SelectedIndexChanged1(ByVal sender AsObject, ByVal e As System.EventArgs) Handles CBOPRODUCTO.SelectedIndexChanged SelectCase CBOPRODUCTO.Text.Substring(0, 1) Case"a" TXTPRECIO.Text = 500 Case"b" TXTPRECIO.Text = 700 Case"c" TXTPRECIO.Text = 400 Case"d" TXTPRECIO.Text = 100 Case"e" TXTPRECIO.Text = 150 Case"f" TXTPRECIO.Text = 200 Case"g" TXTPRECIO.Text = 250 Case"h" TXTPRECIO.Text = 300 Case"i" TXTPRECIO.Text = 500 Case"j" TXTPRECIO.Text = 750 Case"k" TXTPRECIO.Text = 600 Case"l" TXTPRECIO.Text = 800 Case"m" TXTPRECIO.Text = 125 Case"n" TXTPRECIO.Text = 150 EndSelect TXTCANTIDAD.Focus() EndSub ROYER TUESTA SALAS Página 65
  67. 67. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 PrivateSub BTNNUEVO_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BTNNUEVO.Click CBOPRODUCTO.Text = "" TXTPRECIO.Text = "" TXTCANTIDAD.Text = "" TXTTOTAL.Text = "" CBOPRODUCTO.Focus() EndSub EndClass ROYER TUESTA SALAS Página 66
  68. 68. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 PublicClass Form1 Dim d AsSingle PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click d = txtDin.Text If chkcompra.Checked = TrueThen TextBox2.Text = d / 2.78 TextBox2.Text = FormatCurrency(TextBox2.Text) Label4.Text = "Ud. a cambiado a Dolares" EndIf If chkventa.Checked = TrueThen TextBox2.Text = d * 2.8 TextBox2.Text = FormatCurrency(TextBox2.Text) Label4.Text = "Ud. a cambiado a Soles" EndIf EndSub PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click txtDin.Text = "" TextBox2.Text = "" chkventa.Checked = False chkcompra.Checked = False txtDin.Focus() EndSub PrivateSub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Me.Close() End Sub ROYER TUESTA SALAS Página 67
  69. 69. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 PublicClass Form2 Dim a, a1, a2 AsString Dim b, b1, b2 AsString Dim c, c1, c2 AsString Dim d, d1, d2 AsString Dim mayor AsInteger PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If TextBox4.Text = ""Then a = TextBox1.Text b = TextBox2.Text c = Val(TextBox3.Text) TextBox4.Text = a TextBox5.Text = b TextBox6.Text = c d = Val(TextBox6.Text) TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox9.Text = "" TextBox1.Focus() EndIf ROYER TUESTA SALAS Página 68
  70. 70. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 If TextBox7.Text = ""Then a1 = TextBox1.Text b1 = TextBox2.Text c1 = Val(TextBox3.Text) TextBox7.Text = a1 TextBox8.Text = b1 TextBox9.Text = c1 d1 = Val(TextBox9.Text) TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox12.Text = "" TextBox1.Focus() EndIf If TextBox10.Text = ""Then a2 = TextBox1.Text b2 = TextBox2.Text c2 = Val(TextBox3.Text) TextBox10.Text = a2 TextBox11.Text = b2 TextBox12.Text = c2 d2 = Val(TextBox12.Text) TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox1.Focus() EndIf EndSub PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click If d > d1 Then ROYER TUESTA SALAS Página 69
  71. 71. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 mayor = d MsgBox(b + " Es mayor") If d2 > mayor Then mayor = d2 MsgBox(b2 + " Es mayor") Else MsgBox(b + " Es mayor") EndIf Else If d2 > mayor Then mayor = d2 MsgBox(b2 + " Es mayor") Else mayor = d1 MsgBox(b1 + " Es mayor") EndIf EndIf EndSub PrivateSub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Me.Close() EndSub PrivateSub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" TextBox5.Text = "" TextBox6.Text = "" TextBox7.Text = "" TextBox8.Text = "" ROYER TUESTA SALAS Página 70
  72. 72. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 TextBox9.Text = "" TextBox10.Text = "" TextBox11.Text = "" TextBox12.Text = "" TextBox1.Focus() EndSub PrivateSub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click Form2.ActiveForm.Hide() Form1.Show() EndSub PrivateSub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click Form2.ActiveForm.Hide() Form3.Show() EndSub EndClass ROYER TUESTA SALAS Página 71
  73. 73. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 ROYER TUESTA SALAS Página 72
  74. 74. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 PublicClass Form3 Dim s, sn, sa, bon AsSingle Dim afp, ipss AsSingle Dim a AsInteger PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click s = Val(TextBox1.Text) a = Val(TextBox2.Text) If ((s > 500) And (a >= 10)) Then bon = s * 0.2 If a < 10 Then bon = s * 0.05 EndIf Else s = Val(TextBox1.Text) EndIf sa = s + bon afp = s * 0.1 ipss = s * 0.08 sn = sa - afp – ipss TextBox3.Text = sn TextBox4.Text = afp TextBox5.Text = ipss TextBox6.Text = sa sa = 0 afp = 0 ipss = 0 sn = 0 bon = 0 EndSub PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ROYER TUESTA SALAS Página 73
  75. 75. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" TextBox5.Text = "" TextBox6.Text = "" TextBox1.Focus() EndSub PrivateSub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Me.Close() EndSub ROYER TUESTA SALAS Página 74
  76. 76. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 INCORPORAR DATOS DE OTROS APLICACIONES AL SISTEMA Primero llevamos la información de Excel hacia Access: Luego nos aparece una ventana para poder buscar nuestro archivo de base de datos que deseamos y buscamos y le damos seleccionar y abrir: ROYER TUESTA SALAS Página 75
  77. 77. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 Luego nos va a mostrar las tablas que contiene nuestra base de datos de Access, y después seleccionaos la tabla que deseamos y le damos clic Y finalmente nos va a mostrar el resultado de la tabla de Access: ROYER TUESTA SALAS Página 76
  78. 78. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 Y una vez tenido los resultados de la tabla de Access nos vamos a la función actualizar, luego a propiedades, esta función me va a permitir actualizar mis datos de Excel, observa las siguientes imágenes que te voy a presentar: ROYER TUESTA SALAS Página 77
  79. 79. EJERCICIOS RESUELTOS EN VISUAL BASIC 2010 Y luego nos aparece esta siguiente ventana: Y activamos este checkbox que muestra la imagen y le damos a cuantos segundos quieres que se actualice tu Excel: ROYER TUESTA SALAS Página 78

×