You are on page 1of 11

APUNTES

'Comisión de sus Ventas'


Sub Aumento()
Dim Sueldo_Base As Currency
Dim Porcen_Com As Double
Dim Venta_1 As Currency
Dim Venta_2 As Currency
Dim Venta_3 As Currency
Dim Comision As Double

Sueldo_Base = 0#
Comision = 0
Porcen_Com = 0.1
Venta_1 = 0#
Venta_2 = 0#
Venta_3 = 0#

Sueldo_Base = InputBox("Ingreso del Sueldo Base: ", "Ingrese sueldo base:")


Venta_1 = InputBox("Venta Uno: ", "Ingrese Valor Venta 1:")
Venta_2 = InputBox("Venta Dos: ", "Ingrese Valor Venta 2:")
Venta_3 = InputBox("Venta Tres: ", "Ingrese Valor Venta 3:")
'Proceso
Comision = (Venta_1 + Venta_2 + Venta_3) * Porcen_Com
Sueldo_Total = Sueldo_Base + Comision
Range("A2").Value = Sueldo_Base
Range("B2").Value = Porcen_Com
Range("C2").Value = Venta_1
Range("D2").Value = Venta_2
Range("E2").Value = Venta_3
Range("F2").Value = Sueldo_Total
End Sub

' Descuento por compra


Sub desc_compra()
'Declaración variables
Dim valor_art1 As Currency
Dim valor_art2 As Currency
Dim valor_art3 As Currency
Dim total_compra As Currency
Dim descuento As Double
Dim r, d, e As Range
'Definición Moneda y Constante
valor_art1 = 0#
valor_art2 = 0#
valor_art3 = 0#
total_compra = 0#
porcen_desc = 0.15
'Captura Datos
valor_art1 = InputBox("Valor en Q. del Artículo 1", "Ingrese Valor 1:")
valor_art2 = InputBox("Valor en Q. del Artículo 2", "Ingrese Valor 2:")
valor_art3 = InputBox("Valor en Q. del Artículo 3", "Ingrese Valor 3:")

'Operacion - Proceso
descuento = (valor_art1 + valor_art2 + valor_art3) * porcen_desc
total_compra = (valor_art1 + valor_art2 + valor_art3) - descuento

'Cod Fuente para Escribir Texto con Negrita en cada Celda en el rango
Range("A1").Value = valor_art1
Set r = ActiveSheet.Range("A1:c1")
r.Value = "ARTICULOS COMPRADOS"
r.Font.Bold = True
Set e = ActiveSheet.Range("D1")
e.Value = "DESCUENTO"
e.Font.Bold = True
Set d = ActiveSheet.Range("E1")
d.Value = "TOTAL COMPRAS"
d.Font.Bold = True
'Organización - Ubicación Datos en Celdas
Range("A2").Value = valor_art1
Range("B2").Value = valor_art1
Range("C2").Value = valor_art1
Range("D2").Value = porcen_desc
Range("E2").Value = total_compra
'Cuadro de Diálogo - Terminal
MsgBox prompt:="Gracias por su Compra"
'Fin ejecución
End Sub
'porcentaje de hombres y mujeres
Sub porcentaje()
Dim cant_hombres As Integer
Dim cant_mujeres As Integer
Dim porc_hombres As Double
Dim porc_mujeres As Double
Dim total_integ As Integer
Dim r, s, t, u As Range

cant_hombres = 0
cant_mujeres = 0
total_integ = 0
cant_hombres = InputBox("Número de Hombres?", "Cantidad Hombres")
cant_mujeres = InputBox("Número de Mujeres?", "Cantidad Mujeres")
total_integ = cant_hombres + cant_mujeres
porc_hombres = (100 * cant_hombres) / total_integ
porc_mujeres = (100 * cant_mujeres) / total_integ
'-------------------------------
Set r = ActiveSheet.Range("a1")
r.Value = "CANT HOMBRES"
'-------------------------------
Set s = ActiveSheet.Range("b1")
s.Value = "CANT MUJERES"
'------------------------------
Set t = ActiveSheet.Range("d1")
t.Value = "% HOMBRES"
'------------------------------
Set u = ActiveSheet.Range("e1")
u.Value = "% MUJERES"
Range("a2").Value = cant_hombres
Range("b2").Value = cant_mujeres
Range("c2").Value = total_integ
Range("d2").Value = porc_hombres
Range("e2").Value = porc_mujeres
MsgBox prompt:="Finaliza Programa"
End Sub

