Académique Documents
Professionnel Documents
Culture Documents
- 163 -
- 164 -
- 165 -
- 166 -
9. Aparecer lo siguiente
- 167 -
Set(value As String)
End Set
End Property
Public Property Radio() As Single
Get
End Get
Set(value As Single)
End Set
End Property
Public ReadOnly Property Area As Single
Get
End Get
End Property
Protected Overrides Sub Finalize()
End Sub
''' <summary>
''' Calcula El Area
''' </summary>
Function CalcularArea(r1 As Single) As Single
End Function
Public Sub AsignarNombre(Optional Nom1 As String = "Sn")
End Sub
Public Sub MostrarValores()
End Sub
End Class
12. El diagrama de clase seria lo siguiente
- 168 -
- 169 -
- 170 -
15 . El cdigo generado es
Public Class CILINDRO
Private Altura1 As Single
Private Volumen1 As Single
Public Sub New(Optional Nombre2 As String = "SN", Optional r As Single = 10,
Optional h1 As Single = 1)
End Sub
Public Property Altura As Single
Get
End Get
Set(value As Single)
End Set
End Property
Public ReadOnly Property Volumen As Single
Get
End Get
End Property
Public Function CalcularVolumen(v1 As Single) As Single
End Function
Public Sub MostrarValores()
End Sub
End Class
- 171 -
16. Se puede modificar el cdigo por ejemplo la propiedad volumen es de solo lectura
Public ReadOnly Property Volumen As Single
Get
End Get
End Property
17. El diagrama de la clase cilindro de seria lo siguiente
- 172 -
- 173 -
- 174 -
e
23 Con la herramienta de la herencia agrega las clases circulo y al mtodo nombre al
final la estructura debe quedar de la siguiente manera
Para implementar una interfaz trazando una lnea de herencia
1. En el diagrama de clases, muestre la interfaz y la clase que implementar la
interfaz.
2. Trace una lnea de herencia desde la clase a la interfaz.
Y debe aparece lo siguiente
- 175 -
End Interface
25. el Nuevo cdigo de la clase circulo es
- 176 -
- 177 -
End Get
Set(value As Single)
Select Case value
Case Is < 0
RaiseEvent Evento1(value)
Case CSng(value > 0) To 100
Radio1 = value
Case Is > 100
RaiseEvent Evento2(value)
End Select
End Set
End Property
Public ReadOnly Property Area As Single
Get
Area = Area1
End Get
End Property
Protected Overrides Sub Finalize()
Console.WriteLine("objeto destruido")
End Sub
''' <summary>
''' Calcula El Area
''' </summary>
Function CalcularArea(r1 As Single) As Single
Area1 = Math.PI * Math.Pow(r1, 2)
Return Area1
End Function
Public Sub AsignarNombre(Optional Nom1 As String = "Sn")
Nombre1 = Nom1
End Sub
Public Function ObtenerValores() As String
Dim Cadena As String = ""
Area1 = CalcularArea(Radio1)
Cadena = "Nombre =" + Nombre1 + " Radio = " + Str(Radio1) + " Area " +
Str(Area1)
Return Cadena
End Function
End Class
CLASE CILINDRO
Public Class CILINDRO
Inherits CIRCULO
' Implements ICIRCULO
Private Altura1 As Single
Private Volumen1 As Single
Public Sub New(Optional Nombre2 As String = "SN", Optional r As Single = 10,
Optional h1 As Single = 1)
MyBase.New(Nombre2, r)
Altura1 = h1
End Sub
- 178 -
- 179 -
- 180 -
- 181 -
- 182 -
- 183 -
- 184 -
+
Agregue el siguiente codigo al boton propiedades
Private Sub btnPropiedades_Click(sender As Object, e As EventArgs) Handles
btnPropiedades.Click
- 185 -
Dim i As Integer
Dim A(10) As CIRCULO
ListBox1.Items.Clear()
For i = 0 To 9
A(i) = New CIRCULO("Circulo " & i)
A(i).Radio = i * 10
ListBox1.Items.Add("Objeto " & A(i).Nombre)
ListBox1.Items.Add("Radio " & A(i).Radio)
Next
A(0).Radio = Val(Txtradio.Text)
txtArea.Text = A(0).Area
End Sub
ELABORACION DE CONTROL DE USUARIO EN VISUAL ESTUDIO 2012( o
controles personalizados)
Paso 1
Agregue un con control de usuario con
Paso 2
Disee el siguiente formulario
- 186 -
- 187 -
End Select
End Set
End Property
Public ReadOnly Property Area As Single
Get
Area = Area1
End Get
End Property
Function CalcularArea(r1 As Single) As Single
Area1 = Math.PI * Math.Pow(r1, 2)
Return Area1
End Function
Public Sub AsignarNombre(Optional Nom1 As String = "Sn")
Nombre1 = Nom1
End Sub
Private Sub btnCalcular_Click(sender As Object, e As EventArgs) Handles
btnCalcular.Click
If IsNumeric(txtRadio.Text) Then
Radio = txtRadio.Text
Area1 = CalcularArea(Radio)
txtArea.Text = Area1
Else
MsgBox("INGRESE VALORES NUMERICOS")
End If
End Sub
Private Sub UCirculo_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
txtRadio.Text = Radio
End Sub
End Class
Paso 4 . Ejecute la aplicacion
Para crear un control de usuario mediante Visual Basic Express (2012)
1. En el men Archivo, haga clic en Nuevoproyecto.
2. En el panel Plantillas, del cuadro de dilogo Nuevo proyecto, haga clic
en Biblioteca de clases y luego en Aceptar.
3. En el men Proyecto, haga clic en Agregar control de usuario.
4. En el cuadro de dilogo Agregar nuevo elemento, seleccione Control de usuario.
5. En el cuadro Nombre, escriba NamesControl y haga clic en Agregar.
- 188 -
- 189 -
9 Seleccionar y abrir
- 190 -
- 191 -
- 192 -
11. puede ver las propiedades metodos y eventos del objeto usuario1 del tipo circulo
- 193 -
- 194 -
Get
Return R
End Get
End Property
End Class
Cdigo del mdulo
Option Explicit On
Option Strict On
Module Module1
Dim objeto As OPERACION
Sub Main()
objeto = New OPERACION
objeto.Ingresar()
Console.WriteLine(" la suma es {0}", objeto.Sumar())
Console.WriteLine(" la resta es {0}", objeto.Restar())
objeto.Nro1 = 100
objeto.Sumar()
Console.WriteLine(" El resultado es {0}", objeto.Res)
Console.ReadLine()
End Sub
End Module
El objeto llamado Operacin debera tener los siguientes mtodos y propiedades
Solucion
- 195 -
- 196 -
- 197 -
Optional
End Sub
Sub ingresar()
Console.Write(" ingrese nombre")
Nombre = Console.ReadLine
Console.Write(" ingrese DNI")
DNI = Console.ReadLine
End Sub
Sub VerDatos()
Console.WriteLine(" Nombre {0}", Nombre)
Console.WriteLine(" DNI {0}", DNI)
End Sub
End Class
Module Module1
Dim Juan, Pedro, Maria As PERSONA
Sub Main()
Juan = New PERSONA
Pedro = New PERSONA("Pedro Picapiedra")
Maria = New PERSONA(" Maria Parado", 234567)
Juan.VerDatos()
Pedro.VerDatos()
Maria.VerDatos()
Console.ReadLine()
End Sub
End Module
Ejecicio con propiedades
Option Explicit On
Option Strict On
Public Class PERSONA
Protected Nombre1 As String
Protected DNI1 As Integer
Property Nombre() As String
Get
Nombre = Nombre1
End Get
Set(value As String)
Nombre1 = value
End Set
End Property
Property DNI() As Integer
Get
DNI = DNI1
End Get
- 198 -
Set(value As Integer)
DNI1 = value
End Set
End Property
Public Sub New(Optional ByVal nombre1 As String = "sin nombre", _
Optional Dn1 As Integer = 11111)
Nombre = nombre1
DNI1 = Dn1
End Sub
Sub ingresar()
Console.Write(" ingrese nombre")
Nombre = Console.ReadLine
Console.Write(" ingrese DNI")
DNI = CInt(Console.ReadLine)
End Sub
Sub VerDatos()
Console.WriteLine(" Nombre {0}", Nombre)
Console.WriteLine(" DNI {0}", DNI)
End Sub
End Class
Option Explicit On
Option Strict On
Module Module1
Dim Juan, Pedro, Maria As PERSONA
Sub Main()
Juan = New PERSONA
Pedro = New PERSONA("Pedro Picapiedra")
Maria = New PERSONA(" Maria Parado", 234567)
Juan.DNI = 9999
Pedro.VerDatos()
Maria.VerDatos()
Juan.VerDatos()
Console.ReadLine()
End Sub
End Module
CLASES Y OBJETOS CON ARREGLOS
- 199 -
- 200 -
- 201 -
jeto
Module Module1
Sub Main()
Dim i As Integer, np As Integer
Dim n As Integer = 4
Dim A(10) As PERSONA
For i = 0 To n - 1
A(i) = New PERSONA("P" & i, i)
Next
Console.WriteLine(" los objetos creado son")
For i = 0 To n - 1
A(i).VerDatos()
Next
Console.WriteLine("INGRESE EL NRO A A MODIFICAR {0} a {1} ", 0, n - 1)
np = Console.ReadLine
A(np).ingresar()
Console.WriteLine(" los objetos modificados son")
For i = 0 To n - 1
A(i).VerDatos()
Next
Console.ReadLine()
End Sub
End Module
Implementacion de eventos
Option Explicit On
Option Strict On
- 202 -
- 203 -
- 204 -
Nombre = Console.ReadLine
Console.Write(" ingrese DNI")
DNI = CInt(Console.ReadLine)
End Sub
Sub VerDatos()
Console.WriteLine(" Nombre {0}", Nombre)
Console.WriteLine(" DNI {0}", DNI)
End Sub
End Class
Module Module1
Private WithEvents Objeto As PERSONA
Sub Main()
Objeto = New PERSONA()
Objeto.DNI = -40 ' provoca el evento 1
Objeto.DNI = 2000000000 ' provoca el evento 2
Objeto.DNI = 300 ' no provoca ningun evento
Console.WriteLine("dni {0} ", Objeto.DNI)
Console.ReadLine()
End Sub
Private Sub Evento1(ByVal Valor As Single) Handles Objeto.Evento1
Console.WriteLine("{0} no se permite dni ", Valor)
' MsgBox("no se permite dni negativo " & Valor)
End Sub
Private Sub Ecirculo_Evento2(ByVal Valor As Single) Handles Objeto.Evento2
Console.WriteLine("{0} no se permite valores superiores a 1000000", Valor)
End Sub
End Module
PRACTICA DEL MIERCOLES 28 DE MAYO DEL 2014
CLASE VEHICULOS
- 205 -
Console.Write("Ingrese Ao")
ao = Console.ReadLine
End Sub
Sub VerDatos()
Console.WriteLine("Placa {0} Propietario {1} Ao {2} ", placa, propietario, ao)
End Sub
Sub Encender()
Console.WriteLine(" Carro Encedido")
End Sub
Sub Apagar()
Console.WriteLine(" Carro APAGADO")
End Sub
End Class
Module Module1
Dim carro As Vehiculo
Sub Main()
carro = New Vehiculo
carro.IngresarDatos()
carro.VerDatos()
carro.Encender()
carro.Apagar()
Console.ReadLine()
End Sub
End Module
- 206 -
End Sub
End Class
Module Module1
Dim DUEOS(100) As Vehiculo
Sub Main()
Dim n = 100, i As Integer
For i = 0 To n - 1
DUEOS(i) = New Vehiculo("A" & i, "Dueo " & i, 0)
Next
For i = 0 To n - 1
DUEOS(i).VerDatos()
Next
DUEOS(4).propietario = "juan perez"
Console.ReadLine()
End Sub
End Module
CLASE ESTADISTICA
Public Class ESTADISTICA
Private i As Integer
Protected N As Integer
Protected datos(10) As Integer
Protected media As Single
Protected desviacion As Single
Sub IngresarDatos()
Console.Write(" cantidad de datos ")
N = Console.ReadLine
Console.Write("ingrese {0} datos ", N)
Console.WriteLine()
For i = 0 To N - 1
datos(i) = Console.ReadLine
Next
End Sub
Sub MostrarDatos()
Console.WriteLine(" los datos del objeto son ")
For i = 0 To N - 1
Console.Write(" {0} ", datos(i))
Next
Console.WriteLine()
End Sub
Public Sub New(Optional ByVal n2 As Integer = 3)
N = n2
For i = 0 To N - 1
datos(i) = i + 1
Next
End Sub
End Class
Module Module1
Dim Objeto1, objeto2 As ESTADISTICA
- 207 -
Sub Main()
Objeto1 = New ESTADISTICA
objeto2 = New ESTADISTICA(2)
Objeto1.MostrarDatos()
objeto2.MostrarDatos()
Console.ReadLine()
End Sub
End Module
Diagrama de clases
SOLUCIONES DE EXAMENES
GRUPO1 Lunes de 16 a 18 horas
Public Class Form1
- 208 -
- 209 -
- 210 -
DataGridView1.Rows(cont).Cells(2).Value = CboCargo.Text
DataGridView1.Rows(cont).Cells(3).Value = TxtSueldo.Text
Select Case CboCargo.Text
Case "Gerente"
tg = tg + 1
Case "Empleado"
te = te + 1
Case "Operariop"
Top = Top + 1
End Select
cont = cont + 1
TxtNombre.Enabled = False
TxtSueldo.Enabled = False
CboCargo.Enabled = False
End Sub
Private Sub BtnEstadistica_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles BtnEstadistica.Click
Form3.txtGerente.Text = tg
Form3.txtEmpleado.Text = te
Form3.txtOperario.Text = Top
Form3.txtTotalSueldo.Text = tsueldo
Form3.ShowDialog()
End Sub
End Class
- 211 -
- 212 -
- 213 -
- 214 -
End Sub
End Class
- 215 -
- 216 -
- 217 -
- 218 -
- 219 -
CboArea.Enabled = True
CboSexo.Enabled = True
BtnGuardar.Enabled = True
End Sub
Private Sub BtnGuardar_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles BtnGuardar.Click
DataGridView1.Rows.Add()
DataGridView1.Rows(cont).Cells(0).Value = txtCodigo.Text
DataGridView1.Rows(cont).Cells(1).Value = CboArea.Text
DataGridView1.Rows(cont).Cells(2).Value = CboSexo.Text
Select Case CboArea.Text
Case "Ingenierias"
If CboSexo.Text = "Masculino" Then
sva1 = sva1 + 1
Else
sma1 = sma1 + 1
End If
Case "Sociales"
If CboSexo.Text = "Masculino" Then
sva2 = sva2 + 1
Else
sma2 = sma2 + 1
End If
Case "Biomedicas"
If CboSexo.Text = "Masculino" Then
sva3 = sva3 + 1
Else
sma3 = sma3 + 1
End If
End Select
cont = cont + 1
txtCodigo.Enabled = False
CboSexo.Enabled = False
CboArea.Enabled = False
End Sub
Private Sub BtnEstadistica_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles BtnEstadistica.Click
Form3.DataGridView1.ColumnCount = 4
Form3.DataGridView1.RowCount = 3
Form3.DataGridView1.Columns(0).HeaderText = "Area"
Form3.DataGridView1.Columns(1).HeaderText = "Varones"
Form3.DataGridView1.Columns(2).HeaderText = "Mujeres"
Form3.DataGridView1.Columns(3).HeaderText = "Total"
Form3.DataGridView1.Rows(0).Cells(0).Value = CboArea.Items(0)
Form3.DataGridView1.Rows(0).Cells(1).Value = sva1
Form3.DataGridView1.Rows(0).Cells(2).Value = sma1
Form3.DataGridView1.Rows(0).Cells(3).Value = sva1 + sma1
- 220 -
Form3.DataGridView1.Rows(1).Cells(0).Value = CboArea.Items(1)
Form3.DataGridView1.Rows(1).Cells(1).Value = sva2
Form3.DataGridView1.Rows(1).Cells(2).Value = sma2
Form3.DataGridView1.Rows(1).Cells(3).Value = sva2 + sma2
Form3.DataGridView1.Rows(2).Cells(0).Value = CboArea.Items(2)
Form3.DataGridView1.Rows(2).Cells(1).Value = sva3
Form3.DataGridView1.Rows(2).Cells(2).Value = sma3
Form3.DataGridView1.Rows(2).Cells(3).Value = sva3 + sma3
Form3.ShowDialog()
End Sub
End Class
Private X1 As Integer
Private y1 As Integer
Public Property X As Integer
Get
X = X1
End Get
Set(ByVal value As Integer)
X1 = value
End Set
End Property
Public Property Y As Integer
Get
Y = y1
End Get
Set(ByVal value As Integer)
y1 = value
End Set
End Property
End Class
Public Class Circulo
Inherits Punto
Private Radio1 As Integer
Public Property Radio As Integer
Get
Radio = Radio1
End Get
Set(ByVal value As Integer)
Radio1 = value
End Set
End Property
End Class
- 221 -
- 222 -
- 223 -
Me.Close()
End Sub
- 224 -
DataGridView1.Rows(cont).Cells(0).Value = CboCodigo.Text
DataGridView1.Rows(cont).Cells(1).Value = CboNota.Text
snota = snota + CboNota.Text
If CboNota.Text > mayor Then
mayor = CboNota.Text
codgana = CboCodigo.Text
End If
cont = cont + 1
CboCodigo.Enabled = False
CboNota.Enabled = False
End Sub
Private Sub BtnEstadistica_Click(ByVal sender As Object, ByVal e As EventArgs)
Handles BtnEstadistica.Click
Form3.TxtPnota.Text = snota / cont
Form3.txtMaximaNota.Text = mayor
Form3.txtGanador.Text = codgana
Form3.ShowDialog()
End Sub
End Class
- 225 -
Blog www.incanato.site90.com
Juan Carlos Arcila Daz
Chiclayo - Per
Enero 2014
Se realizar Prcticas para el examen (del primer y segundo trabajo)
Se preguntara sobre recursividad. Solucin de las preguntas del examen tentativo
Como realizar macros en excel
MDI hay 3 formularios hechos (mostrar su modificaciones)
- Preguntas sobre controles button, textbox, cuadros de listas, cuadros
combinados, men strip,menus contextuales, cuadros de dilogos, eventos del
mouse y del teclado, cajas de dialogo (open files dialog,etc )
- Creacin de formularios y controles en tiempo de ejecucin
- Input box, message box, timer animacin sencilla
- Propiedades mtodos eventos
- Grficos
- Procedimientos de eventos
En evaluacin de expresiones hay 2 trabajos
Archivos, escritura lectura, leer una matriz, grabar los Valores de una funcin
Cadenas. Elaborar funciones de cadenas, ejemplo buscar una su cadena, reemplazar
una su cadena ,
Trabajo adicional juego
Matrices mostrar una parte de una matriz,
Preguntas sobre clases y objetos
1. crear una clase con sus propiedades, campos, mtodos, eventos
2. Usar la clase creada en modo consola o formulario
Saludos
Ing. Veliz
SISTEMA EJEMPLO DE CLASES Y OBJETOS ( CLASE VEHICULO)
- 226 -
- 227 -
- 228 -
- 229 -
- 230 -
fila = DataGridView1.CurrentRow.Index
objeto = autos(fila)
txtNro.Text = objeto.Nro
txtAo.Text = objeto.Ao
txtPropietario.Text = objeto.Propietario
txtplaca.Text = objeto.Placa
txtMarca.Text = objeto.Marca
txtFoto.Text = objeto.Foto
txtCombustible.Text = objeto.CantCombustible
PictureBox1.Load("E:\DATOS\FOTOS\" & objeto.Foto)
End Sub
End Class
PRACTICAS SI 2015 DEL DIA MARTES 09 DE JUNIO DEL 2015
Turno de 5 a 7 pm
Elaborar la siguiente aplicacin
Imports System.IO
Public Class Form1
Dim NombreArchivo As String
Private Sub btnBorrar_Click(sender As Object, e As EventArgs) Handles
btnBorrar.Click
TextBox1.Clear()
End Sub
Private Sub btnFuente_Click(sender As Object, e As EventArgs) Handles
btnFuente.Click
FontDialog1.ShowDialog()
TextBox1.Font = FontDialog1.Font
End Sub
- 231 -
- 232 -
- 233 -
- 234 -
- 235 -
- 236 -
- 237 -
- 238 -
- 239 -
Module Module1
Function CLETRAS(cadena As String, cad1 As String) As Integer
Dim fila As Integer
Dim cont = 0
For fila = 0 To Len(cadena) - 1
If cadena(fila) = cad1 Then cont = cont + 1
Next
CLETRAS = cont
End Function
End Module
Public Class Form1
Dim nfilas As Integer = 60
Dim grafico As Graphics
Dim pen As Pen
Dim pen1 As Pen
Dim brocha As SolidBrush
Dim cx As Integer = 10
Dim cy As Integer = 400
Dim ancho As Integer = 400
Dim alto As Integer = 410
Dim ex As Integer = 8
Dim ey As Integer = 8
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim fila As Integer
With Me.DataGridView1.DefaultCellStyle
.Font = New Font("Tahoma", 15)
.ForeColor = Color.Blue
.BackColor = Color.Beige
.SelectionForeColor = Color.Yellow
.SelectionBackColor = Color.Black
End With
DataGridView1.ColumnCount = 2
- 240 -
DataGridView1.RowCount = nfilas + 1
DataGridView1.Columns(0).HeaderText = "Letra"
DataGridView1.Columns(1).HeaderText = "Cantidad"
For fila = 0 To nfilas - 1
DataGridView1.Rows(fila).Cells(0).Value = Chr(32 + fila)
Next
End Sub
Private Sub btnProcesar_Click(sender As Object, e As EventArgs) Handles
btnProcesar.Click
Dim cadena As String
Dim nletras As Integer
Dim fila As Integer
cadena = TextBox1.Text
For fila = 0 To nfilas - 1
nletras = CLETRAS(cadena, Chr(32 + fila))
DataGridView1.Rows(fila).Cells(1).Value = nletras
Next
End Sub
Private Sub btnGraficar_Click(sender As Object, e As EventArgs) Handles
btnGraficar.Click
Dim fila, y As Integer
grafico = PictureBox1.CreateGraphics
pen = New Pen(Color.Red, 2)
pen1 = New Pen(Color.Blue, 1)
brocha = New SolidBrush(Color.Green)
' coordenadas
grafico.DrawLine(pen1, 0, cy, ancho, cy)
grafico.DrawLine(pen1, cx, 0, cx, alto)
For fila = 0 To nfilas - 1
y = DataGridView1.Rows(fila).Cells(1).Value
grafico.FillRectangle(brocha, cx + fila * ex, cy - y * ey, ex, y * ey)
grafico.DrawRectangle(pen, cx + fila * ex, cy - y * ey, ex, y * ey)
Next
End Sub
Private Sub btnLimpiar_Click(sender As Object, e As EventArgs) Handles
btnLimpiar.Click
TextBox1.Text = ""
grafico.Clear(Color.Black)
End Sub
End Class
Contar palabras
- 241 -
- 242 -
- 243 -
- 244 -
- 245 -
- 246 -
- 247 -
- 248 -
- 249 -
- 250 -
- 251 -
Case 2
For fila = 1 To ne - 1
cadres = cadres + cadena(fila)
Next
cadres = cadres + cadena(0)
End Select
Return cadres
End Function
End Module
CODIGO DEL FORMULARIO
Public Class Form1
Dim Color As Color
Dim Pos As Integer
Dim pos1 As Integer = 1
Dim posini As Integer = 1
Dim tipo As Integer = 1
Private Sub btnBorrar_Click(sender As Object, e As EventArgs) Handles
btnBorrar.Click
RichTextBox1.Clear()
End Sub
Private Sub btnSalir_Click(sender As Object, e As EventArgs) Handles btnSalir.Click
Me.Close()
End Sub
Private Sub btnGrabar_Click(sender As Object, e As EventArgs) Handles
btnGrabar.Click
SaveFileDialog1.Title = "Abrir Documento rtf"
SaveFileDialog1.Filter = "Documento rtf|*.rtf"
SaveFileDialog1.ShowDialog()
RichTextBox1.SaveFile(SaveFileDialog1.FileName,
RichTextBoxStreamType.RichText)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
BtnAbrir1.Click
OpenFileDialog1.Title = "Abrir Documento rtf"
OpenFileDialog1.Filter = "Documento rtf|*.rtf"
OpenFileDialog1.ShowDialog()
RichTextBox1.LoadFile(OpenFileDialog1.FileName,
RichTextBoxStreamType.RichText)
End Sub
Private Sub BtnColor_Click(sender As Object, e As EventArgs) Handles
BtnColor.Click
ColorDialog1.ShowDialog()
Color = ColorDialog1.Color
RichTextBox1.SelectionColor = Color ' El color que quieras
End Sub
- 252 -
- 253 -
- 254 -
End Set
End Property
Public Property Nombre As String
Get
Nombre = nombre1
End Get
Set(value As String)
nombre1 = value
End Set
End Property
Public Property sexo As Boolean
Get
sexo = sexo1
End Get
Set(value As Boolean)
sexo1 = value
End Set
End Property
Sub New(Optional dni2 As Integer = 0, Optional nombre2 As String = "fulano", _
Optional Sexo2 As Boolean = True)
DNI1 = dni2
nombre1 = nombre2
sexo1 = Sexo2
End Sub
Function ObtenerValores() As String
Dim cad1 As String = ""
cad1 = " Nombre " + nombre1 + vbCrLf + "Dni " + DNI + vbCrLf + "sexo " + sexo1
Return cad1
End Function
End Class
- 255 -
- 256 -
- 257 -
'
'
'
txtDNI.Text = objeto.DNI
txtNombre.Text = objeto.Nombre
txtSexo.Text = objeto.sexo
'Catch ex As Exception
' MsgBox(ex.Message)
'End Try
End Sub
End Class
Practicas del dia martes 16 de junio del 2015
Turno de 7-9
Clase animal
- 258 -
- 259 -
- 260 -
- 261 -
End Sub
Private Sub btnCrear_Click(sender As Object, e As EventArgs) Handles
btnCrear.Click
' objeto = New ANIMAL()
gato = New ANIMAL("GARFIELD", 2, "E:\DATOS\avion1.BMP")
'perro = New ANIMAL("FIDO")
'vaca = New ANIMAL
'vaca.Nombre = "MANUELA"
'vaca.Peso = 400
End Sub
Private Sub btnMostrar_Click(sender As Object, e As EventArgs) Handles
btnMostrar.Click
TxtNombre.Text = gato.Nombre
txtPeso.Text = gato.Peso
txtFoto.Text = gato.foto
Dim NOMBRE As String
NOMBRE = "E:\DATOS\avion1.bmp"
PictureBox1.Load(NOMBRE)
End Sub
End Class
Public Class ANIMAL
Protected Nombre1 As String
Protected Peso1 As Single
Protected foto1 As String
Public Event Evento1(ByVal Valor As Single)
Property Nombre As String
Get
Nombre = Nombre1
End Get
Set(value As String)
Nombre1 = value
End Set
End Property
Property Peso As Single
Get
Peso = Peso1
End Get
Set(value As Single)
If Peso < 0 Then
RaiseEvent Evento1(value)
Else
Peso1 = value
End If
End Set
End Property
Property foto As String
Get
- 262 -
foto = foto1
End Get
Set(value As String)
foto1 = value
End Set
End Property
Sub New(Optional nombre2 As String = "Animal", _
Optional peso2 As Single = 0, Optional foto2 As String = "sin foto")
Nombre1 = nombre2
Peso1 = peso2
foto1 = foto2
End Sub
Function MostrarValor() As String
Dim cadena As String
cadena = "Nombre " + Nombre1 + vbCrLf + "peso " + CStr(Peso1) + vbCrLf + "foto
" + foto1
Return cadena
End Function
End Class
CLASE ESTADISTICA MODO CONSOLA
Clase del miercoles 17 de junio del 2015
Cdigo de la clase
- 263 -
- 264 -
- 265 -
N1 = Ndatos
For fila = 0 To N1 - 1
A(fila) = fila + 1
Next
End Sub
Public Sub Asignar(A1() As Single, ndatos As Integer)
Dim fila As Integer
Dim mayor As Single = -1000
Dim menor As Single = 1000
Dim suma As Single = 0
N1 = ndatos
For fila = 0 To N1 - 1
A(fila) = A1(fila)
suma = suma + A(fila)
If A(fila) > mayor Then mayor = A(fila)
If A(fila) < menor Then menor = A(fila)
Next
suma1 = suma
Prom1 = suma1 / N1
max1 = mayor
min1 = menor
End Sub
Public Function VerDatos() As String
Dim fila As Integer
Dim cadena As String = ""
For fila = 0 To N1 - 1
cadena = cadena + vbCrLf + CStr(A(fila))
Next
Return cadena
End Function
Public Function VerResultados() As Single()
Dim Vector(5) As Single
Vector(0) = N1
Vector(1) = suma1
Vector(2) = Prom1
Vector(3) = max1
Vector(4) = min1
VerResultados = Vector
End Function
End Class
CODIGO DEL FORMULARIO
Imports System.IO
Public Class Form1
Dim Maxdatos As Integer = 10
Dim Vector(Maxdatos) As Single
Dim VR(Maxdatos) As Single
Dim objeto As ESTADISTICA
Dim Nd As Integer = 3
- 266 -
- 267 -
- 268 -