Está en la página 1de 53

Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -1

MIS PRACTICAS DE SISTEMAS DE INFORMACIÓN 2018A

Module Module1
Dim n1, n2, suma As Single
Sub Main()
Console.Write("ingrese primer numero ")
n1 = Console.ReadLine
Console.Write("ingrese primer numero ")
n2 = Console.ReadLine
suma = n1 + n2
Console.Write("la suma es {0} ", suma)
Console.ReadLine()
End Sub
End Module

Turno 1

Module Module1
Dim n1, n2, suma As Single
Sub Main()
Console.Write("ingrese Nro 1")
n1 = Console.ReadLine
Console.Write("ingrese Nro 2")
n2 = Console.ReadLine
suma = n1 + n2
Console.WriteLine("la suma es {0}", suma)
Console.ReadLine()
End Sub
End Module

En modo formulario

Public Class Form1


Dim n1, n2, resultado As Single
Private Sub sumar(sender As Object, e As EventArgs) Handles btnSuma.Click,
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -2

btnResta.Click, btnMultiplicar.Click
n1 = txtN1.Text
n2 = txtN2.Text
Select Case sender.text
Case "+" : resultado = n1 + n2
Case "-" : resultado = n1 - n2
Case "X" : resultado = n1 * n2
End Select
txtRes.Text = resultado
End Sub
End Class

Con funciones
Public Class Form1
Dim n1, n2, resultado As Single
Function SUMAR(N1 As Single, N2 As Single) As Single
Return N1 + N2
' SUMAR = N1 + N2
End Function
Function RESTAR(N1 As Single, N2 As Single) As Single
RESTAR = N1 - N2
End Function
Private Sub sumar(sender As Object, e As EventArgs) Handles btnSuma.Click,
btnResta.Click, btnMultiplicar.Click, btnSeno.Click
n1 = txtN1.Text
n2 = txtN2.Text
Select Case sender.text
Case "+" : resultado = SUMAR(n1, n2)
Case "-" : resultado = RESTAR(n1, n2)
Case "X" : resultado = n1 * n2
Case "SENO" : resultado = Math.Sin(n1)
End Select
txtRes.Text = resultado
End Sub
End Class
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -3

Public Class Form1


Dim n1, n2, resultado As Single
Function SUMAR(N1 As Single, N2 As Single) As Single
Return N1 + N2
' SUMAR = N1 + N2
End Function

Private Sub BTNpRUEBA_MouseEnter(sender As Object, e As EventArgs) Handles


BTNpRUEBA.MouseEnter
BTNpRUEBA.BackColor = Drawing.Color.Red
End Sub

Private Sub BTNpRUEBA_MouseLeave(sender As Object, e As EventArgs) Handles


BTNpRUEBA.MouseLeave
BTNpRUEBA.BackColor = Drawing.Color.Green
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick


BTNpRUEBA.Left = BTNpRUEBA.Left + 10
End Sub

Private Sub btnIniciar_Click(sender As Object, e As EventArgs) Handles


btnIniciar.Click
Timer1.Interval = 100
Timer1.Start()
End Sub

Private Sub btnParar_Click(sender As Object, e As EventArgs) Handles


btnParar.Click
Timer1.Stop()
End Sub
Function RESTAR(N1 As Single, N2 As Single) As Single
RESTAR = N1 - N2
End Function
Private Sub sumar(sender As Object, e As EventArgs) Handles btnSuma.Click,
btnResta.Click, btnMultiplicar.Click, btnSeno.Click
n1 = txtN1.Text
n2 = txtN2.Text
Select Case sender.text
Case "+" : resultado = SUMAR(n1, n2)
Case "-" : resultado = RESTAR(n1, n2)
Case "X" : resultado = n1 * n2
Case "SENO" : resultado = Math.Sin(n1)
End Select
txtRes.Text = resultado
End Sub
End Class
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -4

Public Class Form1


Function Sumar(n1 As Single, n2 As Single) As Single
Return n1 + n2
End Function
Function restar(n1 As Single, n2 As Single) As Single
restar = n1 - n2
End Function
Private Sub operacion(sender As Object, e As EventArgs) _
Handles btnSUma.Click, btnResta.Click, btnMod.Click
Dim n1, n2, res As Single
n1 = txtNro1.Text
n2 = txtNro2.Text
Select Case sender.text
Case "+" : res = Sumar(n1, n2)
Case "-" : res = restar(n1, n2)
Case "Mod" : res = n1 Mod n2
End Select
txtRes.Text = res
End Sub

Private Sub btnPrueba_Click(sender As Object, e As EventArgs) Handles


btnPrueba.Click
Me.BackColor = Drawing.Color.Yellow
End Sub
Private Sub btnPrueba_MouseLeave(sender As Object, e As EventArgs) Handles
btnPrueba.MouseLeave
Me.BackColor = Drawing.Color.Gray
End Sub
Private Sub btnPrueba_MouseEnter(sender As Object, e As EventArgs) Handles
btnPrueba.MouseEnter
Me.BackColor = Drawing.Color.Green
End Sub
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -5

Private Sub btnIniciar_Click(sender As Object, e As EventArgs) Handles


btnIniciar.Click
Timer1.Interval = 10
Timer1.Start()
End Sub
Private Sub btnParar_Click(sender As Object, e As EventArgs) Handles
btnParar.Click
Timer1.Stop()
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick


btnMovil.Left = btnMovil.Left + 1
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


OpenFileDialog1.ShowDialog()
PictureBox1.Load(OpenFileDialog1.FileName)
End Sub
End Class

Practicas grupo miercoles de 850 a 10:30

Module Module1
Dim n1, n2, suma As Single
Sub Main()
Console.Write("ingrese n1")
n1 = Console.ReadLine
Console.Write("ingrese n2")
n2 = Console.ReadLine
suma = n1 + n2
Console.WriteLine(" la suma es {0}", suma)
Console.ReadLine()
End Sub
End Module

Module Module1
Dim n1, n2 As Single
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -6

Sub Main()
Console.Write("ingrese n1 ")
n1 = Console.ReadLine
Console.Write("ingrese n2 ")
n2 = Console.ReadLine
Console.WriteLine(" la suma es {0}", n1 + n2)
Console.WriteLine(" la resta es {0}", n1 - n2)
Console.WriteLine(" LA POTENCIA DE {0} A {1} ES {2}", n1, n2, Math.Pow(n1, n2))
Console.ReadLine()
End Sub
End Module

Module Module1
Dim n1, n2 As Single
Sub Main()
Console.Write("ingrese n1 ")
n1 = Console.ReadLine
Console.Write("ingrese n2 ")
n2 = Console.ReadLine
Console.WriteLine(" la suma es {0}", n1 + n2)
Console.WriteLine(" la resta es {0}", n1 - n2)
Console.ForegroundColor = 10
Console.WriteLine(" LA POTENCIA DE {0} A {1} ES {2}", n1, n2, Math.Pow(n1, n2))
Console.WriteLine(" la FECHA ES {0}", Date.Now)
Console.WriteLine(" LA HORAS {0}", Date.Now.Hour)
Console.ForegroundColor = ConsoleColor.Red
Console.WriteLine("MINUTOS {0}", Date.Now.Minute)
Console.SetCursorPosition(40, 20)
Console.Write("EPII")
Console.ReadLine()
End Sub
End Module
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -7