'Convertir una distancia en metros a pies y pulgadas.


Sub distancias()
Dim valor_mts As Double
Dim valor_pies As Double
Dim valor_pgl As Double
Const conv_pie As Double = 3.2808
Const conv_pgl As Double = 39.37
Dim caracter As String
Dim x, y As Range
caracter = InputBox("Presione <1> si desea convertir MTS -> Pies / <2> si desea convertir MTS -> Pulgadas",
"METROS")
Select Case caracter
Case 1
valor_mts = InputBox("Ingrese valor MTS", "CONV MTS -> PIES")
valor_pies = valor_mts * conv_pie
Set x = ActiveSheet.Range("a1")
x.Value = "VALOR MTS"
Set y = ActiveSheet.Range("b1")
y.Value = "VALOR PIES"
Range("a2").Value = valor_mts
Range("b2").Value = valor_pies
MsgBox prompt:="Finalizada la conversión", Title:="CONV MTS -> PIES"
Case 2
valor_mts = InputBox("Ingrese valor MTS", "CONV MTS -> PULGADAS")
valor_pgl = valor_mts * conv_pgl
Set x = ActiveSheet.Range("a1")
x.Value = "VALOR MTS"
Set y = ActiveSheet.Range("b1")
y.Value = "VALOR PULG"
Range("a2").Value = valor_mts
Range("b2").Value = valor_pgl
MsgBox prompt:="Finalizada la conversión", Title:="CONV MTS -> PULGADAS"
End Select
End Sub

1. 'Programa que al seleccionar un valor despliega una ocupación


Entrada: valor de tipo entero
Salida: mensaje
Proceso:
Seleccionar Case valor
Case valor = 0
Escribir “ Ingeniero”
Case valor = 1
Escribir “ Ingeniero”
Case valor = 2
Escribir “Doctor”
Case valor = 3
Escribir “Bailarin”
Case valor = 4
Escribir “Presidente”
Case valor = 5
Escribir “Maestro”
Fin selección case

PSEUDOCÓDIGO

