jueves, 2 de febrero de 2017

Ejercicios de Visual Basic 7

Realizar un programa para obtener serie de numeros y hallar la suma y promedio de esta serie de numeros

1. Insertamos los objetos con sus respectivos nombres
OBJETO
NOMBRE
CAPTION
Form
frmPrincipal
SERIE
Label
lblCantidad
CANTIDAD
Label
lblSuma
SUMA
Label
lblNumero
NUMERO
Label
lblPromedio
PROMEDIO
TextBox
txtSuma
TextBox
txtCantidad
TextBox
txtNumero
TextBox
txtPromedio
CommandButton
cmdGenerar
GENERAR
CommandButton
cmdLimpiar
LIMPIAR
EN EL PROGRAMA DEBE VISUALIZARSE ASI:



2. Colocamos el siguiente codigo 


Option Explicit
Dim gen, numero, cantidad, suma, promedio, i As Integer
Private Sub cmdGenerar_Click()
numero = Val(Me.txtNumero.Text)
cantidad = Val(Me.txtCantidad.Text)
For i = 1 To cantidad
gen = gen + numero
Me.lstSerie.AddItem (gen)
suma = suma + gen
promedio = suma / cantidad
Me.txtPromedio.Text = promedio
Me.txtSuma.Text = suma
Next
End Sub


Private Sub cmdLimpiar_Click()
Me.txtPromedio.Text = ""
Me.txtSuma.Text = ""
Me.txtCantidad.Text = ""
Me.txtNumero.Text = ""
Me.lstSerie.Clear
gen = 0
suma = 0
promedio = 0

End Sub



EN EL PROGRAMA VISUALIZAMOS ASI






UNA VEZ TERMINADO PONEMOS EJECUTAR






Y  de este modo hemos terminado con este ejercicio

No hay comentarios:

Publicar un comentario