Public Class Form1


Dim n1, n2, res As Single
Private Sub btnOtros_Click(sender As Object, e As EventArgs) Handles
btnOtros.Click
Dim fila, nro As Integer
ListBox1.Items.Clear()
Randomize()
ListBox1.Items.Add(" la FECHA ES" & Date.Now)
ListBox1.Items.Add(" hora ES" & Date.Now.Hour)
ListBox1.Items.Add(" minutoES" & Date.Now.Minute)
' 10 NUMEROS ALETORIOAS 0 A 20
For fila = 1 To 10
nro = Int(Rnd() * 20)
ListBox1.Items.Add(" nro" & nro)
Next
End Sub
Private Sub btnSuma_Click(sender As Object, e As EventArgs) _
Handles btnSuma.Click, btnResta.Click, btnPot.Click
n1 = txtNro1.Text
n2 = txtNro2.Text
Select Case sender.text
Case "+" : res = n1 + n2
Case "-" : res = n1 - n2
Case "Potencia" : res = Math.Pow(n1, n2)
End Select
txtRes.Text = res
End Sub
End Class

PRACTICAS DEL LUNES 26 DE MARZO DEL 2018


TURNO DE 940 A 11:20
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -8

Imports System.IO
Module Module1
Sub Main()
Dim archivo As StreamWriter
archivo = New StreamWriter("f:\DATOS\NOTAS.txt")
archivo.WriteLine("HOLA MUNDO")
archivo.Close()
Console.WriteLine(" archivo grabado satisfactoriamente")
Console.ReadLine()
End Sub
End Module

Tabla de multiplicar solo en la pantalla

Module Module1
Sub Main()
Dim fila, col As Integer
For fila = 1 To 12
For col = 1 To 12
Console.Write("{0}{1}", fila * col, vbTab)
Next
Console.WriteLine()
Next
Console.ReadLine()
End Sub
End Module

Con archivos

Imports System.IO
Module Module1
Sub Main()
Dim archivo As StreamWriter
archivo = New StreamWriter("f:\datos\tablamult.txt")
Dim fila, col As Integer
For fila = 1 To 12
For col = 1 To 12
Console.Write("{0}{1}", fila * col, vbTab)
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -9

archivo.Write("{0}{1}", fila * col, vbTab)


Next
archivo.WriteLine()
Console.WriteLine()
Next
archivo.Close()
Console.WriteLine("archivo grabado")
Console.ReadLine()
End Sub
End Module
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -10

Module Module1
Sub MAIN()
Dim Fila, col As Integer
Dim prom, suma As Single
RecuperarMatriz(NombreArchivo, A, nfilas, ncol)
MostrarMatriz(A, nfilas, ncol)
For Fila = 0 To nfilas - 1
suma = 0
For col = 0 To ncol - 1
suma = suma + A(Fila, col)
Next
prom = suma / ncol
Console.WriteLine("prom {0} es {1}", Fila, prom)
Next
Console.ReadLine()
End Sub
End Module

Imports System.IO
Module Module2
Public NombreArchivo As String = "F:\datos\notas2.txt"
Public Const limite As Integer = 10
Public A(limite, limite) As Integer
Public nfilas, ncol As Integer
Function ContarLetra(Cadena As String, letra As Char)
Dim LARGO As Integer = Len(Cadena)
Dim cont, cant As Integer
For cont = 0 To LARGO - 1
If Cadena(cont) = letra Then
cant = cant + 1
End If
Next
Return cant
End Function

Sub RecuperarMatriz(ByVal nombrearchivo As String,


Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -11

ByRef A(,) As Integer, ByRef nf As Integer, ByRef nc As Integer)


Dim srLector As StreamReader
srLector = New StreamReader(nombrearchivo)
Dim fila As Integer, col As Integer
Dim cadena As String = ""
Dim subcadena As String
Dim pos As Integer = 0
Dim inicio As Integer = 1
cadena = srLector.ReadLine()
nc = ContarLetra(cadena, vbTab) + 1
Do While Not (cadena = "")
cadena = cadena & vbTab
inicio = 1
For col = 0 To nc - 1
pos = InStr(inicio, cadena, Chr(9))
subcadena = Mid(cadena, inicio, pos - inicio)
A(fila, col) = Val(subcadena)
inicio = pos + 1
Next
fila = fila + 1
cadena = srLector.ReadLine()
Loop
nf = fila
Console.WriteLine("Archivo leido satisfactoriamente")
srLector.Close()
End Sub
Sub VerMatriz(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As Integer, ByVal
cx As Integer, ByVal cy As Integer)
Dim fila, col, c1 As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
If A(fila, col) <= 15 Then
Console.SetCursorPosition(cx + col, cy + fila)
Console.BackgroundColor = CType(A(fila, col), ConsoleColor)
Console.ForegroundColor = CType(A(fila, col), ConsoleColor)
Console.Write("{0}", A(fila, col))
End If
Next
Next
End Sub
Sub MostrarMatriz(A(,) As Integer, nf As Integer, nc As Integer)
Dim fila, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
Console.Write("{0} {1}", A(fila, col), vbTab)
Next
Console.WriteLine()
Next
End Sub
End Module
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -12

PRACTICAS DEL MARTES 27 DE MARZO DE 15:40 17:30

Imports System.IO
Module Module1
Sub Main()
Dim Archivo As StreamWriter
Archivo = New StreamWriter("F:\DATOS\PRUEBA.TXT")
Console.WriteLine(" HOLA MUNDO")
Archivo.WriteLine(" HOLA MUNDO")
Archivo.Close()
Console.ReadLine()
End Sub
End Module

Ejercicio 2
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -13

Module Module1
Sub PROMEDIOS(A(,) As Integer, NF As Integer, NC As Integer)
Dim FILA, COL As Integer
Dim suma As Single
For FILA = 0 To NF - 1
suma = 0
For COL = 0 To NC - 1
suma = suma + A(FILA, COL)
Next
Console.WriteLine("{0} {1}", FILA, suma / NC)
Next
End Sub

Sub MAIN()
RecuperarMatriz(NombreArchivo, A, nfilas, ncol)
MostrarMatriz(A, nfilas, ncol)
Console.WriteLine("promedios")
PROMEDIOS(A, nfilas, ncol)
Console.ReadLine()
End Sub
End Module

Imports System.IO
Module Module2
Public NombreArchivo As String = "F:\datos\matriz.txt"
Public Const limite As Integer = 120
Public A(limite, limite) As Integer
Public nfilas, ncol As Integer
Function ContarLetra(Cadena As String, letra As Char)
Dim LARGO As Integer = Len(Cadena)
Dim cont, cant As Integer
For cont = 0 To LARGO - 1
If Cadena(cont) = letra Then
cant = cant + 1
End If
Next
Return cant
End Function

Sub RecuperarMatriz(ByVal nombrearchivo As String, ByRef A(,) As Integer, ByRef


nf As Integer, ByRef nc As Integer)
Dim srLector As StreamReader
srLector = New StreamReader(nombrearchivo)
Dim fila As Integer, col As Integer
Dim cadena As String = ""
Dim subcadena As String
Dim pos As Integer = 0
Dim inicio As Integer = 1
cadena = srLector.ReadLine()
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -14