a) Inicio.
b) Escribir “Ingrese Valor”
c) Leer valor
d) Proceso
Seleccionar Case valor
Case valor = 0
Escribir “ Ingeniero”
Case valor = 1
Escribir “ Ingeniero”
Case valor = 2
Escribir “Doctor”
Case valor = 3
Escribir “Bailarin”
Case valor = 4
Escribir “Presidente”
Case valor = 5
Escribir “Maestro”
Fin selección case
e) Fin
CODIGO FUENTE
Sub operaciones()
Dim valor As Integer
Dim b, c, d, e As Range
valor = InputBox("ELIJA OPCIÓN:" & vbCrLf & "<0> Ingeniero " & vbCrLf & "<1> Doctor" & vbCrLf & "<2>
Bombero" & vbCrLf & "<3> Bailarin" & vbCrLf & "<4> Presidente" & vbCrLf & "<5> Maestro")
Select Case valor
Case 0
Set b = ActiveSheet.Range("a1")
b.Value = "Valor"
Set c = ActiveSheet.Range("b1")
c.Value = "Profesión"
Set d = ActiveSheet.Range("a2")
d.Value = 0
Set e = ActiveSheet.Range("b2")
e.Value = "Ingeniero "

Case 1
Set b = ActiveSheet.Range("a1")
b.Value = "Valor"
Set c = ActiveSheet.Range("b1")
c.Value = "Profesión"
Set d = ActiveSheet.Range("a2")
d.Value = 1
Set e = ActiveSheet.Range("b2")
e.Value = "Doctor"

Case 2
Set b = ActiveSheet.Range("a1")
b.Value = "Valor"
Set c = ActiveSheet.Range("b1")
c.Value = "Profesión"
Set d = ActiveSheet.Range("a2")
d.Value = 2
Set e = ActiveSheet.Range("b2")
e.Value = "Bombero"
Case 3
Set b = ActiveSheet.Range("a1")
b.Value = "Valor"
Set c = ActiveSheet.Range("b1")
c.Value = "Profesión"
Set d = ActiveSheet.Range("a2")
d.Value = 3
Set e = ActiveSheet.Range("b2")
e.Value = "Bailarin"
Case 4
Set b = ActiveSheet.Range("a1")
b.Value = "Valor"
Set c = ActiveSheet.Range("b1")
c.Value = "Profesión"
Set d = ActiveSheet.Range("a2")
d.Value = 4
Set e = ActiveSheet.Range("b2")
e.Value = "Presidente"
Case 5
Set b = ActiveSheet.Range("a1")
b.Value = "Valor"
Set c = ActiveSheet.Range("b1")
c.Value = "Profesión"
Set d = ActiveSheet.Range("a2")
d.Value = 5
Set e = ActiveSheet.Range("b2")
e.Value = "Maestro"
End Select
End Sub

2. 'El IGSS requiere clasificar a las personas que se jubilaran en el año 2010. Existen tres tipos de jubilaciones: por
edad, por antigüedad joven y por antigüedad adulta. Las personas adscritas a la jubilación por edad deben tener 60
años o más y una antigüedad en su empleo de menos de 25 años. Las personas adscritas a la jubilación por antigüedad
joven deben tener menos de 60 años y una antigüedad en su empleo de 25 años o más. Las personas adscritas a la
jubilación por antigüedad adulta deben tener 60 años o más y una antigüedad en su empleo de 25 años o más.
Entrada:
nombre es de tipo texto (String)
edad, anti es de tipo Númerico Entero (Integer)
Salida:
Mensaje
Proceso:
si (edad >= 60) And (anti < 25) entonces
Escribir: "CLASIFICACIÓN POR EDAD:"
Sino
si (edad < 60) And (anti >= 25) entonces
Escribir: "CLASIFICACIÓN POR Antigüedad Joven:"
sino
si (edad >= 60) And (anti >= 25) entonces
Escribir "CLASIFICACIÓN POR Antigüedad Adulta:"
Fin si
Fin si
Fin si

PSEUDOCÓDIGO
A) Inicio
B) Escribir “Ingrese Nombre del afiliado, edad y Años de Antigüedad
C) Leer nombre, edad, anti
D) Proceso:
si (edad >= 60) And (anti < 25) entonces
Escribir: "CLASIFICACIÓN POR EDAD:"
Sino
si (edad < 60) And (anti >= 25) entonces
Escribir: "CLASIFICACIÓN POR Antigüedad Joven:"
sino
si (edad >= 60) And (anti >= 25) entonces
Escribir "CLASIFICACIÓN POR Antigüedad Adulta:"
Fin si
Fin si
Fin si
E) Fin
CODIGO FUENTE
Sub jubilacion()
Dim nombre As String
Dim edad, anti As Integer
nombre = InputBox("Ingrese Nombre del Afiliado:", "Nombre")
edad = InputBox("Ingrese Edad:", "EDAD")
anti = InputBox("Ingrese Años de antigüedad :", "Antigüedad")
If (edad >= 60) And (anti < 25) Then
MsgBox "CLASIFICACIÓN POR EDAD:" & vbCrLf & vbCrLf & _
"- Jubilación 2010!!!." & vbCrLf & _
vbCrLf _
, vbExclamation + vbOKOnly, _
"Actualización terminada."
Else
If (edad < 60) And (anti >= 25) Then
MsgBox "CLASIFICACIÓN POR Antigüedad Joven:" & vbCrLf & vbCrLf & _
"- Jubilación 2010!!!." & vbCrLf & _
vbCrLf _
, vbExclamation + vbOKOnly, _
"Actualización terminada."
Else
If (edad >= 60) And (anti >= 25) Then
MsgBox "CLASIFICACIÓN POR Antigüedad Adulta:" & vbCrLf & vbCrLf & _
"- Jubilación 2010!!!." & vbCrLf & _
vbCrLf _
, vbExclamation + vbOKOnly, _
"Actualización terminada."
End If
End If
End If
End Sub
3. Un obrero necesita calcular su salario semanal, el cual se obtiene de la sig. manera: Si trabaja 40 horas o menos se
le paga Q25 por hora; Si trabaja más de 40 horas se le paga Q.25 por cada una de las primeras 40 horas y Q.20 por
cada hora extra.
Entrada:
Nombre de tipo String
hora_trab de tipo double
Salida:
Sueldo_sem de tipo double
Proceso:
si (hora_trab <= 40) entonces
sueldo_sem = hora_trab * 25
Escribir “El sueldo semanal es: “,sueldo_sem
//Bifurcación hijo else if
sino (hora_trab > 40) entonces
extra = (hora_trab - 40) * 20
sueldo_sem = (40 * 25) + extra
Escribir “El sueldo semanal es: “,sueldo_sem
PSEUDOCODIGO

