1. UNIVERSIDAD GERARDO BARRIOS SAN
MIGUEL
ALUMNO:
JOSE ALFREDO CASTRO JOYA
ASIGNATURA:
PROGRAMACION COMPUTACIONAL 1
DOCENTE:
INGENIERA GISELA ESPINOZA
CARRERA:
INGENERIA EN SISTEMAS
CICLO:
02-2016
2. CODIGO DE CLASE
Public Class persona
'declaracion de propiedades
Private codigo As String
Private nombre As String
Private apellido As String
Private sexo As String
Private dirrecion As String
'indica si los datos estan completos
Private datosCompletos As Boolean
'metodos depropiedades
Public Property nombreAlumno() As String
Get
Return nombre
End Get
Set(value As String)
nombre = value
End Set
End Property
Public Property apellidoAlumno() As String
Get
Return apellido
End Get
Set(value As String)
apellido = value
End Set
End Property
Public Property sexoAlumno() As String
Get
Return sexo
End Get
Set(value As String)
sexo = value
End Set
End Property
Public Property dirrecionAlumno() As String
Get
Return dirrecion
End Get
Set(value As String)
dirrecion = value
3. End Set
End Property
Public ReadOnly Property datosAceptados() As Boolean
Get
Return datosCompletos
End Get
End Property
'construtor de la clase
Public Sub New()
datosCompletos = False
'determina si los datos aun no han sido ingresados
End Sub
'determinar si los datos ingresados son correctos
'y asigna los atributos de la clase
Public Sub datosAlumno(ByVal codigoA As String, ByVal nombreA As String, ByVal
apellidoA As String, ByVal sexoA As String, ByVal dirrecionA As String)
datosCompletos = False
'asume que lso datos recibidos son incorrectos
If codigoA.Length = 0 Then
MsgBox("debe generar el codigo del alumno")
Exit Sub
Else
codigo = codigoA
End If
If nombreA.Length = 0 Then
MsgBox("debe scribir el nombre del alumno")
Exit Sub
Else
nombre = nombreA
End If
If apellidoA.Length = 0 Then
MsgBox("Debe escribir el apellido ")
Exit Sub
Else
apellido = apellidoA
End If
If sexoA.Length = 0 Then
MsgBox("escriba el sexo ")
Exit Sub
Else
4. sexo = sexoA
End If
If dirrecionA.Length = 0 Then
MsgBox("Debe ingresar la direccion")
Exit Sub
Else
dirrecion = dirrecionA
End If
If sexoA = "F" Or sexoA = "M" Then
Else
MsgBox("Debe escribir F para femenino o M para masculino")
Exit Sub
End If
End Sub
'funcion para generar el codigo del alumno
Public Function generarCodigo(ByVal nombre As String)
Dim valor1 As String
Dim valor2 As String
Dim numero As Single
valor1 = UCase(Left(nombre, 1))
valor2 = Right(nombre, 2)
numero = Int(Rnd() * 1000) + 65
Return valor1 & numero & valor2
End Function
End Class
CODIGO 2
Public Class Form1
'instanciacion de la clase
Dim alumno As New Alumno
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If txtNombre.Text = "" Then
MsgBox("debe escribir su nombre")
Else
txtcodigo.Text = alumno.generarCodigo(txtNombre.Text)
5. End If
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Me.DataGridView1.Rows.Add(txtNombre.Text, txtApellido.Text, txtSexo.Text,
txtDireccion.Text, TextBox2.Text, TextBox1.Text)
If alumno.datosAceptados Then
MsgBox("alumno " & alumno.nombreAlumno & " registrado")
Else
End If
End Sub
End Class
CODIGO 3
Public Class Form1
Dim alumno As New persona
Private Sub btnAgregar_Click(sender As Object, e As EventArgs) Handles
btnAgregar.Click
alumno.datosAlumno(txtCodigo.Text, txtNombre.Text, txtApellido.Text,
txtSexo.Text, txtDireccion.Text)
If alumno.datosAceptados Then
MsgBox("Alumno" & alumno.nombreAlumno & "Registrado")
Else
End If
If ValidaEMail(txtCorreo.Text) Then
MessageBox.Show("Correo valido")
Else
MessageBox.Show("Correo invalido, revise si lo ha escrito bien")
End If
Me.regis.Rows.Add(txtCodigo.Text, txtNombre.Text, txtApellido.Text, txtSexo.Text,
txtEdad.Text, txtDireccion.Text, txtCorreo.Text)
End Sub
6. Private Function ValidaEMail(ByVal EMail As String) As Boolean
If Not EMail.Contains("@") Then
Return False
End If
Dim SeccionesEMail As String() = EMail.Split(CChar("@"))
If SeccionesEMail.Length <> 2 Then
Return False
End If
If Not SeccionesEMail(1).Contains(".") Or Not SeccionesEMail(1).Length >= 3 Then
Return False
End If
Return True
End Function
Private Sub btnGenerar_Click(sender As Object, e As EventArgs) Handles
btnGenerar.Click
If txtNombre.Text = "" Then
MsgBox("Debe ingresar su nombre")
Else
txtCodigo.Text = alumno.generarCodigo(txtNombre.Text)
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
inciar()
End Sub
Public Sub inciar()
With regis.Columns
.Add("cod", "Codigo")
.Add("nom", "Nombre")
.Add("ape", "Apellido")
.Add("eda", "Edad")
.Add("se", "Sexo")
.Add("dir", "Direccion")
.Add("co", "Correo")
End With
regis.ReadOnly = True
End Sub
End Class