nc = ContarLetra(cadena, vbTab) + 1
Do While Not (cadena = "")
cadena = cadena & vbTab
inicio = 1
For col = 0 To nc - 1
pos = InStr(inicio, cadena, Chr(9))
subcadena = Mid(cadena, inicio, pos - inicio)
A(fila, col) = Val(subcadena)
inicio = pos + 1
Next
fila = fila + 1
cadena = srLector.ReadLine()
Loop
nf = fila
Console.WriteLine("Archivo leido satisfactoriamente")
srLector.Close()
End Sub
Sub VerMatriz(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As Integer, ByVal
cx As Integer, ByVal cy As Integer)
Dim fila, col, c1 As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
If A(fila, col) <= 15 Then
Console.SetCursorPosition(cx + col, cy + fila)
Console.BackgroundColor = CType(A(fila, col), ConsoleColor)
Console.ForegroundColor = CType(A(fila, col), ConsoleColor)
Console.Write("{0}", A(fila, col))
End If
Next
Next
End Sub
Sub MostrarMatriz(A(,) As Integer, nf As Integer, nc As Integer)
Dim fila, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
Console.Write("{0} {1}", A(fila, col), vbTab)
Next
Console.WriteLine()
Next
End Sub
End Module

PRATICAS MARTES 27 DE MARZO DLE 2018


Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -15

Module Module1
Sub Main()
Console.WriteLine("HOLA MUNDO")
Console.ReadLine()
End Sub
End Module

Con archivos

Imports System.IO
Module Module1
Sub Main()
Dim Archivo As StreamWriter
Archivo = New StreamWriter("f:\datos\prueba.txt")
Console.WriteLine("HOLA MUNDO")
Archivo.WriteLine("HOLA MUNDO")
Archivo.Close()
Console.WriteLine("el archivo ha sido grabado")
Console.ReadLine()
End Sub
End Module

Imports System.IO
Module Module1
Function f(x As Single, y As Single) As Single
'f = Math.Sin(x * x + y * y) / (x * x + y * y)
f = Math.Sin(x + y)
'Return Math.Sin(x * x + y * y) / x * x + y * y
End Function
Sub Main()
Dim x, y As Single
Dim Archivo As StreamWriter
Archivo = New StreamWriter("f:\datos\funcion3d.txt")
Console.WriteLine("valor de f(x,y)")
Archivo.WriteLine("valor de f(x,y)")
For y = -4 To 4 Step 0.5
For x = -4 To 4 Step 0.5
Console.Write("{0}{1}", f(x, y), vbTab)
Archivo.Write("{0}{1}", f(x, y), vbTab)
Next
Console.WriteLine()
Archivo.WriteLine()
Next
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -16

Archivo.Close()
Console.WriteLine("el archivo ha sido grabado")
Console.ReadLine()
End Sub
End Module

Module Module1
Sub PROMEDIOS(A(,) As Integer, NF As Integer, NC As Integer)
Dim FILA, COL As Integer
Dim suma As Single
For FILA = 0 To NF - 1
suma = 0
For COL = 0 To NC - 1
suma = suma + A(FILA, COL)
Next
Console.WriteLine("{0} {1}", FILA, suma / NC)
Next
End Sub
Sub MAIN()
RecuperarMatriz(NombreArchivo, A, nfilas, ncol)
MostrarMatriz(A, nfilas, ncol)
Console.WriteLine()
PROMEDIOS(A, nfilas, ncol)
Console.ReadLine()
End Sub
End Module

Imports System.IO
Module Module2
Public NombreArchivo As String = "F:\datos\matriz.txt"
Public Const limite As Integer = 120
Public A(limite, limite) As Integer
Public nfilas, ncol As Integer
Function ContarLetra(Cadena As String, letra As Char)
Dim LARGO As Integer = Len(Cadena)
Dim cont, cant As Integer
For cont = 0 To LARGO - 1
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -17

If Cadena(cont) = letra Then


cant = cant + 1
End If
Next
Return cant
End Function

Sub RecuperarMatriz(ByVal nombrearchivo As String, ByRef A(,) As Integer, ByRef


nf As Integer, ByRef nc As Integer)
Dim srLector As StreamReader
srLector = New StreamReader(nombrearchivo)
Dim fila As Integer, col As Integer
Dim cadena As String = ""
Dim subcadena As String
Dim pos As Integer = 0
Dim inicio As Integer = 1
cadena = srLector.ReadLine()
nc = ContarLetra(cadena, vbTab) + 1
Do While Not (cadena = "")
cadena = cadena & vbTab
inicio = 1
For col = 0 To nc - 1
pos = InStr(inicio, cadena, Chr(9))
subcadena = Mid(cadena, inicio, pos - inicio)
A(fila, col) = Val(subcadena)
inicio = pos + 1
Next
fila = fila + 1
cadena = srLector.ReadLine()
Loop
nf = fila
Console.WriteLine("Archivo leido satisfactoriamente")
srLector.Close()
End Sub

Sub VerMatriz(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As Integer, ByVal


cx As Integer, ByVal cy As Integer)
Dim fila, col, c1 As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
If A(fila, col) <= 15 Then
Console.SetCursorPosition(cx + col, cy + fila)
Console.BackgroundColor = CType(A(fila, col), ConsoleColor)
Console.ForegroundColor = CType(A(fila, col), ConsoleColor)
Console.Write("{0}", A(fila, col))
End If
Next
Next
End Sub
Sub MostrarMatriz(A(,) As Integer, nf As Integer, nc As Integer)
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -18

Dim fila, col As Integer


For fila = 0 To nf - 1
For col = 0 To nc - 1
Console.Write("{0} {1}", A(fila, col), vbTab)
Next
Console.WriteLine()
Next
End Sub
End Module

PRACTICAS DEL MIERCOLES 28 DE MARZO DEL 2018

Module Module1
Dim N1, N2,SUMA As Single
Sub Main()
Console.Write("INGRESE NRO 1 ")
N1 = Console.ReadLine
Console.Write("INGRESE NRO 2 ")
N2 = Console.ReadLine
SUMA=N1+N2
Console.WriteLine("LA SUMA DE {0} + {1} ES ={2} ", N1, N1, SUMA)
Console.ReadLine()
End Sub
End Module

Imports System.IO
Module Module1
Dim N1, N2, SUMA As Single
Sub Main()
Dim Archivo As StreamWriter
Archivo = New StreamWriter("f:\datos\prueba.txt")
Console.Write("INGRESE NRO 1 ")
N1 = Console.ReadLine
Console.Write("INGRESE NRO 2 ")
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -19

N2 = Console.ReadLine
SUMA = N1 + N2
Console.WriteLine("LA SUMA DE {0} + {1} ES ={2} ", N1, N2, SUMA)
Archivo.WriteLine("LA SUMA DE {0} + {1} ES ={2} ", N1, N2, SUMA)
Archivo.Close()
Console.ReadLine()
End Sub
End Module

Function 3d sin archivos

Imports System.IO
Module Module1
Function F(x As Single, y As Single) As Single
F = Math.Sin(x * x + y * y) / (x * x + y * y)
' Return Math.Sin(x * x + y * y) / (x * x + y * y)
End Function
Sub Main()
Dim x, y, z As Single
For y = -4 To 4 Step 0.5
For x = -4 To 4 Step 0.5
z = F(x, y)
Console.Write("{0}{1}", z, vbTab)
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -20