A) Inicio.
B) Escribir “Ingrese Nombre y Hora Trabajada”
C) Leer nombre, hora_trab
D) Proceso
si (hora_trab <= 40) entonces
sueldo_sem = hora_trab * 25
Escribir “El sueldo semanal es: “,sueldo_sem
//Bifurcación hijo else if
sino (hora_trab > 40) entonces
extra = (hora_trab - 40) * 20
sueldo_sem = (40 * 25) + extra
Escribir “El sueldo semanal es: “,sueldo_sem
E) fin

CODIGO FUENTE
Sub sueldo_sem()
Dim nombre As String
Dim hora_trab As Double
Dim sueldo_sem As Double
Dim extra As Double
Dim a, b, c, d, e, f As Range
'Inicializar variables
sueldo_sem = 0#
hora_trab = 0
'captura de datos
nombre = InputBox("Ingrese nombre del trabajador", "NOMBRE")
hora_trab = InputBox("Ingrese Horas Trabajadas en la semana", "HORAS LABORADAS")
'proceso
If (hora_trab <= 40) Then
sueldo_sem = hora_trab * 25
'Asignar texto en celda
Set a = ActiveSheet.Range("a1")
a.Value = "TRABAJADOR"
Set b = ActiveSheet.Range("b1")
b.Value = "HORA LAB"
Set c = ActiveSheet.Range("c1")
c.Value = "SUELDO SEM"
'Asignar variables a celdas
Range("a2").Value = nombre
Range("b2").Value = hora_trab
Range("c2").Value = sueldo_sem
'Bifurcación hijo else if
ElseIf (hora_trab > 40) Then
extra = (hora_trab - 40) * 20
sueldo_sem = (40 * 25) + extra
Set a = ActiveSheet.Range("a1")
a.Value = "TRABAJADOR"
Set b = ActiveSheet.Range("b1")
b.Value = "HORA LAB"
Set c = ActiveSheet.Range("c1")
c.Value = "HORAS EXTRAS"
Set d = ActiveSheet.Range("d1")
d.Value = "SUELDO_SEM"

Range("a2").Value = nombre
Range("b2").Value = hora_trab
Range("c2").Value = (hora_trab - 40)
Range("d2").Value = sueldo_sem
End If
End Sub

4. Obtener el perímetro y el Área de las siguientes figuras geométricas, triangulo y rectángulo.


Entrada: b_tr, h_tr, b_rec, a_rec as double
T as string
Salida:
Area_t, per_t, area_rec, perim_rec as double
Proceso:
si (t = "r") entonces
Seleccionar Case t
Case "r"
Escribir: "Seleccione Opciones:" & vbCrLf & "<1> Perímetro " & vbCrLf & "<2> Área"
Leer -> m
Seleccionar Case m
Case 1
Escribir: "Ingrese Base:"
Leer a_rec
Escribir: "Ingrese Altura:"
Leer b_rec
perim_rec = (2 * a_rec) + (2 * b_rec)
Escribir: "Perimetro es",perim_rec
Case 2
Escribir: "Ingrese Base:"
Leer a_rec
Escribir: "Ingrese Altura:"
Leer b_rec
area_rec = (a_rec * b_rec)
Escribir: “Area del rectángulo es:”,area_rec
Fin select
Case "x"
Escribir "Seleccione Opciones:" & vbCrLf & "<1> Perímetro " & vbCrLf & "<2> Área"
Leer n
Seleccionar Case n
Case 1
lados Escribir: "Ingrese Número de Lados de la Figura:"
Leer lados
per_t = (3 * lados)
Escribir: “Figura Isosceles, su perímetro es:", per_t
Case 2
Escribir: "Ingrese Base:"
Leer b_tr
Escribir: "Ingrese Altura:"
Leer h_tr
area_t = (b_tr * h_tr) / 2
Escribir: "Área Triángulo", area_t
Fin select
Fin select
PSEUDOCÓDIGO

