En este ejercicio consiste en que al introducir un número cualquiera preferible de 2 mas cifras salga una serie de analisis como el siguiente diseño:

Para ello debemos realizar la siguiente codificación:
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
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
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
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
Ejericicio 2
En este ejercicio debemos de introducir cierta cantidad de productos que aigamos vendido y debemos hallar el valor total de venta en el dia según el precio de cada producto.

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
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
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
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
Unload Me
End
End Sub
Ejercicio 3
En este ejercicio consiste en matricular a una persona con los siguientes requisitos que se observa en el formulario.

Para ello debemos dar la siguiente codificación:
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
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
End
Else
Cancel = True
End If
End Sub
Private Sub List1_Click()
Text1 = List1
End Sub
Text1 = List1
End Sub
Private Sub List2_Click()
Text5 = List2
End Sub
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
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
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
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
Unload Me
End
End Sub
Ejercicio 4
Este ejercicio consiste en que al arrastrar cada objeto donde la señora de caja debe salir lo que debo pagar.

Para ello debemos dar la siguiente codificación:
En General:
Dim total As Double
Private Sub Form_DragDrop(Source As Control, X As Single, Y As Single)
Source.Move X, Y
End Sub
Source.Move X, Y
End Sub
El botón Cuenta Nueva
Private Sub Command1_Click()
Label7 = ""
total = o
End Sub
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
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
Ejercicio 5
En es te ejerrcicio consiste sacar el promedio general de notas de un alumno y dar un comentario si esta bien o mal.

Para ello dar la siguiente codificación:
El botón Salir:
Private Sub Command3_Click()
Unload Me
End
End Sub
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
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 < text9 = "Muy Bien">= 8.5 And promedio < text9 = "Bien">= 8 And promedio < text9 = "Regular" text9 = "Mal">
Ejercicio 6: Palindromos

Crea un formulario con tres etiquetas, dos cajas de texto, tres botones y escribe el siguiente código:
En General colocamos lo siguiente:
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
Ejercicio7 : Ordena los Números

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) <>
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
Ejercicio 8: Fecha Escrita

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
Ejercicio 9: Aprendiendo a Sumar

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:
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
Ejercicio 10: Impresión

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
1 comentario:
Muchas gracias
Publicar un comentario