Next
Console.WriteLine()
Next
Console.ReadLine()
End Sub
End Module
Chart Title

1
0.5
0
-0.5 1

Series73
15

Series64
Series55
29

Series46
43

Series37
Series28
57

Series19
Series10
71 Series1

-0.5-0 0-0.5 0.5-1

Funcion 3D con archivos

Imports System.IO
Module Module1
Function F(x As Single, y As Single) As Single
F = Math.Sin(x * x + y * y) / (x * x + y * y)
' Return Math.Sin(x * x + y * y) / (x * x + y * y)
End Function
Sub Main()
Dim archivo As StreamWriter
Dim nombrearchivo As String = "F:\datos\funcio3d.txt"
archivo = New StreamWriter(nombrearchivo)
Dim x, y, z As Single
For y = -4 To 4 Step 0.1
For x = -4 To 4 Step 0.1
z = F(x, y)
Console.Write("{0}{1}", z, vbTab)
archivo.Write("{0}{1}", z, vbTab)
Next
Console.WriteLine()
archivo.WriteLine()
Next
archivo.Close()
Console.ForegroundColor = 10
Console.WriteLine("el archivo {0} a sido grabado", nombrearchivo)
Console.ReadLine()
End Sub
End Module
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -21

CLASES DEL 2 DE ABRIL DEL 2018

CLASE CIRCULO
Public Class circulo
' campos
Private Radio1 As Single
Private Area1 As Single
' propiedades
Property Radio() As Single
Get
Radio = Radio1
'Return Radio1
End Get
Set(value As Single)
Radio1 = value
End Set
End Property
ReadOnly Property Area() As Single
Get
Area = Area1
'Return Radio1
End Get
End Property
Sub CalcularArea()
Area1 = Math.PI * Math.Pow(Radio1, 2)
End Sub
Sub New(Optional R = 10)
Radio1 = 10
End Sub
Protected Overrides Sub Finalize()
MsgBox(" OBJETO DESTRUIDO ")
End Sub
End Class

Detalles de la clase

Aplicacion usando la clase circulo


Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -22

Module Module1
Dim objeto As circulo
Dim radio, area As Single
Sub Main()
objeto = New circulo(20)
Console.Write("ingrese radio ")
radio = Console.ReadLine
objeto.Radio = radio
objeto.CalcularArea()
area = objeto.Area
Console.WriteLine(" el area es {0}", area)
Console.ReadLine()
End Sub
End Module

PRACTICAS DEL MIERCOLES 04 DE ABRIL DEL 2018

CLASE PERSONA
Public Class PERSONA
' CAMPOS
Private Nombre1 As String
Private DNi1 As Integer
' propiedades
Property Nombre As String
Get
Nombre = Nombre1
' Return Nombre1
End Get
Set(value As String)
Nombre1 = value
End Set
End Property
Property Dni As Integer
Get
Dni = DNi1
End Get
Set(value As Integer)
DNi1 = value
End Set
End Property
Sub MostrarDatos()
Console.WriteLine(" el nombre es {0} ", Nombre1)
Console.WriteLine(" Dni es {0} ", DNi1)
End Sub
Sub New(Optional nombre2 As String = "FULANO", Optional dNI2 As Integer = 0)
Nombre1 = nombre2
DNi1 = dNI2
End Sub
Protected Overrides Sub Finalize()
Console.WriteLine("objeto destruido")
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -23

End Sub
End Class

Uso de la clase persona

Module Module1
Dim Juan As PERSONA
Dim Pedro As PERSONA
Dim Carlos As PERSONA
Sub Main()
Juan = New PERSONA()
Pedro = New PERSONA("PEDRO")
Carlos = New PERSONA("CARLOS", 1234)
Juan.MostrarDatos()
Pedro.MostrarDatos()
Carlos.MostrarDatos()
Juan.Nombre = "JUAN PEREZ"
Juan.MostrarDatos()
Console.ReadLine()
End Sub
End Module

Ejercicio 2 ingrese datos para n personas

Module Module1
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -24

Dim A(100) As PERSONA


Sub Main()
Dim n, fila As Integer
Console.Write("ingrese N ")
n = Console.ReadLine
For fila = 0 To n - 1
A(fila) = New PERSONA("persona" & fila, fila)
Next
Console.WriteLine("datos generados")
For fila = 0 To n - 1
Console.WriteLine("{0} {1} {2}", A(fila).Nombre, vbTab, A(fila).Dni)
Next
Console.WriteLine("cambianddo datos")
For fila = 0 To n - 1
Console.Write("ingrese nombre de {0} ", fila)
A(fila).Nombre = Console.ReadLine
Console.Write("ingrese dni de persona {0} ", fila)
A(fila).Dni = Console.ReadLine
Next
Console.WriteLine("datos cambiados")
For fila = 0 To n - 1
Console.WriteLine("{0} {1} {2}", A(fila).Nombre, vbTab, A(fila).Dni)
Next
Console.ReadLine()
End Sub
End Module

Derive la clase alumno

Public Class ALUMNO


Inherits PERSONA
Private Nota1 As Integer
Property NOTA As Integer
Get
NOTA = Nota1
End Get
Set(value As Integer)
Nota1 = value
End Set
End Property
End Class

Derive la clase Profesor de la clase persona

Public Class PROFESOR


Inherits PERSONA
Private SUELDO1 As Single
Property SUELDO As Single
Get
SUELDO = SUELDO1
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -25

End Get
Set(value As Single)
SUELDO1 = value
End Set
End Property
End Class

Diagrama de clases

Clases del lunes 09 de abril del 2018


Clase persona

Public Class Persona


Private nombre1 As String
Private 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
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -26

'Return dni
End Get
Set(value As Integer)
dni1 = value
End Set
End Property
Sub New(Optional nombre2 As String = "FULANO",
Optional DNI2 As Integer = 0)
nombre1 = nombre2
dni1 = DNI2
End Sub
Protected Overrides Sub Finalize()
Console.WriteLine(" OBJETO DESTRUIDO")
End Sub
Sub MostrarDatos()
Console.WriteLine(" {0}{1}{2} ", nombre1, vbTab, dni1)
End Sub
End Class

Implementación de la clase persona


Module Module1
Dim objeto1, objeto2, objeto3 As Persona
Sub Main()
objeto1 = New Persona()
objeto2 = New Persona("zutano")
objeto3 = New Persona("mengano", 23)
objeto1.MostrarDatos()
objeto2.MostrarDatos()
objeto3.MostrarDatos()
objeto3.dni = 123
objeto3.nombre = "JUAN PEREZ"
Console.WriteLine("MODIFICADO")
objeto3.MostrarDatos()
Console.ReadLine()
End Sub
End Module

tarea ‘ generar 100 objetos de personas cuyo nombres sean nombre1 2,3,99 y sus dni
aleatorios
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -27

Module Module1
Const N As Integer = 10
Dim A(N) As Persona
Sub Main()
Dim fila As Integer
For fila = 0 To N - 1
A(fila) = New Persona("persona" & fila, Int(Rnd() * 1000000))
Next
For fila = 0 To N - 1
A(fila).MostrarDatos()
Next
Console.ReadLine()
End Sub
End Module