A) Inicio.
B) Escribir: "Seleccione Opciones:" & vbCrLf & " Rectángulo" & vbCrLf & " Triángulo"
C) Leer t
si (t = "r") entonces
Seleccionar Case t
Case "r"
Escribir: "Seleccione Opciones:" & vbCrLf & "<1> Perímetro " & vbCrLf & "<2> Área"
Leer -> m
Seleccionar Case m
Case 1
Escribir: "Ingrese Base:"
Leer a_rec
Escribir: "Ingrese Altura:"
Leer b_rec
perim_rec = (2 * a_rec) + (2 * b_rec)
Escribir: "Perimetro es",perim_rec
Case 2
Escribir: "Ingrese Base:"
Leer a_rec
Escribir: "Ingrese Altura:"
Leer b_rec
area_rec = (a_rec * b_rec)
Escribir: “Area del rectángulo es:”,area_rec
Fin select
Case "x"
Escribir "Seleccione Opciones:" & vbCrLf & "<1> Perímetro " & vbCrLf & "<2> Área"
Leer n
Seleccionar Case n
Case 1
lados Escribir: "Ingrese Número de Lados de la Figura:"
Leer lados
per_t = (3 * lados)
Escribir: “Figura Isosceles, su perímetro es:", per_t
Case 2
Escribir: "Ingrese Base:"
Leer b_tr
Escribir: "Ingrese Altura:"
Leer h_tr
area_t = (b_tr * h_tr) / 2
Escribir: "Área Triángulo", area_t
Fin select
Fin select
D) Fin

CODIGO FUENTE

