manual visual basic intermedio
TRANSCRIPT
Capítulo 1: Ejercicio1: Aprende a SumarEnlaces patrocinadosImpresoras económicas HPAverigua qué impresora HP es la ideal para tu empresa.www.hp.com/pe/microempresa
Cursos Dexeus. On line Formación virtual en Ginecología Fundación Dexeus Salud de la Mujerwww.dexeus.comEnlaces patrocinados
Crea un formulario con cinco etiquetas, una caja de texto, tres botones, dos imágenes y tres líneas. Modifica las propiedades de las etiquetas de las cantidades y la de la palabra de resultado como sigue: BackColor blanco y Border Style 1-Fixed Single. Usa Font y ForeColor para el tamaño y color del contenido y Alignment 2-Center
En Word crea las caritas y colócalas dentro de los cuadros de imágenes con su propiedad Stretch en True, las líneas hazlas más gruesas en BorderWidth 3 y BorderColor azul.
Vamos a crear un procedimiento para generar al azar los números:
Haz doble clic en el formulario. Haz clic en Tools (Herramientas)/Add Procedure (Agregar Procedimiento). En Add Procedure escribe el nombre del procedimiento, en este caso Azar y haz clic en Aceptar. Ahora escribe el código:
Public Sub azar()
n1 = Int(Rnd * 10) + 1
n2 = Int(Rnd * 10) + 1
Label1.Caption = n1
Label2.Caption = n2
End Sub
Haz doble clic en el formulario y escribe el siguiente código:
Private Sub Form_Load()
Randomize
Call azar
Image1.Visible = False
Image2.Visible = False
End Sub
El botón Otra Suma
Private Sub Command1_Click()
Call azar
Text1.Text = ""
Label3.Caption = ""
Image1.Visible = False
Image2.Visible = False
End Sub
El botón Revisar
Private Sub Command2_Click()
If Val(Text1) = Val(Label1) + Val(Label2) Then
Label3.Caption = "Bien"
Image1.Visible = True
Else
Label3.Caption = "Mal"
Image1.Visible = False
Image2.Visible = True
End If
End Sub
El botón Salir
Private Sub Command3_Click()
Unload Me
End
End Sub
Capítulo 2: Ejercicio 2: Ordenar los NúmerosEnlaces patrocinadosSistema RRHH para HotelesSueldos, Administracion, Asistencia Capacitación. Evaluaciónwww.payroll.com.ar
Crea un formulario con nueve etiquetas, dos de ellas serán las instrucciones y a las que contendrán los números (seis) cámbiales su Propiedad Alignment a 2-Center, BackColor blanco, BorderStyle a 1-Fixed Single y tres botones, ahora
Repetro - Databras Regime Especial Aduaneiro Repetro Databraswww.repetro.comEnlaces patrocinados
Introduce las siguientes declaraciones
Haz doble clic en el formulario En la caja de combo de la esquina superior izquierda selecciona (General) Y escribe: Dim n1, n2, n3 As Integer (presiona Enter al terminar)
Ahora crea un procedimiento:
Haz doble clic en el formulario. Haz clic en Herramientas (Tools)/Agregar Procedimiento (Add Procedure). En Agregar Procedimiento escribe el nombre del Procedimiento (en este caso azar) y haz clic en Aceptar. Ahora escribe el siguiente código:
Public Sub azar()
n1 = Int(Rnd * 10) + 1
n2 = Int(Rnd * 10) + 1
n3 = Int(Rnd * 10) + 1
If n1 <> n2 And n2 <> n3 And n1 <> n3 Then
Label1.Caption = n1
Label2.Caption = n2
Label3.Caption = n3
Else
Exit Sub
End If
End Sub
La etiqueta 4
Private Sub Label4_DragDrop(Source As Control, X As Single, Y As Single)
Label4.Caption = Source
Source.Visible = False
End Sub
La etiqueta 5
Private Sub Label5_DragDrop(Source As Control, X As Single, Y As Single)
Label5.Caption = Source
Source.Visible = False
End Sub
La etiqueta 6
Private Sub Label6_DragDrop(Source As Control, X As Single, Y As Single)
Label6.Caption = Source
Source.Visible = False
End Sub
El botón Iniciar
Private Sub Command1_Click()
Label4.Caption = ""
Label5.Caption = ""
Label6.Caption = ""
Label7.Caption = ""
Label1.Visible = True
Label2.Visible = True
Label3.Visible = True
Call azar
End Sub
El botón Resultado
Private Sub Command2_Click()
If Val(Label4.Caption) < Val(Label5.Caption) And Val(Label5.Caption) < Val(Label6.Caption) Then
Label7.Caption = "Bien"
Else
Label7.Caption = "Mal"
End If
End Sub
El botón Salir
Private Sub Command3_Click()
Unload Me
End
End Sub
El formulario
Private Sub Form_Load()
Randomize
Call azar
End Sub
Capítulo 3: Ejercicio 3: Calcular la edadEnlaces patrocinadosAsistencia por Biometriacontrol de asistencia por biometria computarizadawww.scimic.net/productos.htm
Crea un formulario con dos etiquetas, dos cajas de texto y tres botones, escribe el siguiente código:
El botón Calcular la Edad
Private Sub Command1_Click()
Dim fecnac As Date, edad As Integer
fecnac = CDate(Text1)
edad = CInt((Date - fecnac) / 365)
Text2 = Str(edad) & " años"
End Sub
El botón Nuevo Cálculo
Private Sub Command2_Click()
Text1 = ""
Text2 = ""
Text1.SetFocus
End Sub
El botón Salir
Private Sub Command3_Click()
Unload Me
End
End Sub
Capítulo 4: Ejercicio 4: Cálculo de VentasEnlaces patrocinadosSoluciones IBMSistemas Inteligentes para Empresas Inteligentes ¡Aquí!www.IBM.com
Impresoras Zebra Código de Barras y RFID Transferencia Térmica o Directawww.lineadatascan.comEnlaces patrocinados
Crea un formulario con ocho etiquetas, ocho cajas de texto, un control Microsoft Hierarchical FlexGrid (haz clic con el botón derecho del ratón sobre la caja de herramientas y haz clic en Componentes, selecciona la casilla Microsoft Hierarchical FlexGrid Control 6.0 y haz clic en Aceptar) tres botones y escribe el siguiente código:
Doble clic sobre el formulario
Private Sub Form_Load()
grdmenu.Cols = 2
grdmenu.Rows = 8
grdmenu.FixedCols = 0
grdmenu.FixedRows = 1
grdmenu.TextArray(0) = "Menú"
grdmenu.TextArray(1) = "Precio"
grdmenu.TextArray(2) = "Burrito"
grdmenu.TextArray(3) = "9.50"
grdmenu.TextArray(4) = "Burger"
grdmenu.TextArray(5) = "12.75"
grdmenu.TextArray(6) = "Torta"
grdmenu.TextArray(7) = "8.25"
grdmenu.TextArray(8) = "Refresco"
grdmenu.TextArray(9) = "4.00"
grdmenu.TextArray(10) = "Cerveza"
grdmenu.TextArray(11) = "15.60"
grdmenu.TextArray(12) = "Ensalada"
grdmenu.TextArray(13) = "14.45"
grdmenu.TextArray(14) = "Hot Dog"
grdmenu.TextArray(15) = "6.90"
End Sub
El botón Aceptar
Private Sub Command1_Click()
Dim burrito As Integer, burger As Integer
Dim torta As Integer, refresco As Integer
Dim cerveza As Integer, ensalada As Integer
Dim hotdog As Integer, ventatotal As Double
burrito = Val(Text1)
burger = Val(Text2)
torta = Val(Text3)
refresco = Val(Text4)
cerveza = Val(Text5)
ensalada = Val(Text6)
hotdog = Val(Text7)
ventatotal = burrito * 9.5 + burger * 12.75 + torta * 8.25 + refresco * 4.60 + cerveza * 15.6 + ensalada * 14.45 + hotdog * 6.9
Text8 = Str(ventatotal)
End Sub
El botón Limpiar
Private Sub Command2_Click()
Text1 = "": Text2 = ""
Text3 = "": Text4 = ""
Text5 = "": Text6 = ""
Text7 = "": Text8 = ""
text9 = "": Text1.SetFocus
End Sub
El botón Salir
Private Sub Command3_Click()
Unload Me
End
End Sub
Capítulo 5: Ejercicio 5: Fecha EscritaEnlaces patrocinadosDescarga Google ChromeEs gratis y se instala en segundos Más velocidad en Internet. Ingresa.www.Google.com/Chrome
Coaching Ontológico 2012 Coaching, Liderazgo e Inteligencia Emocional.Virtual.Inscripc abiertawww.cocrear.com.arEnlaces patrocinados
Crea un formulario con cinco etiquetas, tres cajas de texto, un marco, tres botones y escribe el siguiente código:
El botón Convertir
Private Sub Command1_Click()
Dim cadmes As String, mes As Integer
mes = Val(Text2)
Select Case mes
Case 1: cadmes = "Enero"
Case 2: cadmes = "Febrero"
Case 3: cadmes = "Marzo"
Case 4: cadmes = "Abril"
Case 5: cadmes = "Mayo"
Case 6: cadmes = "Junio"
Case 7: cadmes = "Julio"
Case 8: cadmes = "Agosto"
Case 9: cadmes = "Septiembre"
Case 10: cadmes = "Octubre"
Case 11: cadmes = "Noviembre"
Case 12: cadmes = "Diciembre"
Case Else
MsgBox "Revísalos Por Favor", vbCritical, "Hay un Error en los Datos...!!!"
Call Command2_Click
Exit Sub
End Select
Label4 = Text1 & " de " & cadmes & " de " & Text3
End Sub
El botón Limpiar
Private Sub Command2_Click()
Text1 = ""
Text2 = ""
Text3 = ""
Text1.SetFocus
End Sub
El botón Salir
Private Sub Command3_Click()
If MsgBox("¿Ya Quieres Salir del Programa?", vbQuestion + vbYesNo, "Tengo una Pregunta para Ti") = vbYes Then
End
Else: Call Command2_Click
End If
End Sub
Capítulo 6: Ejercicio 6: Análisis NuméricoEnlaces patrocinadosSistemas Inteligentes IBMDescubra Las Soluciones de IBM Rentabilice Su Empresa ¡Aquí!www.IBM.com
¿Quieres hablar francés? Comienza ya mismo y gratis con nuestro divertido sitio webwww.tv5.org/premiereclasseEnlaces patrocinados
Crea un formulario con cuatro marcos, siete etiquetas, ocho cajas de texto, tres botones y escribe el siguiente código:
El botón Análisis
Private Sub Command1_Click()
If IsNumeric(Text1) Then
Dim s As Integer, si As Integer, sp As Integer
Dim may As Integer, min As Integer
Dim cad As String
Dim i As Integer, j As Integer
n = CLng(Text1)
m = CLng(Text1)
cad = ""
i = 0
j = 1
s = sp = si = 0
For j = 1 To n
If (n Mod j = 0) Then
cad = cad & j & vbCrLf
End If
Next j
While (n > 0)
If ((n Mod 10) Mod 2) = 0 Then
sp = sp + (n Mod 10)
Else
si = si + (n Mod 10)
End If
s = s + (n Mod 10)
n = n \ 10
i = i + 1
Wend
may = Mid(Text1, 1, 1)
men = may
While (m > o)
If may < (m Mod 10) Then
may = m Mod 10
End If
If men > (m Mod 10) Then
men = m Mod 10
End If
m = m \ 10
Wend
Text2 = Str(i)
Text3 = Str(si)
Text4 = Str(sp)
Text5 = Str(s)
Text6 = Str(may)
Text7 = Str(men)
Text8 = cad
Else
MsgBox "Debes Introducir un Número, El que Quieras pero Introduce Un Número", vbCritical, "Aviso Importante"
Text1.SetFocus
End If
End Sub
El botón Otro Número
Private Sub Command2_Click()
Text1 = "": Text2 = ""
Text3 = "": Text4 = ""
Text5 = "": Text6 = ""
Text7 = "": Text8 = ""
Text1.SetFocus
End Sub
El botón Salir
Private Sub Command3_Click()
If MsgBox("¿Deseas Cerrar el Programa?", vbQuestion + vbYesNo, "Aviso Antes de Cerrar el Programa") = vbYes Then
End
Else
Cancel = True
Text1.SetFocus
End If
End Sub
Capítulo 7: Ejercicio 7: Lista de NúmerosEnlaces patrocinadosAsistencia de PersonalControl de accesos por biometria huella digital, facialwww.scimic.net/productos.htm
Impresoras Zebra Código de Barras y RFID Transferencia Térmica o Directawww.lineadatascan.comEnlaces patrocinados
Crea un formulario con tres marcos, una caja de texto, dos botones de opción, una caja de lista, cuatro botones y escribe el siguiente código:
Haz doble clic en el formulario y escribe:
Private Sub Form_Unload(Cancel As Integer)
If MsgBox("¿Cerramos el Programa?", vbQuestion + vbYesNo, "¿Ya nos Vamos?") = vbYes Then
End
Else: Cancel = True: Text1.SetFocus
End If
End Sub
El botón Agregar
Private Sub Command1_Click()
If IsNumeric(Text1.Text) Then
List1.AddItem Text1.Text
Text1.Text = ""
Text1.SetFocus
Else
MsgBox "Introduce un Número", vbCritical, "Por Favor"
Text1.SelStart = 0
Text1.SelLength = Len(Text1.Text)
Text1.SetFocus
End If
End Sub
El botón Ordenar
Private Sub Command2_Click()
Dim i As Integer, j As Integer, t As Integer, n As Integer
Dim a() As Integer
n = List1.ListCount
ReDim a(n)
For i = 0 To n - 1
a(i) = List1.List(i)
Next i
If Option1.Value Then
For i = 0 To n - 2
For j = i + 1 To n - 1
If a(i) > a(j) Then
t = a(i)
a(i) = a(j)
a(j) = t
End If
Next j
Next i
End If
Text1.SetFocus
If Option2.Value Then
For i = 0 To n - 2
For j = i + 1 To n - 1
If a(i) < a(j) Then
t = a(i)
a(i) = a(j)
a(j) = t
End If
Next j
Next i
End If
List1.Clear
For i = 0 To n - 1
List1.List(i) = a(i)
Next i
Text1.SetFocus
End Sub
El botón Lista Nueva
Private Sub Command4_Click()
Text1 = ""
List1.Clear
Text1.SetFocus
End Sub
El botón Salir
Private Sub Command3_Click()
If MsgBox("¿Seguro que Quieres Cerrar el Programa?", vbQuestion + vbYesNo, "¿Ya es Hora de Irnos?") = vbYes Then
End
Else: Cancel = True: Text1.SetFocus
End If
End Sub
Capítulo 8: Ejercicio 8: Registro de CursosEnlaces patrocinadosClub ResellersConozca los Beneficios de IBM. Intel Partner. Inscribase!Clubresellersibm.com/pe
KEL Ediciones S.A. Books in English for Everyone Venta On - Linewww.kelediciones.comEnlaces patrocinados
Crea un formulario con cuatro marcos, seis etiquetas, cinco cajas de texto, un cuadro combinado, dos cajas de lista, cuatro botones y escribe el siguiente código:
Private Sub Form_Load()
List1.AddItem "Intro. a Sistemas"
List1.AddItem "Windows"
List1.AddItem "MS Word"
List1.AddItem "MS Excel"
List1.AddItem "MS PowerPoint"
List1.AddItem "MS Access"
List1.AddItem "Soporte Técnico"
List1.AddItem "Redes"
List1.AddItem "MS Visual Basic"
List1.AddItem "Internet"
List2.AddItem "Chihuahua"
List2.AddItem "Campeche"
List2.AddItem "Veracruz"
List2.AddItem "Colima"
List2.AddItem "Yucatán"
List2.AddItem "Sonora"
List2.AddItem "Sinaloa"
List2.AddItem "Puebla"
List2.AddItem "Tabasco"
List2.AddItem "Zacatecas"
Combo1.AddItem "Masculino"
Combo1.AddItem "Femenino"
End Sub
Private Sub Form_Unload(Cancel As Integer)
If MsgBox("¿Estás Seguro de Querer Cerrar el Programa?", vbQuestion + vbYesNo, "¿Oye qué pasa contigo?") = vbYes Then
End
Else
Cancel = True
End If
End Sub
Private Sub List1_Click()
Text1 = List1
End Sub
Private Sub List2_Click()
Text5 = List2
End Sub
El botón Guardar
Private Sub Command1_Click()
List1.Enabled = False
List2.Enabled = False
Text1.Locked = True
Text2.Locked = True
Combo1.Locked = True
Text4.Locked = True
Text5.Locked = True
MsgBox "Este Alumno ha sido Matriculado", vbInformation, "Mensaje Importante"
End Sub
El botón Limpiar
Private Sub Command2_Click()
List1.Enabled = True
List2.Enabled = True
Text1.Locked = False
Text2.Locked = False
Text3.Locked = False
Combo1.Locked = False
Text4.Locked = False
Text5.Locked = False
Text1 = ""
Text2 = ""
Text3 = ""
Combo1 = ""
Text4 = ""
Text5 = ""
Text1.SetFocus
End Sub
El botón Cancelar
Private Sub Command3_Click()
If MsgBox("Deseas Cancelar Algún Dato?", vbQuestion + vbYesNo, "Aviso Muy Importante") = vbYes Then
List1.Enabled = True
List2.Enabled = True
Text1.Locked = False
Text2.Locked = False
Text3.Locked = False
Combo1.Locked = False
Text4.Locked = False
Text5.Locked = False
End If
End Sub
El botón Salir
Private Sub Command4_Click()
Unload Me
End
End Sub
Capítulo 9: Ejerciocio 9: PalíndromosEnlaces patrocinados אישית בתפיסה גיור , עמי
עכשיו הכנסו. כשר גיור על המידע כל וביחידים בכיתות יהדות אולפני !www.project-ami.org
Crea un formulario con tres etiquetas, dos cajas de texto, tres botones y escribe el siguiente código:
Function cadinvertida(cadena As String) As String
Dim invertida() As String * 1
Dim i As Integer
Dim j As Integer
n = Len(cadena)
ReDim invertida(n)
For i = 1 To n
invertida(i - 1) = Mid(cadena, i, 1)
Next i
For j = (n - 1) To 0 Step -1
cadinvertida = cadinvertida & invertida(j)
Next j
End Function
El botón Invertir
Private Sub Command1_Click()
Text2 = cadinvertida(Text1)
End Sub
El botón Limpiar
Private Sub Command2_Click()
Text1 = ""
Text2 = ""
Text1.SetFocus
End Sub
El botón Salir
Private Sub Command3_Click()
Unload Me
End
End Sub
Capítulo 10: Ejercicio 10: Inter Compras NetEnlaces patrocinadosClub ResellersConozca los Beneficios de IBM. Intel Partner. Inscribase!Clubresellersibm.com/pe
Crea un formulario con siete etiquetas, cinco cuadros image, un botón y escribe el siguiente código:
Dim total As Double
Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
Source.Move X, Y
End Sub
El botón Cuenta Nueva
Private Sub Command1_Click()
Label7 = ""
total = o
End Sub
Private Sub Image5_DragDrop(Source As Control, X As Single, Y As Single)
If Source = Image1 Then
total = total + 250#
ElseIf Source = Image2 Then
total = total + 375#
ElseIf Source = Image3 Then
total = total + 400#
ElseIf Source = Image4 Then
total = total + 500#
End If
Label7 = "$" & total & ".00"
End Sub
Capítulo 11: Ejercicio 11: CalificacionesEnlaces patrocinadosImpresoras para empresas¿Tienes la impresora HP ideal para tu negocio? Averigualo ahora!www.hp.com/pe/microempresa
Curso de Cierre de Ventas Con Metodologías de Vanguardia Instructores de Talla Internacionalwww.trainingandconference.netEnlaces patrocinados
Crea un formulario con ocho etiquetas, nueve cajas de texto, tres botones ye escribe el siguiente código:
El botón Salir
Private Sub Command3_Click()
Unload Me
End
End Sub
El botón Limpiar
Private Sub Command2_Click()
Text1 = ""
Text2 = ""
Text3 = ""
Text4 = ""
Text5 = ""
Text6 = ""
Text7 = ""
Text8 = ""
Text9 = ""
Text1.SetFocus
End Sub
El botón Prom. Gral. Redondeado
Private Sub Command1_Click()
Dim n1 As Double, n2 As Double, n3 As Double, n4 As Double, n5 As Double, n6 As Double
Dim promedio As Integer
n1 = Val(Text2): n2 = Val(Text3)
n3 = Val(Text4): n4 = Val(Text5)
n5 = Val(Text6): n6 = Val(Text7)
promedio = ((n1 + n2 + n3 + n4 + n5 + n6) / 6)
Text8 = Str(promedio)
If promedio >= 9.5 Then
Text9 = "Excelente"
End If
If promedio >= 9 And promedio < 9.5 Then
Text9 = "Muy Bien"
End If
If promedio >= 8.5 And promedio < 9 Then
Text9 = "Bien"
End If
If promedio >= 8 And promedio < 8.5 Then
Text9 = "Regular"
End If
If promedio < 8 Then
Text9 = "Mal"
End If
End Sub
Capítulo 12: Ejercicio 12: ImpresiónEnlaces patrocinadosImpresoras ZebraCódigo de Barras y RFID Transferencia Térmica o Directawww.lineadatascan.com
Coaching Ontológico 2012 Coaching, Liderazgo e Inteligencia Emocional.Virtual.Inscripc abiertawww.cocrear.com.arEnlaces patrocinados
Crea un formulario con seis etiquetas, seis cajas de texto, dos botones y escribe el siguiente código:
El botón Limpiar
Private Sub Command2_Click()
Text1 = ""
Text2 = ""
Text3 = ""
Text4 = ""
Text5 = ""
Text6 = ""
Text1.SetFocus
End Sub
El botón Imprimir
Private Sub Command1_Click()
Printer.Orientation = 1
Printer.FontSize = 12
Printer.Print
Printer.Print
Printer.Print
Printer.Print Tab(15); Label1.Caption; Tab(30); Text1.Text
Printer.Print
Printer.Print
Printer.Print Tab(15); Label2.Caption; Tab(30); Text2.Text
Printer.Print
Printer.Print
Printer.Print Tab(15); Label3.Caption; Tab(30); Text3.Text
Printer.Print
Printer.Print
Printer.Print Tab(15); Label4.Caption; Tab(30); Text4.Text
Printer.Print
Printer.Print
Printer.Print Tab(15); Label5.Caption; Tab(30); Text5.Text
Printer.Print
Printer.Print
Printer.Print Tab(15); Label6.Caption; Tab(30); Text6.Text
Printer.EndDoc
End Sub