1. Los nombres son letras aleatorias

Module Module1
Const N As Integer = 10
Dim A(N) As Persona
Dim nletras = 5
Sub Main()
Randomize()
Dim fila, col As Integer
Dim cadena As String
For fila = 0 To N - 1
Dim letra As String
cadena = ""
For col = 1 To 5
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -28

letra = Chr(65 + Int(Rnd() * 20))


cadena = cadena + letra
Next
A(fila) = New Persona(cadena, Int(Rnd() * 1000000))
Next
For fila = 0 To N - 1
A(fila).MostrarDatos()
Next
Console.ReadLine()
End Sub
End Module

1. Ingrese n nombres y que luego los muestre

Module Module1
Dim N As Integer
Dim A(100) As Persona
Sub Main()
' instancio
Console.Write(" CUANTOS DATOS QUIERE INGRESAR ")
N = Console.ReadLine
For fila = 0 To N - 1
A(fila) = New Persona()
Next
' ingreso
For fila = 0 To N - 1
Console.WriteLine(" ingrese nombre {0} ", fila)
A(fila).nombre = Console.ReadLine
Console.WriteLine(" ingrese DNI {0} ", fila)
A(fila).dni = Console.ReadLine
Next
'MUESTRA
Console.WriteLine("DATOS INGRESADOS")
For fila = 0 To N - 1
A(fila).MostrarDatos()
Next
Console.ReadLine()
End Sub
End Module
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -29

Tarea. Ingrese los nombres de un archivo y dni de un archivo


2. que lo modifique y lo grabe
3. derive la clase alumno
4. derive la clase profesor
5. encuentre un listado de todos los alumnos aprobados
6. encuentre el promedio de sueldo de profesores
7. los datos que lea del excel y tambien que grabe para execel
8. hacer to eso en modo formulario

Solución de practica del dia 10 de abril del 2018

Public Class PERSONA


Private Nombre1 As String
Private 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
Set(value As Integer)
DNI1 = value
End Set
End Property
Sub New(Optional NOMBRE2 As String = "FULANO", Optional DNI2 As Integer = 0)
Nombre1 = NOMBRE2
DNI1 = DNI2
End Sub
Sub FINALIZE()
Console.WriteLine(" OBJETO DESTRUIDO")
End Sub
Sub MostrarDatos()
Console.WriteLine("{0}{1}{2}", Nombre1, vbTab, DNI1)
End Sub
End Class

APLICACIÓN de la clase persona

Module Module1
Dim Juan, pedro, lucas As PERSONA
Sub Main()
Juan = New PERSONA()
pedro = New PERSONA("pedro")
lucas = New PERSONA("LUCAS", 234)
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -30

Juan.NOMBRE = "juan perez"


pedro.MostrarDatos()
lucas.MostrarDatos()
lucas.DNI = 8888
lucas.MostrarDatos()
Console.ReadLine()
End Sub
End Module

Genere aleatoriamente lo dnis y elabore un listado como la mostrada


Module Module1
Const N As Integer = 20
Dim A(N) As PERSONA
Sub Main()
For fila = 0 To N - 1
A(fila) = New PERSONA("nombre " & fila, Int(Rnd() * 100000))
Next
Console.WriteLine("mostrando datos")
For fila = 0 To N - 1
A(fila).MostrarDatos()
Next
Console.ReadLine()
End Sub
End Module

Ingrese n datos de personas y que luego los muestre


Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -31

Module Module1
Const N As Integer = 20
Dim A(N) As PERSONA
Dim Cadena, letra As String
Dim np As Integer
Sub Main()
Console.Write(" cuantas personas son")
np = Console.ReadLine
' instanciando
For fila = 0 To np - 1
A(fila) = New PERSONA()
Next
Console.WriteLine("lectura de datos")
For fila = 0 To np - 1
Console.Write("nombre {0} ", fila)
A(fila).NOMBRE = Console.ReadLine
Console.Write("dni {0} ", fila)
A(fila).DNI = Console.ReadLine
Next
Console.WriteLine("mostrando datos")
For fila = 0 To np - 1
A(fila).MostrarDatos()
Next
Console.ReadLine()
End Sub
End Module

Leer los datos de un archivo de texto

Imports System.IO
Module Module1
Dim A(100) As PERSONA
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -32

Dim cont As Integer


Sub Main()
Dim Archivo As StreamReader
Archivo = New StreamReader("F:\DATOS\PERSONAS.txt")
Dim Cadena, cadnombre, cadni As String
Dim pos As Integer
Console.WriteLine("lectura de archivos")
Cadena = Archivo.ReadLine()
cont = 0
Do While Not (Cadena Is Nothing)
pos = InStr(Cadena, vbTab)
cadnombre = Mid(Cadena, 1, pos - 1)
cadni = Mid(Cadena, pos + 1)
A(cont) = New PERSONA()
A(cont).NOMBRE = cadnombre
A(cont).DNI = Val(cadni)
cont = cont + 1
' Console.WriteLine(Cadena)
Cadena = Archivo.ReadLine()
Loop
Archivo.Close()
Console.WriteLine("OBJETOS CREADOS Y ASIGNADOS")
For FILA = 0 To cont - 1
A(FILA).MostrarDatos()
Next
Console.ReadLine()
End Sub
End Module

Practicas de Sistemas de Informacion martes 10 de Abril del 2018


Turno de 17:30 a 19:10 Leer datos de un archivo y asignar objetos
1. implementar la clase persona de acuerdo a la siguiente estructura
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -33

2.usando esa clase genere 3 objetos , uno sin parámetros, otros con un parámetro, y
otro con dos parámetros
3. genere 100 objetos donde el nombre de 5 letras generados en forma aleatoria y su
dni también con números de hasta 8 digitos
4. ingres n nombres y su dnis por teclado y que luego los muestre
5 lo mis mismo que la pregutna 4 pero de el ingreso es de archivos

Public Class PERSONA


Private nombre1 As String
Private dni1 As String
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
Set(value As Integer)
dni1 = value
End Set
End Property
Sub New(Optional NOMBRE2 As String =
"FULANO", _
Optional DNI2 As Integer = 0)
nombre1 = NOMBRE2
dni1 = DNI2
End Sub
Sub MostrarDatos()
Console.WriteLine(" {0}{1} ", nombre1, vbTab, dni1)
End Sub
Sub finalize()
Console.WriteLine("objeto destruido ")
End Sub
End Class

Implementacion de la clase persona


Module Module1
Dim Juan, pedro, luis As PERSONA
Sub Main()
Juan = New PERSONA()
pedro = New PERSONA("Pedro")
luis = New PERSONA("luis", 123)
Juan.MostrarDatos()
pedro.MostrarDatos()
luis.MostrarDatos()
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -34

luis.Nombre = "luis miguel"


Console.ReadLine()
End Sub
End Module

El nombre de la persona tiene 4 letras que se genera aleatoriamente y el DNI se


genera aleatoriamente con un numero de 8 cifras

Module Module1
Const N As Integer = 20
Dim A(N) As PERSONA
Dim cadena, letra As String
Sub Main()
Randomize()
Dim fila, COL As Integer
For fila = 0 To N - 1
cadena = ""
For COL = 1 To 4
letra = Chr(65 + Int(Rnd() * 20))
cadena = cadena + letra
Next
A(fila) = New PERSONA(cadena, Int(Rnd() * 10000000))
Next
For fila = 0 To N - 1
A(fila).MostrarDatos()
Next
Console.ReadLine()
End Sub
End Module
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -35