Sub perimetro_ar()
'variables del area de un triangulo
Dim b_tr As Double
Dim h_tr As Double
Dim area_t As Double
'varibles del perimetro de un triangulo
Dim per_t As Double
Dim lados As Double
'variables del perimetro y área de un rectangulo
Dim perim_rec As Double
Dim b_rec As Double
Dim a_rec As Double
Dim area_rec As Double
'********************************************************
'Resto de variables - range, set activesheet, etc...
Dim u, v, w As Range
Dim t As String 'para capturar el dato a elegir para ejecutar acción de perimetro o área de las fig geometricas
Dim m, n As String
'********************************************************
'inicializo variables
MsgBox prompt:="PERÍMETRO Y ÁREA DE FIGURAS GEOMETRICAS", Title:="TRIÁNGULO Y
RECTÁNGULO"
t = InputBox("Seleccione Opciones:" & vbCrLf & " Rectángulo" & vbCrLf & " Triángulo", "FIGURAS
GEOMETRICAS")
'If (t = "r") Then
Select Case t
Case "r"
m = InputBox("Seleccione Opciones:" & vbCrLf & "<1> Perímetro " & vbCrLf & "<2> Área", "Rectángulo")
Select Case m
Case 1
a_rec = InputBox("Ingrese Base:", "Base Rectángulo")
b_rec = InputBox("Ingrese Altura:", "Altura Rectángulo")
perim_rec = (2 * a_rec) + (2 * b_rec)

Set u = ActiveSheet.Range("a1")
u.Value = "Base"
Set v = ActiveSheet.Range("b1")
v.Value = "Altura"
Set w = ActiveSheet.Range("c1")
w.Value = "Perimetro Rect"

Range("a2") = a_rec
Range("a2") = b_rec
Range("a2") = perim_rec
Case 2
a_rec = InputBox("Ingrese Base:", "Base Rectángulo")
b_rec = InputBox("Ingrese Altura:", "Altura Rectángulo")
area_rec = (a_rec * b_rec)

Set u = ActiveSheet.Range("a1")
u.Value = "Base"
Set v = ActiveSheet.Range("b1")
v.Value = "Altura"
Set w = ActiveSheet.Range("c1")
w.Value = "Área Rect"

Range("a2") = a_rec
Range("b2") = b_rec
Range("c2") = area_rec
End Select
Case "x"
n = InputBox("Seleccione Opciones:" & vbCrLf & "<1> Perímetro " & vbCrLf & "<2> Área", "Triángulo")
Select Case n
Case 1
lados = InputBox("Ingrese Número de Lados de la Figura:", "Triángulo")
per_t = (3 * lados)

Set u = ActiveSheet.Range("a1")
u.Value = "Fig"
Set v = ActiveSheet.Range("b1")
v.Value = "Perimetro Triángulo"
Set w = ActiveSheet.Range("c1")
w.Value = " "
Range("a2") = "Isosceles"
Range("b2") = per_t
Range("c2") = " "

Case 2
b_tr = InputBox("Ingrese Base:", "Base Triángulo")
h_tr = InputBox("Ingrese Altura:", "Altura Triángulo")
area_t = (b_tr * h_tr) / 2
Set u = ActiveSheet.Range("a1")
u.Value = "Base"
Set v = ActiveSheet.Range("b1")
v.Value = "Altura"
Set w = ActiveSheet.Range("c1")
w.Value = "Área Triángulo"

Range("a2") = b_tr
Range("b2") = h_tr
Range("c2") = area_t
End Select
End Select
End Sub

Leer 10 números y obtener su cuadrado y cubo.

Variables de Entrada: “ingreso” de tipo single


Variables de Salida: “a” de tipo range
Proceso:
For i=1 a 10, incremento 1
Escribir: “Ingrese número”
Lee ingreso1
Msgbox=”el número ingresado es”,i
Msgbox=”el cuadrado es:”, i ^ 2
Msgbox=”el cuadrado es:”, i ^ 3
Fin for

INICIO
Declaración de Variables (i,ingreso; single), (a de tipo range)
I=0
Ingreso=0
For i=1 a 10, incremento 1
Escribir: “Ingrese número”
Lee ingreso1
Msgbox=”el número ingresado es”,i
Msgbox=”el cuadrado es:”, i ^ 2
Msgbox=”el cuadrado es:”, i ^ 3
Fin for
FIN
CODIGO FUENTE

Sub cuadrado_cubo()
Dim i As Single
Dim a As Range
Dim ingreso As Single
i=0
ingreso = 0
For i = 1 To 10 Step 1
ingreso = InputBox("Ingrese Número:", "Número " & i)
Set a = ActiveSheet.Range("a1")
a.Offset(i, 0).Value = i
a.Offset(i, 1).Value = ingreso
a.Offset(i, 2).Value = ingreso ^ 2
a.Offset(i, 3).Value = ingreso ^ 3
Next i
Range("a1") = "No."
Range("b1") = "VALOR INGRESADO"
Range("c1") = "CUADRADO"
Range("d1") = "CUBO"
End Sub

'promedio de un alumno con 7 calificaciones


Sub promedio()
Dim i As Single
Dim suma As Single
Dim ingreso As Single
Dim contador As Single
Dim promedio As Single
i=0
ingreso = 0
suma = 0
contador = 0
For i = 1 To 7 Step 1
ingreso = InputBox("Ingrese Calificación de Algoritmos:", "Nota " & i)
contador = contador + 1
suma = suma + ingreso
Next i
promedio = suma / contador
Range("a1") = "SUMA"
Range("a2") = suma
Range("b1") = "PROMEDIO"
Range("b2") = Int(promedio) & " " & "pts"

MsgBox prompt:="El promedio es:" & vbCrLf & Int(promedio) & "pts" & vbCrLf & "NOTA: REDONDEADO A
ENTERO", Title:="PROMEDIO DE NOTAS DE ALGORITMOS"
End Sub

You might also like