Leer n datos para asignarlos a los objetos de la clase persona y luego


mostrarlos

Module Module1
Const N As Integer = 20
Dim A(N) As PERSONA
Dim np As Integer
Sub Main()
Dim fila As Integer
Console.Write(" cuantos datos son ")
np = Console.ReadLine
Console.WriteLine(" primero instanciamos")
For fila = 0 To np - 1
A(fila) = New PERSONA()
Next
Console.WriteLine(" luego leemos")
For fila = 0 To np - 1
Console.Write(" nombre {0} ", fila)
A(fila).Nombre = Console.ReadLine
Console.Write(" DNI {0} ", fila)
A(fila).Dni = Console.ReadLine
Next
Console.WriteLine(" luego MOSTRAMOS")
For fila = 0 To np - 1
A(fila).MostrarDatos()
Next
Console.ReadLine()
End Sub
End Module

1. derive la clase alumno que tiene su propiedad nota y la clase profesor que tiene
su propiedad sueldo
2. liste los alumnos aprobados con su nombre y su notas
3. encuentre el promedio de sueldo de profesores
4. lo mismo pero en windows form

Clases y objetos en Windows form


Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -36

Derivación de la Clase alumno de la clase persona


Public Class alumno
Inherits persona
Private nota1 As Integer
Property nota As Integer
Get
nota = nota1
End Get
Set(value As Integer)
nota1 = value
End Set
End Property
End Class

Derivación de la Clase Profesor de la clase persona


Public Class profesor
Inherits persona
Private sueldo1 As Single
Property sueldo As Single
Get
sueldo = sueldo1
End Get
Set(value As Single)
sueldo1 = value
End Set
End Property
End Class
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -37

Leer lo datos de un archivo de texto y asignarlos a los objetos de clase alumnos los
nombres y las notas

Imports System.IO
Module Module1
Const na As Integer = 1000
Dim A(na) As alumno
Sub main()
Dim srLector As StreamReader = New StreamReader("F:\DATOS\ALUMNOS.txt")
Dim Linea, nombre As String
Dim pos, nota, nobj, fila As Integer
Dim cont As Integer
Console.WriteLine("lectura de archivos")
Linea = srLector.ReadLine()
Do While Not (Linea Is Nothing)
A(cont) = New alumno()
pos = InStr(Linea, vbTab)
nombre = Mid(Linea, 1, pos - 1)
nota = CInt(Mid(Linea, pos + 1))
A(cont).nombre = nombre
A(cont).nota = nota
' Console.WriteLine(Linea)
Linea = srLector.ReadLine()
cont = cont + 1
Loop
nobj = cont
Console.WriteLine("los objetos leidos son ")
For fila = 0 To nobj - 1
Console.WriteLine(" {0} {1} {2}", A(fila).nombre, vbTab, A(fila).nota)
Next
Console.ReadLine()
End Sub
End Module

Practicas SI del martes 17 de abril del 2018

Se tiene las clases persona, alumnos, profesor que tienen la siguiente estructura
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -38

Derivación de la clase Alumno de la clase Persona


Public Class ALUMNO
Inherits PERSONA
Protected nota1 As Integer
Property nOTA As Integer
Get
nOTA = nota1
End Get
Set(value As Integer)
nota1 = value
End Set
End Property
End Class

Derivación de la clase Profesor de la clase Persona


Public Class PROFESOR
Inherits PERSONA
Private Sueldo1 As Single
Property Sueldo As Single
Get
Sueldo = Sueldo1
End Get
Set(value As Single)
Sueldo = Sueldo1
End Set
End Property
End Class
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -39

La siguiente aplicacion muestra como se muestra formularios y controles en tiempo


de ejecución

Public Class Form1


Private Sub btnForm1_Click(sender As Object, e As EventArgs) Handles
btnForm1.Click
Dim objetoForm1 As Form1
objetoForm1 = New Form1
objetoForm1.Show()
End Sub

Private Sub btnFromEstandar_Click(sender As Object, e As EventArgs) Handles


btnFromEstandar.Click
Dim objetoForm As Form
objetoForm = New Form
objetoForm.Show()
End Sub

Private Sub btnCrearBoton_Click(sender As Object, e As EventArgs) Handles


btnCrearBoton.Click
' Declaramos el objeto Button
Dim MiControl As New Button
' Declaramos un nombre al control (si queremos)
MiControl.Name = "btn1"
MiControl.Text = "Ejemplo de Botón"
MiControl.BackColor = Color.Green
MiControl.Top = 50
MiControl.Left = 50
MiControl.Width = 200
MiControl.Height = 50
' Añadimos el control al Formulario
Me.Controls.Add(MiControl)
End Sub
End Class

P1014. Crear dos controles en tiempo de Ejecucion


Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -40

Public Class form1


Inherits System.Windows.Forms.Form
Private lblNombre As New Label()
Private txtNombre As New TextBox()
Private WithEvents btnAceptar As New Button()
Private WithEvents btnCancelar As New Button()

Private Sub CrearControles(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
With lblNombre
.Text = "Nombre:"
.AutoSize = True
.Location = New Point(30, 40)
End With
With txtNombre
.Width = 150
.Location = New Point(100, 35)
End With
With btnAceptar
.Text = "&Aceptar"
.Location = New Point(30, 100)
.BackColor = Color.Aqua
End With
With btnCancelar
.Text = "&Cancelar"
.Location = New Point(180, 100)
End With
Me.Controls.Add(lblNombre)
Me.Controls.Add(txtNombre)
Me.Controls.Add(btnAceptar)
Me.Controls.Add(btnCancelar)
AddHandler btnAceptar.Click, AddressOf Saludo
AddHandler btnCancelar.Click, AddressOf Salir
End Sub

Private Sub Saludo(ByVal sender As Object, ByVal e As EventArgs)


MessageBox.Show("Hola " & txtNombre.Text, "Saludo", MessageBoxButtons.OK,
MessageBoxIcon.Exclamation)
End Sub
Private Sub Salir(ByVal sender As Object, ByVal e As EventArgs)
Me.Close()
End Sub
End Class

3. Creación de una matriz de controles. Crear controles en tiempo de ejecución


Ver la practica 3 de si
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -41

Public Class form1


Inherits System.Windows.Forms.Form
Dim cont As Integer
Dim pasoX As Integer = 80
Dim pasoY As Integer = 40
Dim N As Integer = 8
Dim valor As Boolean = True
Private Sub btnCrear_Click(sender As Object, e As EventArgs) Handles
btnCrear.Click
Dim objeto As New Form
Dim A(8, 8) As Button
Dim fila, col As Integer
objeto = New Form
objeto.Width = 700
objeto.Height = 400
objeto.Text = "formulario bones 8 x 8"
For fila = 0 To N - 1
For col = 0 To N - 1
A(fila, col) = New Button
A(fila, col).Top = fila * pasoY
A(fila, col).Left = col * pasoX
A(fila, col).Name = "boton" & fila & col
A(fila, col).Text = "boton " & fila & col
AddHandler A(fila, col).Click, AddressOf lclick
AddHandler A(fila, col).MouseEnter, AddressOf lenter
AddHandler A(fila, col).MouseLeave, AddressOf lleave
objeto.Controls.Add(A(fila, col))
Next
Next
objeto.Show()
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -42

End Sub
Private Sub lclick(ByVal sender As Object, ByVal e As EventArgs)
Dim l As Button = CType(sender, Button)
valor = Not valor
l.BackColor = System.Drawing.Color.FromArgb(255, 255, 0)
End Sub
Private Sub lenter(ByVal sender As Object, ByVal e As EventArgs) '' [b]handles
Button1.click, button2.click[/b]
Dim l As Button = CType(sender, Button)
l.BackColor = System.Drawing.Color.FromArgb(0, 255, 0)
End Sub
Private Sub lleave(ByVal sender As Object, ByVal e As EventArgs) '' [b]handles
Button1.click, button2.click[/b]
Dim l As Button = CType(sender, Button)
If valor Then
l.BackColor = System.Drawing.Color.FromArgb(0, 0, 255)
Else
l.BackColor = System.Drawing.Color.FromArgb(255, 0, 0)
End If
End Sub
End Class

Tarea de sistemas de información

1. Terminar la clase persona tanto en consola como en modo formulario


2. Modifique la clase que lea los datos de un archivo
3. Y que saque fotos por ejemplo
4. Control del Usuario de Windows
5. Trabajo de clases en Windows forms por ejemplo creación controles etc,
Ver pag 12 de practica 22
6 .presente una aplicación de eventos del mouse 8 implemente esa clase
Elaborar las practicas 12,3,4 de la guai de practicas
Ejemplo de letras que giran
brazo Robot articulado
interface visual basic con excel
Aplicaciones de graficos
Pluma
Pincel
Brocha
Imágenes
Datagridview

PRACTICAS DEL MIERCOLES 18 DE ABRIL DEL 2018


Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -43

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
Set(value As Integer)
dni1 = value
End Set
End Property
Protected Overrides Sub Finalize()
Console.WriteLine("objeto destruido")
End Sub
Sub New(Optional nombre2 As String = "fulano", Optional dni2 As Integer = 0)
nombre1 = nombre2
dni1 = dni2
End Sub
Sub MostrarDatos()
Console.WriteLine("{0}{1}{2}", nombre1, vbTab, dni1)
End Sub
End Class

Public Class PROFESOR


Inherits persona
Protected SUELDO1 As Single
Property SUELDO As Single
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -44

Get
SUELDO = SUELDO1
End Get
Set(value As Single)
SUELDO1 = value
End Set
End Property
End Class

Public Class alumno


Inherits persona
Private nota1 As Integer
Property nota As Integer
Get
nota = nota1
End Get
Set(value As Integer)
nota1 = value
End Set
End Property
End Class

Para un solo alumno


Module Module1
Dim A As New alumno
Sub Main()
Console.WriteLine(" ingrese nombre")
A.Nombre = Console.ReadLine
Console.WriteLine(" ingrese nota")
A.nota = Console.ReadLine
Console.WriteLine("datos ingresados")
A.MostrarDatosAlumno()

Console.ReadLine()
End Sub
End Module
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -45

Module Module1
Dim A(100) As alumno
Dim ca As Integer = 2
Sub Main()
Dim fila As Integer
Console.WriteLine("cuantos datos quieres ingresar")
ca = Console.ReadLine
For fila = 0 To ca - 1
A(fila) = New alumno
Console.WriteLine(" ingrese nombre")
A(fila).Nombre = Console.ReadLine
Console.WriteLine(" ingrese nota")
A(fila).nota = Console.ReadLine
Next
Console.WriteLine("datos ingresados")
For fila = 0 To ca - 1
A(fila).MostrarDatosAlumno()
Next
Console.ReadLine()
End Sub
End Module

Imports System.IO
Module Module1
Dim A(100) As alumno
Dim ca As Integer = 2
Sub Main()
Dim cadena, nombre As String
Dim nota, pos, cont As Integer
Dim Archivo As StreamReader
Archivo = New StreamReader("F:\datos\notas.txt")
cadena = Archivo.ReadLine
cont = 0
Do While Not (cadena Is Nothing)
pos = InStr(1, cadena, vbTab)
nombre = Mid(cadena, 1, pos - 1)
nota = CInt(Mid(cadena, pos + 1))
A(cont) = New alumno
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -46

A(cont).Nombre = Mid(cadena, 1, pos - 1)


A(cont).nota = nota
cont = cont + 1
' Console.WriteLine(cadena)
cadena = Archivo.ReadLine
Loop
Archivo.Close()
ca = cont
For fila = 0 To ca - 1
A(fila).MostrarDatosAlumno()
Next
Console.ReadLine()
End Sub
End Module

Practica 5 en la semana lunes 23 al miércoles 25 abril del 2018


CREACION DE BASE DE DATOS,- Siga las instrucciones de la practica 4

Practica 6 en la semana lunes 30 de abril al miércoles 02 mayo del 2018


SQL Siga las instrucciones de la guía de practica 5

Practica 7 en la semana lunes 7 de mayo al miércoles 09 mayo del 2018


Ejercicios a realizar

Asistencia al laboratorio 10 puntos (las dos horas)


Se revisará
1. Tener su base de datos alumnos o crearlo al instante (1 punto)
2. Demostrar que ha practicado los ejercicios de las practicas 4 y 5 con la base de
datos alumnos. Debe crearlo con sql (3 punto)
3. Demostrar que ha practicado los ejercicios de los documentos de
ejerciciosSQL.PDF enviado(1 )
4. Demostrar que ha practicado con la base de datos NORTHWIND.MDF o
AdventureWorksDW_Data.md(1)
5. Demostrar que ha practicado con la base de datos en Access o excel (1 punto)
6. Presentar base de datos de su sistema libre y jugar con ello (2 punto)
7. Trasladar datos una aplicación a otra aplicación Ejemplo de acceso a SQL Server
de Excel a acceso de Excel a SQL Server, etc.

AYUDA
Sugerencia como hacer su sistema sencillo Ejemplo tengo un base de datos
llamado Tienda que tiene las siguientes tablas

PRODUCTOS
CODPRODUCTO NOMBREPRODUCTO presentacion Pu
P1 Arroz saco 130
P2 Azucar saco 120
P3 Fideos bolsa 50
P4 galletas Caja 30
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -47

VENTAS
NRO fechaVenta CodProducto Cantidad Monto Cliente
1 2/05/2018 P1 2 260 C1
2 3/05/2018 P2 3 360 C1
3 3/05/2018 P1 10 1300 C2
4 3/05/2018 P3 3 500 C3

CLIENTES
CODCLI NOMBRECLI
JUAN
C1 PEREZ
PEDRO
C2 RIOS
C3 MARIA
C4 JOSE

Crear la base de datos tienda


Para la base de datos siga los pasos de la guía 4

Par las tablas


Creando la tabla productos

CREATE TABLE PRODUCTOS


(CodProducto varchar(5),
NombreProducto varchar(50),
Presentacion varchar(30),
Pu money,
primary key (CodProducto)
)

Tabla ventas
CREATE TABLE Ventas
(Nro int ,
FechaVenta date,
CodProducto varchar(5),
Cantidad int,
Monto money,
CodCli varchar(5),
primary key (nro)
)

Tabla clientes

CREATE TABLE Clientes


(CodCli varchar(5) ,
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -48

NombreCli varchar(50),
primary key (CodCli)
)

El resultado debe ser lo siguiente

Llenando la tabla productos

INSERT INTO PRODUCTOS (Codproducto, NombreProducto, Presentacion, Pu)


values('P1','Arroz','Saco',130);
INSERT INTO PRODUCTOS (Codproducto, NombreProducto, Presentacion, Pu)
values('P2','Azucar','Saco',150);
INSERT INTO PRODUCTOS (Codproducto, NombreProducto, Presentacion, Pu)
values('P3','Fideos','Bolsa',40);
INSERT INTO PRODUCTOS (Codproducto, NombreProducto, Presentacion, Pu)
values('P4','Galletas','Caja',30);

llenando la tabla ventas

INSERT INTO VENTAS (Nro,FechaVenta,CodProducto,Cantidad,Monto,CodCli)


values(1,'2/05/2018','P1',2,260,'C1');
INSERT INTO VENTAS (Nro,FechaVenta,CodProducto,Cantidad,Monto,CodCli)
values(2,'2/05/2018','P2',3,450,'C1');
INSERT INTO VENTAS (Nro,FechaVenta,CodProducto,Cantidad,Monto,CodCli)
values(3,'3/05/2018','P1',10,1300,'C2');
INSERT INTO VENTAS (Nro,FechaVenta,CodProducto,Cantidad,Monto,CodCli)
values(4,'4/05/2018','P3',3,400,'C3');

Llenando la tabla clients

INSERT INTO CLIENTES (CodCLi,NombreCli) values('C1','JUAN PEREZ');


INSERT INTO CLIENTES (CodCLi,NombreCli) values('C2','PEDRO RIOS');
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -49

INSERT INTO CLIENTES (CodCLi,NombreCli) values('C3','MARIA');


INSERT INTO CLIENTES (CodCLi,NombreCli) values('C4','JOSE');

REALIZANDO LAS CONSULTAS EN LA BASE DE DATOS ( JUGANDO CON LA


BASE DE DATOS TIENDA)

Diagrama como hacerlo en la practica 5


Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -50

CONSULTAS (JUEGUE CON SU BASE DE DATOS)

CONSULTA 1
SELECCIONAR CAMPOS

SELECT * FROM PRODUCTOS

Resultado

CodProducto NombreProducto Presentacion Pu


P1 Arroz Saco 130
P2 Azucar Saco 150
P3 Fideos Bolsa 40
P4 Galletas Caja 30

Definir campos calculados

Suponiendo que se tiene un descuento de 10% en los productos cual seria el precio de
oferta

SELECT NombreProducto, Pu, pu*0.9 as precioOferta FROM PRODUCTOS

se puede trabajar sin tablas


select pi() as valorPI
3.14159265358979

5.7 Encabezados de columna


select Codcli as codigo_cliente , nombrecli from clientes
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -51

codigo_cliente nombrecli
C1 JUAN PEREZ
C2 PEDRO RIOS
C3 MARIA
C4 JOSE

5.8 Ordenar las filas


SELECT * FROM PRODUCTOS ORDER BY NombreProducto ASC, PU DESC

5.9 Incluir criterios de búsqueda (Seleccionar filas)


Seleccionar todos los registros de la table ventas cuyas ventas son mayores que 1000

SELECT * FROM VENTAS WHERE MONTO >=1000

Listar todos los nombres de los productos cuya presentación es en saco

SELECT nombreproducto FROM Productos WHERE Presentacion ='saco';


SELECT nombreproducto FROM Productos WHERE Presentacion like 'saco';

Coincidencia de patrones

Listar los nombres de los productos que contengan la letra A

SELECT * from productos where NombreProducto like '%A%'

El operador Entre (Between


13 El operador In : (Inclusión) y not in

5.14 LAS CONSULTAS DE RESUMEN


Calcular los totales de la table ventas

select count (*) as cant, count(monto) ,sum(monto) as total,


Avg(Monto) As Promedio , Max(Monto) As Maximo,
Min(Monto) as Minimo , STDEV (MONTO) AS desviacion,
STDEVp (MONTO) AS desviacion FROM ventas

5.15 Agrupar registros


Obtener subtototales por codproducto
select codproducto ,count (*) as cant,sum(monto) as total,
Avg(Monto) As Promedio , Max(Monto) As Maximo,
Min(Monto) as Minimo , STDEV (MONTO) AS desviacion,
STDEVp (MONTO) AS desviación FROM ventas group by codproducto
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -52

HAVING .- tiene un efecto similar similar a WHERE , pero solo trabaja de acuerdo a los
resultados obtenidos por GROUP BY . Con la siguiente Instrucción

Lo Mismo que el anterior pero solo cuando los promedios son mayors que 500

select codproducto ,count (*) as cant,sum(monto) as total,


Avg(Monto) As Promedio , Max(Monto) As Maximo,
Min(Monto) as Minimo , STDEV (MONTO) AS desviacion,
STDEVp (MONTO) AS desviacion
FROM ventas group by codproducto having avg(monto)>= 500

LAS CONSULTAS MULTITABLA


Obtener la siguiente tabla

CON WHERE
SELECT A.CODPRODUCTO , NOMBREPRODUCTO, A.CODCLI,NOMBRECLI FROM
VENTAS A, PRODUCTOS B,CLIENTES C
WHERE A.CodProducto =B.CodProducto AND A.CodCli =C.CodCli

Combinar 3 tablas con INNER JOIN


SELECT C.CODPRODUCTO , NOMBREPRODUCTO, C.CODCLI,D.NOMBRECLI
FROM (SELECT
a.CodProducto, NOMBREPRODUCTO,codcli from ventas A
iNNER JOIN PRODUCTOS B ON A.CodProducto =B.CodProducto ) C
INNER JOIN CLIENTES D ON C.CodCli =d.CodCli

LA COMPOSICION EXTERNA
Obtener la siguiente table

select a.CodProducto,nombreproducto,b.total from productos A


left join (
Select codproducto,sum(monto) as total from ventas group by CodProducto) B
ON A.CodProducto =B.CODPRODUCTO
Practicas de laboratorio de Sistemas de Información 2018\Ismael Veliz Vilca -53

5.17 UNION.
EL OPERADOR UNION
5.18 LAS CONSULTAS DE REFERENCIAS CRUZADAS
5.19 FUNCIONES DE FECHA Y HORA
LAS CONSULTAS DE ACCIÓN
Ya visto
Crear una tabla en base a una consulta

5.24 Consultas de creación de tabla.( consultas que se almacenan en una tabla)

SELECT * FROM PRODUCTOS;

SELECT * INTO PRODUCTOS1 FROM PRODUCTOS


Creacion de tablas con create table (ya visto)

Inserter registros con una consulta

INSERT INTO productos1 ( codproducto,nombreproducto, presentacion, pu )


SELECT * FROM productos

Datos anexados con valore


s5.26 Consultas de actualización.
5.27 Consulta de eliminación
5.28 OPERACIONES DE MODIFICACIONES DE TABLAS
5.30 EJERCICIOS DE MODIFICACION DE TABLAS (CAMPOS) 373
SENTENCIA SQL AVANZADAS

También podría gustarte