You are on page 1of 55

Tecnologia de base de datos 2016B \9 Reportes parte 2 -1-

CONTROL CHART

EJERCICIO 1, listar los montos de la tabla pagos en Access

Imports System.Windows.Forms
Imports System.Windows.Forms.DataVisualization.Charting
Imports System.Data.OleDb
Imports System.Data
Imports System.Web.UI.DataVisualization.Charting
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim myConnectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=E:\DATOS\ALUMNOS.accdb"
' Define the database query.
Dim mySelectQuery As String = "SELECT nro, monto FROM PAGOS;"
' Create a database connection object using the connection string.
Dim myConnection As OleDbConnection = New
OleDbConnection(myConnectionString)
' Create a database command on the connection using query.
Dim myCommand As OleDbCommand = New OleDbCommand(mySelectQuery,
myConnection)
' Open the connection.
myCommand.Connection.Open()
' Create a database reader.
Dim myReader As OleDbDataReader =
myCommand.ExecuteReader(CommandBehavior.CloseConnection)
' Specify the Name column to be used for point's X values.
Chart1.DataBindTable(myReader, "Nro")
' Close the connection.
myConnection.Close()
' This is a loop to set all created charts appearance with custom attribute.
Dim series As Series
For Each series In Chart1.Series
series.CustomProperties = "DrawingStyle=LightToDark"
Next
End Sub
End Class
Tecnologia de base de datos 2016B \9 Reportes parte 2 -2-

EJERCICIO 2(explicativo)

Imports System.Windows.Forms
Imports System.Windows.Forms.DataVisualization.Charting
Public Class Form1
Sub graficar()
Chart1.Series.Clear()
'Crear la serie
Dim series As New Series("Poblacion")
Chart1.Series.Add(series)
series.ChartType = SeriesChartType.Column
Chart1.Series("Poblacion").Points.AddXY("Peru", 35)
Chart1.Series("Poblacion").Points.AddXY("Argentina", 50)
Chart1.Series("Poblacion").Points.AddXY("Bolivia", 28)
Chart1.Series("Poblacion").Points.AddXY("Brasil", 90)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Chart1.Dock = DockStyle.Fill
graficar()
End Sub
End Class
Tecnologia de base de datos 2016B \9 Reportes parte 2 -3-

EJEMPLO EXPLICATIVO DE GRAPH


Imports System.Windows.Forms
Imports System.Windows.Forms.DataVisualization.Charting
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Chart1.ChartAreas(0).Area3DStyle.Enable3D = True
Chart1.Series.Clear()
'Crear la serie
Dim series1 As New Series("Ingenierias")
Chart1.Series.Add(series1)
Dim series2 As New Series("Sociales")
Chart1.Series.Add(series2)
Dim series3 As New Series("Biomedicas")
Chart1.Series.Add(series3)
' series1.ChartType = SeriesChartType.Column
Chart1.Series(0).Points.AddXY("Primer Ao", 100)
Chart1.Series(0).Points.AddXY("Segundo Ao", 20)
Chart1.Series(0).Points.AddXY("Tercer Ao", 240)
Chart1.Series(0).Points.AddXY("Cuarto Ao", 30)
Chart1.Series(0).Points.AddXY("Quinto Ao", 50)
Chart1.Series(1).Points.AddXY("Primer Ao", 50)
Chart1.Series(1).Points.AddXY("Segundo Ao", 100)
Chart1.Series(1).Points.AddXY("Tercer Ao", 80)
Chart1.Series(1).Points.AddXY("Cuarto Ao", 120)
Chart1.Series(1).Points.AddXY("Quintor Ao", 130)
Chart1.Series(2).Points.AddXY("Primer Ao", 150)
Chart1.Series(2).Points.AddXY("Segundo Ao", 10)
Chart1.Series(2).Points.AddXY("Tercer Ao", 80)
Chart1.Series(2).Points.AddXY("Cuarto Ao", 10)
Chart1.Series(2).Points.AddXY("Quintor Ao", 13)
End Sub
End Class

Vea estas propiedades


Tecnologia de base de datos 2016B \9 Reportes parte 2 -4-

EJERCICIO PARA EXPLICAR EN LABORATORIO ( Miercoles 11 de enero del 2017)


Mostrar los subtotales y los maximo agrupados por codigo del alumno

Imports System.Windows.Forms
Imports System.Windows.Forms.DataVisualization.Charting
Imports System.Data.SqlClient
Public Class Form1
Dim CadenaConexion As String = "Data
Source=(LocalDB)\v11.0;AttachDbFilename=E:\datos1\ALUMNOS.mdf;Integrated
Security=True;Connect Timeout=30"
Dim con As New SqlConnection(CadenaConexion)
Dim dap As New SqlDataAdapter("Select * FROM pagos", con)
Dim dst As New DataSet
Dim Nf As Integer = 1
Dim nc As Integer
Dim A(50, 50) As String
Dim X(50) As String
Dim Y(50) As Single
Dim CadenaSQL As String
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
dap.Fill(dst, "Pagos")
DataGridView1.DataSource = dst.Tables(0)
Tecnologia de base de datos 2016B \9 Reportes parte 2 -5-

End Sub
Private Sub btnMostrarGraficos_Click(sender As Object, e As EventArgs) Handles
btnMostrarGraficos.Click
Dim fila, col, k As Integer
Form2.Chart1.Series.Clear()
Dim series(5) As Series
CadenaSQL = "SELECT CODALUMNO, SUM(MONTO) AS TOTAL, max(monto) as
max1,min(monto) as min1 FROM PAGOS GROUP BY CODALUMNO"
Dim series1 As New Series("Maximo ")
' Form2.Chart1.ChartAreas(0).Area3DStyle.Enable3D = True
dap.SelectCommand.CommandText = CadenaSQL
dst.Tables.Clear()
dap.Fill(dst, "Subtotales")
DataGridView1.DataSource = dst.Tables(0)
Nf = dst.Tables(0).Rows.Count
nc = dst.Tables(0).Columns.Count
For col = 0 To nc - 1
series(col) = New Series(dst.Tables(0).Columns(col).ColumnName)
series(col).ChartType = SeriesChartType.Column
Next
ReDim A(Nf - 1, nc - 1)
ReDim X(Nf - 1)
ReDim Y(Nf - 1)
For fila = 0 To Nf - 1
For col = 0 To nc - 1
A(fila, col) = dst.Tables(0).Rows(fila).Item(col)
Next
Next
'' tener la fila X que es para todos igual
For fila = 0 To Nf - 1
X(fila) = dst.Tables(0).Rows(fila).Item(0)
Next
For k = 1 To nc - 1
For fila = 0 To Nf - 1
Y(fila) = CSng(dst.Tables(0).Rows(fila).Item(k))
Next
series(k).Points.DataBindXY(X, Y)
Form2.Chart1.Series.Add(series(k))
Next
Form2.Text = CadenaSQL
Form2.Show()
End Sub
End Class

Modificar para que grafique cualquier consulta

EJERCICIO EXPLICATIVO ( para explicar en las practicas)

La siguiente aplicacin permite cargar un archivo de texto y de acuerdo a ello elaborar


un grafico de varias series puede hacer modificaciones en el grafico ( modificando los
valores de un datagridview )
Tecnologia de base de datos 2016B \9 Reportes parte 2 -6-

CodLumno N1 N2 N3
A1 10 11 12
A2 11 14 13
A3 20 18 18
A4 5 4 8
A5 11 12 12

La estructura del proyecto es

Codigo del modulo 1

Imports System.IO
Module MODULE1
Public NombreArchivo As String = "E:\datos\notas4x5.txt"
Public NombreArchivoGraba As String = "E:\datos\notas4x5Salida.txt"
Public Const maxfilas As Integer = 10
Public Const maxcol As Integer = 4
Public Matriz(maxfilas, maxcol) As String
Public Campos(maxcol) As String
Public nf As Integer = 5
Public nc As Integer = 4
Public anguloCuboX As Integer = 30 '-45
Public anguloCuboY As Integer = 30
Public anguloCuboZ As Integer = 30
Public VarAngulo As Integer = 10
Tecnologia de base de datos 2016B \9 Reportes parte 2 -7-

Public Tipo As Integer = 2


Public cont As Integer = 1
Public Modo3D As Integer = 0
Public ModoAleatorio As Integer = 0
Public ModoPalete As Integer = 0
Public Perspectiva As Integer = 0
Public ModoLuz As Integer = 0
Sub RecuperarMatriz(ByVal nombrearchivo As String, ByRef A(,) As String, ByVal nf As
Integer, ByVal 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
For fila = 0 To nf - 1
cadena = srLector.ReadLine()
cadena = cadena & Chr(9)
inicio = 1
For col = 0 To nc - 1
pos = InStr(inicio, cadena, Chr(9))
subcadena = Mid(cadena, inicio, pos - inicio)
A(fila, col) = subcadena
inicio = pos + 1
Next
Next
Console.WriteLine("Archivo leido satisfactoriamente")
srLector.Close()
End Sub
Sub MostrarMatriz(ByVal A(,) As String, ByVal nf As Integer, ByVal 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
Sub GrabarMatriz(NombreArchivo As String, ByVal A(,) As String, ByVal nf As Integer,
ByVal nc As Integer)
Dim fila, col As Integer
Dim Archivo As StreamWriter
Archivo = New StreamWriter(NombreArchivo)
For fila = 0 To nf - 1
For col = 0 To nc - 1
Archivo.Write("{0} {1}", A(fila, col), vbTab)
Next
Archivo.WriteLine()
Next
End Sub
Sub main()
Tecnologia de base de datos 2016B \9 Reportes parte 2 -8-

RecuperarMatriz(NombreArchivo, Matriz, nf, nc)


MostrarMatriz(Matriz, nf, nc)
Console.ReadLine()
End Sub
End Module

Cdigo del formulario

Imports System.Windows.Forms
Imports System.Windows.Forms.DataVisualization.Charting
Public Class Form1
Sub MostrarMatrizFormulario(ByVal A(,) As String, ByVal nf As Integer, ByVal nc As
Integer)
Dim fila, col As Integer
For col = 0 To nc - 1
DataGridView1.Columns(col).Width = 40
DataGridView1.Columns(col).HeaderText = A(0, col)
Next
For fila = 0 To nf - 1
For col = 0 To nc - 1
DataGridView1.Rows(fila).Cells(col).Value = A(fila + 1, col)
Next
Next
End Sub
Sub FormularioAmatriz(ByVal A(,) As String, ByVal nf As Integer, ByVal nc As Integer)
Dim fila, col As Integer
For col = 0 To nc - 1
DataGridView1.Columns(col).Width = 40
A(0, col) = DataGridView1.Columns(col).HeaderText
Next
For fila = 0 To nf - 1
For col = 0 To nc - 1
A(fila + 1, col) = DataGridView1.Rows(fila).Cells(col).Value
Next
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnAbrir.Click
RecuperarMatriz(NombreArchivo, Matriz, nf, nc)
DataGridView1.RowCount = nf
DataGridView1.ColumnCount = nc
MostrarMatrizFormulario(Matriz, nf, nc)
End Sub
Sub graficar(A(,) As String, nf As Integer, nc As Integer, tipo As Integer, _
Modo3D As Integer, AnguloX As Integer, AnguloY As Integer, AnguloZ As Integer, _
ModoPalete As Integer, perspectiva As Integer, ModoLuz As Integer)
Form2.Chart1.Series.Clear()
Dim series(nc) As Series
Dim col As Integer
For col = 0 To nc - 1
series(col) = New Series(A(0, col))
Form2.Chart1.Series.Add(series(col))
Form2.Chart1.Series(col).ChartType = tipo
Tecnologia de base de datos 2016B \9 Reportes parte 2 -9-

Next
Form2.Chart1.ChartAreas(0).Area3DStyle.Enable3D = Modo3D
Form2.Chart1.ChartAreas(0).Area3DStyle.Inclination = AnguloX ' eje x
Form2.Chart1.ChartAreas(0).Area3DStyle.Rotation = AnguloY ' eje x
Form2.Chart1.ChartAreas(0).Area3DStyle.PointDepth = AnguloZ ' eje z
Form2.Chart1.Palette = ModoPalete
Form2.Chart1.ChartAreas(0).Area3DStyle.Perspective = perspectiva
Form2.Chart1.ChartAreas(0).Area3DStyle.LightStyle = ModoLuz
For fila = 1 To nf - 1
For col = 0 To nc - 2
Form2.Chart1.Series(col).Points.AddXY(A(fila, 0), CInt(A(fila, col + 1)))
Next
Next
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim fila As Integer
For fila = 0 To 34
Form2.Chart1.Series(0).ChartType = fila
ComboBox1.Items.Add(fila & " " & Form2.Chart1.Series(0).ChartType.ToString)
Next
ComboBox1.SelectedIndex = 1
Form2.Show()
End Sub

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


btnGraficar.Click
graficar(Matriz, nf, nc, Tipo, Modo3D, anguloCuboX, anguloCuboY, anguloCuboZ,
ModoPalete, Perspectiva, ModoLuz)
End Sub
Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles
btnModificar1.Click
FormularioAmatriz(Matriz, nf, nc)
graficar(Matriz, nf, nc, Tipo, Modo3D, anguloCuboX, anguloCuboY, anguloCuboZ,
ModoPalete, Perspectiva, ModoLuz)
End Sub
Private Sub btnModificar_Click(sender As Object, e As EventArgs) Handles
btnModificar.Click
graficar(Matriz, nf, nc, Tipo, Modo3D, anguloCuboX, anguloCuboY, anguloCuboZ,
ModoPalete, Perspectiva, ModoLuz)
End Sub

Private Sub BtnIniciar_Click(sender As Object, e As EventArgs) Handles BtnIniciar.Click


DataGridView2.ColumnCount = 2
DataGridView2.RowCount = 11
DataGridView2.Columns(0).Width = 120
DataGridView2.Columns(1).Width = 40
Dim fila As Integer
For fila = 0 To DataGridView2.RowCount - 1
DataGridView2.Rows(fila).HeaderCell.Value = fila.ToString
Next
DataGridView2.Columns(0).HeaderText = "PROPIEDAD"
DataGridView2.Columns(1).HeaderText = "Valor"
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 10 -

DataGridView2.Rows(0).Cells(0).Value = "ROT X"


DataGridView2.Rows(0).Cells(1).Value = anguloCuboX
DataGridView2.Rows(1).Cells(0).Value = "ROT Y"
DataGridView2.Rows(1).Cells(1).Value = anguloCuboY
DataGridView2.Rows(2).Cells(0).Value = "Prof z"
DataGridView2.Rows(2).Cells(1).Value = anguloCuboZ
DataGridView2.Rows(3).Cells(0).Value = "Var "
DataGridView2.Rows(3).Cells(1).Value = VarAngulo

DataGridView2.Rows(4).Cells(0).Value = "3D 1=SI 0= NO"


DataGridView2.Rows(4).Cells(1).Value = Modo3D
DataGridView2.Rows(5).Cells(0).Value = "tipo"
DataGridView2.Rows(5).Cells(1).Value = Tipo
DataGridView2.Rows(6).Cells(0).Value = "Palete 0-10"
DataGridView2.Rows(6).Cells(1).Value = ModoPalete
DataGridView2.Rows(7).Cells(0).Value = "Perpectiva 0-100 "
DataGridView2.Rows(7).Cells(1).Value = Perspectiva
DataGridView2.Rows(8).Cells(0).Value = "Modo Luz "
DataGridView2.Rows(8).Cells(1).Value = ModoLuz
DataGridView2.Rows(9).Cells(0).Value = "Nfilas "
DataGridView2.Rows(9).Cells(1).Value = nf
DataGridView2.Rows(10).Cells(0).Value = "N Col "
DataGridView2.Rows(10).Cells(1).Value = nc
End Sub
Sub Obtener()
anguloCuboX = DataGridView2.Rows(0).Cells(1).Value
anguloCuboY = DataGridView2.Rows(1).Cells(1).Value
anguloCuboZ = DataGridView2.Rows(2).Cells(1).Value
VarAngulo = DataGridView2.Rows(3).Cells(1).Value
Modo3D = DataGridView2.Rows(4).Cells(1).Value
Tipo = DataGridView2.Rows(5).Cells(1).Value
ModoPalete = DataGridView2.Rows(6).Cells(1).Value
Perspectiva = DataGridView2.Rows(7).Cells(1).Value
ModoLuz = DataGridView2.Rows(8).Cells(1).Value
End Sub
Private Sub btnObtener_Click(sender As Object, e As EventArgs) Handles
btnObtener.Click
Obtener()
FormularioAmatriz(Matriz, nf, nc)
graficar(Matriz, nf, nc, Tipo, Modo3D, anguloCuboX, anguloCuboY, anguloCuboZ,
ModoPalete, Perspectiva, ModoLuz)
End Sub
Private Sub txtRot_KeyDown(sender As Object, e As KeyEventArgs) Handles
txtRot.KeyDown
anguloCuboX = DataGridView2.Rows(0).Cells(1).Value
anguloCuboY = DataGridView2.Rows(1).Cells(1).Value
anguloCuboZ = DataGridView2.Rows(2).Cells(1).Value
Select Case e.KeyCode
Case Keys.Right, Keys.X ' fflecha derecha rota al rededdor del x
If anguloCuboX + VarAngulo < 90 Then
anguloCuboX = anguloCuboX + VarAngulo
End If
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 11 -

Case Keys.Left, Keys.A ' fflecha izquierdaderecha rota al rededdor del x


If anguloCuboX - VarAngulo > -90 Then
anguloCuboX = anguloCuboX - VarAngulo
End If
Case Keys.Up, Keys.Y ' flecha arriba a al rededdor del y
If anguloCuboY + VarAngulo < 180 Then
anguloCuboY = anguloCuboY + VarAngulo
End If
Case Keys.Down, Keys.B ' flecha arriba a al rededdor del y
If anguloCuboY - VarAngulo > -180 Then
anguloCuboY = anguloCuboY - VarAngulo
End If
Case Keys.PageUp, Keys.Z ' pagina arriba giro alrededor del eje z
If anguloCuboZ + VarAngulo < 1000 Then
anguloCuboZ = anguloCuboZ + VarAngulo
End If
Case Keys.PageDown, Keys.C ' pagina arriba giro alrededor del eje z
If anguloCuboZ - VarAngulo > 0 Then
anguloCuboZ = anguloCuboZ - VarAngulo
End If
End Select
DataGridView2.Rows(0).Cells(1).Value = anguloCuboX
DataGridView2.Rows(1).Cells(1).Value = anguloCuboY
DataGridView2.Rows(2).Cells(1).Value = anguloCuboZ
txtRot.Text = ""
btnObtener_Click(sender, e)
End Sub
End Class

Si reemplazamos con este archivo si tendra el siguiente resultado, pruebe con otros
valores
LONGITUD -71,46 -71,459 -71,458 -71,457 -71,456 -71,455 -71,454 -71,453 -71,452 -71,451 -71,45 -71,449 -71,448 -71,447 -71,446 -71,445 -71,444 -71,443 -71,442 -71,441 -71,44
0 -16,26 3257 3228 3212 3210 3207 3156 3104 3085 3094 3101 3076 3061 3068 3059 3074 3089 3078 3042 3025 3053 3115
1 -16,261 3226 3210 3198 3193 3180 3131 3083 3051 3038 3035 3021 3015 3017 3010 3018 3027 3027 3027 3036 3072 3127
2 -16,262 3206 3199 3187 3171 3145 3091 3048 3017 2992 2987 2986 2991 2996 3001 3019 3030 3038 3047 3064 3092 3129
3 -16,263 3195 3188 3166 3133 3090 3045 3007 2983 2979 2992 2998 2998 3001 3016 3035 3051 3068 3080 3095 3117 3139
4 -16,264 3185 3173 3131 3085 3037 3004 2981 2971 2990 3015 3026 3025 3033 3047 3071 3111 3148 3155 3169 3190 3202
5 -16,265 3172 3164 3112 3057 3009 2986 2971 2967 2991 3021 3036 3052 3076 3116 3162 3206 3236 3254 3269 3285 3298
6 -16,266 3151 3145 3105 3046 2999 2977 2969 2969 3000 3029 3064 3101 3139 3193 3238 3273 3305 3330 3352 3365 3367
7 -16,267 3128 3100 3070 3036 3008 2978 2963 2980 3027 3060 3106 3154 3178 3207 3258 3313 3351 3381 3410 3427 3432
8 -16,268 3116 3085 3074 3058 3030 2983 2963 2990 3040 3087 3143 3197 3226 3233 3266 3316 3360 3399 3434 3461 3488
9 -16,269 3111 3098 3085 3060 3022 2966 2968 3004 3055 3112 3176 3228 3262 3288 3311 3323 3340 3383 3438 3482 3523
10 -16,27 3111 3097 3077 3050 2991 2949 2979 3022 3075 3125 3181 3230 3279 3344 3385 3376 3359 3379 3429 3492 3551
11 -16,271 3096 3082 3064 3041 2996 2945 2974 3027 3082 3137 3186 3234 3304 3383 3430 3432 3437 3435 3436 3483 3553
12 -16,272 3090 3083 3076 3053 2996 2946 2968 3027 3090 3153 3210 3275 3350 3420 3469 3495 3508 3495 3470 3481 3535
13 -16,273 3088 3086 3081 3041 2970 2942 2986 3056 3122 3193 3269 3341 3401 3459 3517 3564 3586 3562 3520 3503 3519
14 -16,274 3094 3134 3060 3011 2951 2958 3024 3096 3168 3256 3342 3400 3449 3508 3573 3627 3662 3630 3586 3561 3557
15 -16,275 3113 3065 3007 2965 2952 2998 3063 3132 3233 3332 3406 3456 3414 3572 3624 3673 3707 3688 3657 3640 3634
16 -16,276 3105 3025 2965 2941 2976 3038 3101 3195 3301 3394 3483 3528 3569 3616 3670 3726 3765 3755 3730 3714 3707
17 -16,277 3083 2988 2937 2938 3000 3071 3141 3236 3335 3426 3516 3580 3619 3656 3705 3762 3818 3829 3814 3796 3786
18 -16,278 3029 2954 2920 2941 3004 3080 3157 3230 3324 3408 3496 3571 3627 3702 3753 3801 3852 3891 3900 3887 3877
19 -16,279 2985 2926 2916 2950 3014 3095 3157 3225 3312 3379 3470 3558 3636 3745 3814 3853 3892 3935 3962 3967 3972
20 -16,28 2987 2913 2918 2972 3038 3099 3155 3213 3285 3367 3460 3546 3618 3717 3807 3865 3907 3947 3978 4005 4035
21 -16,281 2972 2905 2940 3008 3070 3119 3166 3209 3267 3356 3447 3535 3603 3688 3787 3857 3907 3944 3977 4020 4061

Si se quita el minimo valor se tendra el siguiente resultado


Tecnologia de base de datos 2016B \9 Reportes parte 2 - 12 -

Con estos datos se obtiene el siguiente resultado


Fc 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1
3 1 2 1 2 2 2 2 2 2 1 1 4 4 4 4 4 4 1 2 1
4 1 2 1 2 3 3 3 3 2 1 1 4 5 5 5 5 4 1 2 1
5 1 2 1 2 3 2 2 3 2 1 1 4 5 2 2 5 4 1 2 1
6 1 2 1 2 3 2 2 3 2 1 1 4 5 2 2 5 4 1 2 1
7 1 2 1 2 3 3 3 3 2 1 1 4 5 5 5 5 4 1 2 1
8 1 2 1 2 2 2 2 2 2 1 1 4 4 4 4 4 4 1 2 1
9 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1
10 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1
11 1 2 1 2 2 2 2 2 2 1 1 6 6 6 6 6 6 1 2 1
12 1 2 1 2 3 3 3 3 2 1 1 6 7 7 7 7 6 1 2 1
13 1 2 1 2 3 2 2 3 2 1 1 6 7 6 6 7 6 1 2 1
14 1 2 1 2 3 2 2 3 2 1 1 6 7 6 6 7 6 1 2 1
15 1 2 1 2 3 3 3 3 2 1 1 6 7 7 7 7 6 1 2 1
16 1 2 1 2 2 2 2 2 2 1 1 6 6 6 6 6 6 1 2 1
17 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1
18 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1
19 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1

Elabore una simulacin usando este control (por ejemplo el juego de la vida)

Imports System.Windows.Forms
Imports System.Windows.Forms.DataVisualization.Charting
Imports System.Data.SqlClient
Public Class Form1
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 13 -

Dim CadenaConexion As String = "Data


Source=(LocalDB)\v11.0;AttachDbFilename=E:\datos1\ALUMNOS.mdf;Integrated
Security=True;Connect Timeout=30"
Dim con As New SqlConnection(CadenaConexion)
Dim dap As New SqlDataAdapter("Select * FROM pagos", con)
Dim dst As New DataSet
Dim Nf As Integer = 1
' Dim nc As Integer = 1
Dim X(50) As String
Dim Y(50) As Single
Dim CadenaSQL As String

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


dap.Fill(dst, "Pagos")
DataGridView1.DataSource = dst.Tables(0)
End Sub
Private Sub btnMostrarGraficos_Click(sender As Object, e As EventArgs) Handles
btnMostrarGraficos.Click
Dim fila As Integer
Form2.Chart1.Series.Clear()
Dim series As New Series("SubTotales ")
series.ChartType = SeriesChartType.Column
' Form2.Chart1.ChartAreas(0).Area3DStyle.Enable3D = True
dap.SelectCommand.CommandText = "SELECT CODALUMNO, SUM(MONTO) AS
TOTAL FROM PAGOS GROUP BY CODALUMNO"
dst.Tables.Clear()
dap.Fill(dst, "Subtotales")
DataGridView1.DataSource = dst.Tables(0)
Nf = dst.Tables(0).Rows.Count
ReDim X(Nf - 1)
ReDim Y(Nf - 1)
For fila = 0 To Nf - 1
X(fila) = dst.Tables(0).Rows(fila).Item(0)
Y(fila) = dst.Tables(0).Rows(fila).Item(1)
Next
series.Points.DataBindXY(X, Y)
'series.Points.DataBindXY(dst)
Form2.Chart1.Series.Add(series)
Form2.Show()
End Sub
End Class

EJERCICIO 2 . ( MODIFICACION CON BASE DE DATOS)

El siguiente ejercicio muestra una consulta en SQL y puede escoger subtotales por un
campo y el tipo de grafico en forma manual y forma automtica tambin puede hacer
graficos 3d , y tambin gira el grafico
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 14 -

Imports System.Windows.Forms
Imports System.Windows.Forms.DataVisualization.Charting
Imports System.Data.SqlClient
Public Class Form1
Public anguloCuboX As Integer = 30 '-45
Public anguloCuboY As Integer = 30
Public anguloCuboZ As Integer = 30
Public VarAngulo As Integer = 10

Dim CadenaConexion As String = "Data


Source=(LocalDB)\v11.0;AttachDbFilename=E:\DATOS\ALUMNOS1.mdf;Integrated
Security=True;Connect Timeout=30"
Dim con As New SqlConnection(CadenaConexion)
Dim dap As New SqlDataAdapter("Select * FROM pagos", con)
Dim dst As New DataSet
Dim Nf As Integer = 1
Dim nc As Integer = 1
Dim X(50) As String
Dim Y(50) As Single
Dim CadenaSQL As String
Dim NombreCampo As String
Dim Tipo As Integer = 1
Dim cont As Integer = 1
Dim Modo3D As Integer = 0
Dim ModoAleatorio As Integer = 0
Dim ModoPalete As Integer = 0
Dim Perspectiva As Integer = 0
Dim ModoLuz As Integer = 0
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
dap.Fill(dst, "Pagos")
DataGridView1.DataSource = dst.Tables(0)
ComboBox1.Items.Add("Nro")
ComboBox1.Items.Add("CodALumno")
ComboBox1.Items.Add("FechaPago")
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 15 -

ComboBox1.Items.Add("Monto")
ComboBox1.Items.Add("CodCurso")
ComboBox1.Items.Add("Year(FechaPago)")
ComboBox1.Items.Add("Month(FechaPago)")
ComboBox1.Items.Add("Day(FechaPago)")
ComboBox1.SelectedIndex = 0
Dim fila As Integer
For fila = 0 To 34
Form2.Chart1.Series(0).ChartType = fila
ComboBox2.Items.Add(fila & " " & Form2.Chart1.Series(0).ChartType.ToString)
Next
ComboBox2.SelectedIndex = 1
Form2.Show()
End Sub
Sub Graficar(ConsultaSql As String, Campo As String, Tipo As Integer, Modo3D As
Integer, Modoaleatorio As Integer, _
AnguloX As Integer, AnguloY As Integer, AnguloZ As Integer, ModoPalete As
Integer, perspectiva As Integer, ModoLuz As Integer)
Dim fila As Integer
Form2.Chart1.Series.Clear()
Dim series As New Series("SubTotales por " & Campo)
' series.ChartType = SeriesChartType.Column
series.ChartType = Tipo
Form2.Chart1.ChartAreas(0).Area3DStyle.Enable3D = True
Form2.Chart1.ChartAreas(0).Area3DStyle.Inclination = AnguloX ' eje x
Form2.Chart1.ChartAreas(0).Area3DStyle.Rotation = AnguloY ' eje x
Form2.Chart1.ChartAreas(0).Area3DStyle.PointDepth = AnguloZ ' eje z
Form2.Chart1.Palette = ModoPalete
Form2.Chart1.ChartAreas(0).Area3DStyle.Perspective = perspectiva
Form2.Chart1.ChartAreas(0).Area3DStyle.LightStyle = ModoLuz
dap.SelectCommand.CommandText = ConsultaSql
dst.Tables.Clear()
dap.Fill(dst, "Subtotales")
DataGridView1.DataSource = dst.Tables(0)
Nf = dst.Tables(0).Rows.Count
ReDim X(Nf - 1)
ReDim Y(Nf - 1)
If Modoaleatorio = 1 Then
For fila = 0 To Nf - 1
dst.Tables(0).Rows(fila).Item(0) = fila
dst.Tables(0).Rows(fila).Item(1) = Int(Rnd() * 500 + 100)
Next
End If
For fila = 0 To Nf - 1
X(fila) = dst.Tables(0).Rows(fila).Item(0)
Y(fila) = dst.Tables(0).Rows(fila).Item(1)
Next
series.Points.DataBindXY(X, Y)
If Modo3D = 1 Then
Form2.Chart1.ChartAreas(0).Area3DStyle.Enable3D = True
Else
Form2.Chart1.ChartAreas(0).Area3DStyle.Enable3D = False
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 16 -

End If
Form2.Chart1.Series.Add(series)
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs)
Handles ComboBox1.SelectedIndexChanged
NombreCampo = ComboBox1.Items(ComboBox1.SelectedIndex)
CadenaSQL = "SELECT " & NombreCampo & ", Sum(monto) as Total FROM
PAGOS GROUP BY " & NombreCampo
Graficar(CadenaSQL, NombreCampo, Tipo, Modo3D, ModoAleatorio, anguloCuboX,
anguloCuboY, anguloCuboZ, ModoPalete, Perspectiva, ModoLuz)
End Sub
Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs)
Handles ComboBox2.SelectedIndexChanged
'Tipo = ComboBox2.Items(ComboBox2.SelectedIndex)
Tipo = ComboBox2.SelectedIndex
Graficar(CadenaSQL, NombreCampo, Tipo, Modo3D, ModoAleatorio, anguloCuboX,
anguloCuboY, anguloCuboZ, ModoPalete, Perspectiva, ModoLuz)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles btnDetener.Click
Timer1.Stop()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnAuto.Click
Timer1.Interval = 100
Timer1.Start()
End Sub
Private Sub btnManual_Click(sender As Object, e As EventArgs) Handles
btnManual.Click
If cont < 33 Then
ComboBox2.SelectedIndex = cont
Tipo = cont
Graficar(CadenaSQL, NombreCampo, Tipo, Modo3D, ModoAleatorio,
anguloCuboX, anguloCuboY, anguloCuboZ, ModoPalete, Perspectiva, ModoLuz)
cont = cont + 1
Else
cont = 0
End If
End Sub
Private Sub btnMostrarGraficos_Click(sender As Object, e As EventArgs) Handles
btnMostrarGraficos.Click
Form2.Show()
End Sub
Private Sub btnSimular_Click(sender As Object, e As EventArgs) Handles
btnSimular.Click
Graficar(CadenaSQL, NombreCampo, Tipo, Modo3D, ModoAleatorio, anguloCuboX,
anguloCuboY, anguloCuboZ, ModoPalete, Perspectiva, ModoLuz)
End Sub
Private Sub btnIniciar_Click(sender As Object, e As EventArgs) Handles btnIniciar.Click
DataGridView2.ColumnCount = 2
DataGridView2.RowCount = 9
DataGridView2.Columns(0).Width = 120
DataGridView2.Columns(1).Width = 40
Dim fila As Integer
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 17 -

For fila = 0 To DataGridView2.RowCount - 1


DataGridView2.Rows(fila).HeaderCell.Value = fila.ToString
Next
DataGridView2.Columns(0).HeaderText = "PROPIEDAD"
DataGridView2.Columns(1).HeaderText = "Valor"
DataGridView2.Rows(0).Cells(0).Value = "ROT X"
DataGridView2.Rows(0).Cells(1).Value = anguloCuboX
DataGridView2.Rows(1).Cells(0).Value = "ROT Y"
DataGridView2.Rows(1).Cells(1).Value = anguloCuboY
DataGridView2.Rows(2).Cells(0).Value = "Prof z"
DataGridView2.Rows(2).Cells(1).Value = anguloCuboZ
DataGridView2.Rows(3).Cells(0).Value = "Var "
DataGridView2.Rows(3).Cells(1).Value = VarAngulo

DataGridView2.Rows(4).Cells(0).Value = "3D 1=SI 0= NO"


DataGridView2.Rows(4).Cells(1).Value = Modo3D
DataGridView2.Rows(5).Cells(0).Value = "Aleatorio 1=SI 0= NO"
DataGridView2.Rows(5).Cells(1).Value = ModoAleatorio
DataGridView2.Rows(6).Cells(0).Value = "Palete 0-10"
DataGridView2.Rows(6).Cells(1).Value = ModoPalete
DataGridView2.Rows(7).Cells(0).Value = "Perpectiva 0-100 "
DataGridView2.Rows(7).Cells(1).Value = Perspectiva
DataGridView2.Rows(8).Cells(0).Value = "Modo Luz "
DataGridView2.Rows(8).Cells(1).Value = ModoLuz
End Sub
Private Sub btnobtener_Click(sender As Object, e As EventArgs) Handles
btnobtener.Click
anguloCuboX = DataGridView2.Rows(0).Cells(1).Value
anguloCuboY = DataGridView2.Rows(1).Cells(1).Value
anguloCuboZ = DataGridView2.Rows(2).Cells(1).Value
VarAngulo = DataGridView2.Rows(3).Cells(1).Value
Modo3D = DataGridView2.Rows(4).Cells(1).Value
ModoAleatorio = DataGridView2.Rows(5).Cells(1).Value
ModoPalete = DataGridView2.Rows(6).Cells(1).Value
Perspectiva = DataGridView2.Rows(7).Cells(1).Value
ModoLuz = DataGridView2.Rows(8).Cells(1).Value
Graficar(CadenaSQL, NombreCampo, Tipo, Modo3D, ModoAleatorio, anguloCuboX,
anguloCuboY, anguloCuboZ, ModoPalete, Perspectiva, ModoLuz)
End Sub
Private Sub TxtRot_KeyDown(sender As Object, e As KeyEventArgs) Handles
TxtRot.KeyDown
anguloCuboX = DataGridView2.Rows(0).Cells(1).Value
anguloCuboY = DataGridView2.Rows(1).Cells(1).Value
anguloCuboZ = DataGridView2.Rows(2).Cells(1).Value
Select Case e.KeyCode
Case Keys.Right, Keys.X ' fflecha derecha rota al rededdor del x
If anguloCuboX + VarAngulo < 90 Then
anguloCuboX = anguloCuboX + VarAngulo
End If
Case Keys.Left, Keys.A ' fflecha izquierdaderecha rota al rededdor del x
If anguloCuboX - VarAngulo > -90 Then
anguloCuboX = anguloCuboX - VarAngulo
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 18 -

End If
Case Keys.Up, Keys.Y ' flecha arriba a al rededdor del y
If anguloCuboY + VarAngulo < 180 Then
anguloCuboY = anguloCuboY + VarAngulo
End If
Case Keys.Down, Keys.B ' flecha arriba a al rededdor del y
If anguloCuboY - VarAngulo > -180 Then
anguloCuboY = anguloCuboY - VarAngulo
End If
Case Keys.PageUp, Keys.Z ' pagina arriba giro alrededor del eje z
If anguloCuboZ + VarAngulo < 1000 Then
anguloCuboZ = anguloCuboZ + VarAngulo
End If
Case Keys.PageDown, Keys.C ' pagina arriba giro alrededor del eje z
If anguloCuboZ - VarAngulo > 0 Then
anguloCuboZ = anguloCuboZ - VarAngulo
End If
End Select
DataGridView2.Rows(0).Cells(1).Value = anguloCuboX
DataGridView2.Rows(1).Cells(1).Value = anguloCuboY
DataGridView2.Rows(2).Cells(1).Value = anguloCuboZ
TxtRot.Text = ""
btnobtener_Click(sender, e)
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
btnManual_Click(sender, e)
End Sub
End Class

Elaborar el autmata celular juego de la vida con el control Chart

Imports System.Windows.Forms
Imports System.Windows.Forms.DataVisualization.Charting
Public Class Form1
Sub MostrarMatrizFormulario(ByVal A(,) As String, ByVal nf As Integer, ByVal nc As
Integer)
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 19 -

Dim fila, col As Integer


For col = 0 To nc - 1
DataGridView1.Columns(col).Width = 30
DataGridView1.Columns(col).HeaderText = A(0, col)
Next
For fila = 0 To nf - 1
For col = 0 To nc - 1
DataGridView1.Rows(fila).Cells(col).Value = A(fila + 1, col)
Next
Next
End Sub

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


Integer)
Dim fila, col As Integer
For fila = 1 To nf - 1
For col = 1 To nc - 1
DataGridView1.Rows(fila).Cells(col).Value = A(fila, col)
Next
Next
End Sub
Sub FormularioAmatriz(ByVal A(,) As String, ByVal nf As Integer, ByVal nc As Integer)
Dim fila, col As Integer
For col = 0 To nc - 1
' DataGridView1.Columns(col).Width = 10
Matriz(0, col) = DataGridView1.Columns(col).HeaderText
Next
For fila = 0 To nf - 1
For col = 0 To nc - 1
Matriz(fila + 1, col) = DataGridView1.Rows(fila).Cells(col).Value
Next
Next
End Sub

Private Sub btnAbrir_Click(sender As Object, e As EventArgs) Handles btnAbrir.Click


RecuperarMatriz(NombreArchivo, Matriz, nf, nc)
DataGridView1.RowCount = nf
DataGridView1.ColumnCount = nc
ConvertirMatrizCadenaEntero(Matriz, A, nf, nc)
MostrarMatrizFormulario(Matriz, nf, nc)
MostrarMatrizJuego(A, nf, nc)
End Sub

Private Sub BtnIniciar_Click(sender As Object, e As EventArgs) Handles BtnIniciar.Click


DataGridView2.ColumnCount = 2
DataGridView2.RowCount = 11
DataGridView2.Columns(0).Width = 120
DataGridView2.Columns(1).Width = 40
Dim fila As Integer
For fila = 0 To DataGridView2.RowCount - 1
DataGridView2.Rows(fila).HeaderCell.Value = fila.ToString
Next
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 20 -

DataGridView2.Columns(0).HeaderText = "PROPIEDAD"
DataGridView2.Columns(1).HeaderText = "Valor"
DataGridView2.Rows(0).Cells(0).Value = "ROT X"
DataGridView2.Rows(0).Cells(1).Value = anguloCuboX
DataGridView2.Rows(1).Cells(0).Value = "ROT Y"
DataGridView2.Rows(1).Cells(1).Value = anguloCuboY
DataGridView2.Rows(2).Cells(0).Value = "Prof z"
DataGridView2.Rows(2).Cells(1).Value = anguloCuboZ
DataGridView2.Rows(3).Cells(0).Value = "Var "
DataGridView2.Rows(3).Cells(1).Value = VarAngulo

DataGridView2.Rows(4).Cells(0).Value = "3D 1=SI 0= NO"


DataGridView2.Rows(4).Cells(1).Value = Modo3D
DataGridView2.Rows(5).Cells(0).Value = "tipo"
DataGridView2.Rows(5).Cells(1).Value = Tipo
DataGridView2.Rows(6).Cells(0).Value = "Palete 0-10"
DataGridView2.Rows(6).Cells(1).Value = ModoPalete
DataGridView2.Rows(7).Cells(0).Value = "Perpectiva 0-100 "
DataGridView2.Rows(7).Cells(1).Value = Perspectiva
DataGridView2.Rows(8).Cells(0).Value = "Modo Luz "
DataGridView2.Rows(8).Cells(1).Value = ModoLuz
DataGridView2.Rows(9).Cells(0).Value = "Nfilas "
DataGridView2.Rows(9).Cells(1).Value = nf
DataGridView2.Rows(10).Cells(0).Value = "N Col "
DataGridView2.Rows(10).Cells(1).Value = nc
End Sub
Sub Obtener()
anguloCuboX = DataGridView2.Rows(0).Cells(1).Value
anguloCuboY = DataGridView2.Rows(1).Cells(1).Value
anguloCuboZ = DataGridView2.Rows(2).Cells(1).Value
VarAngulo = DataGridView2.Rows(3).Cells(1).Value
Modo3D = DataGridView2.Rows(4).Cells(1).Value
Tipo = DataGridView2.Rows(5).Cells(1).Value
ModoPalete = DataGridView2.Rows(6).Cells(1).Value
Perspectiva = DataGridView2.Rows(7).Cells(1).Value
ModoLuz = DataGridView2.Rows(8).Cells(1).Value
End Sub

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


btnGraficar.Click
graficar(Matriz, nf, nc, Tipo, Modo3D, anguloCuboX, anguloCuboY, anguloCuboZ,
ModoPalete, Perspectiva, ModoLuz)
End Sub
Sub graficar(A(,) As String, nf As Integer, nc As Integer, tipo As Integer, _
Modo3D As Integer, AnguloX As Integer, AnguloY As Integer, AnguloZ As Integer, _
ModoPalete As Integer, perspectiva As Integer, ModoLuz As Integer)
Form2.Chart1.Series.Clear()
Dim series(nc) As Series
Dim col As Integer
For col = 0 To nc - 1
series(col) = New Series(A(0, col))
Form2.Chart1.Series.Add(series(col))
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 21 -

Form2.Chart1.Series(col).ChartType = tipo
Next
Form2.Chart1.ChartAreas(0).Area3DStyle.Enable3D = Modo3D
Form2.Chart1.ChartAreas(0).Area3DStyle.Inclination = AnguloX ' eje x
Form2.Chart1.ChartAreas(0).Area3DStyle.Rotation = AnguloY ' eje x
Form2.Chart1.ChartAreas(0).Area3DStyle.PointDepth = AnguloZ ' eje z
Form2.Chart1.Palette = ModoPalete
Form2.Chart1.ChartAreas(0).Area3DStyle.Perspective = Perspectiva
Form2.Chart1.ChartAreas(0).Area3DStyle.LightStyle = ModoLuz
For fila = 1 To nf - 1
For col = 0 To nc - 2
Form2.Chart1.Series(col).Points.AddXY(A(fila, 0), CInt(A(fila, col + 1)))
Next
Next
End Sub

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


BtnObtener.Click
Obtener()
FormularioAmatriz(Matriz, nf, nc)
graficar(Matriz, nf, nc, Tipo, Modo3D, anguloCuboX, anguloCuboY, anguloCuboZ,
ModoPalete, Perspectiva, ModoLuz)
End Sub
Private Sub btnJugar_Click(sender As Object, e As EventArgs) Handles btnJugar.Click
If contador < ng Then
contador = contador + 1
JuegoVida(A, nf, nc)
MostrarMatrizJuego(A, nf, nc)
ConvertirMatrizEnteroCadena(A, Matriz, nf, nc)
graficar(Matriz, nf, nc, Tipo, Modo3D, anguloCuboX, anguloCuboY, anguloCuboZ,
ModoPalete, Perspectiva, ModoLuz)
Else
contador = 0
Timer1.Stop()
MsgBox(" fin del juego")
End If
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Form2.Show()
End Sub
Private Sub VerFomulario2(sender As Object, e As EventArgs) Handles btnForm2.Click
Form2.Show()
End Sub
Private Sub btnForm2_Click(sender As Object, e As EventArgs) Handles
btnForm2.Click
End Sub

Private Sub txtRot_KeyDown(sender As Object, e As KeyEventArgs) Handles


txtRot.KeyDown
anguloCuboX = DataGridView2.Rows(0).Cells(1).Value
anguloCuboY = DataGridView2.Rows(1).Cells(1).Value
anguloCuboZ = DataGridView2.Rows(2).Cells(1).Value
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 22 -

Select Case e.KeyCode


Case Keys.Right, Keys.X ' fflecha derecha rota al rededdor del x
If anguloCuboX + VarAngulo < 90 Then
anguloCuboX = anguloCuboX + VarAngulo
End If
Case Keys.Left, Keys.A ' fflecha izquierdaderecha rota al rededdor del x
If anguloCuboX - VarAngulo > -90 Then
anguloCuboX = anguloCuboX - VarAngulo
End If
Case Keys.Up, Keys.Y ' flecha arriba a al rededdor del y
If anguloCuboY + VarAngulo < 180 Then
anguloCuboY = anguloCuboY + VarAngulo
End If
Case Keys.Down, Keys.B ' flecha arriba a al rededdor del y
If anguloCuboY - VarAngulo > -180 Then
anguloCuboY = anguloCuboY - VarAngulo
End If
Case Keys.PageUp, Keys.Z ' pagina arriba giro alrededor del eje z
If anguloCuboZ + VarAngulo < 1000 Then
anguloCuboZ = anguloCuboZ + VarAngulo
End If
Case Keys.PageDown, Keys.C ' pagina arriba giro alrededor del eje z
If anguloCuboZ - VarAngulo > 0 Then
anguloCuboZ = anguloCuboZ - VarAngulo
End If
End Select
DataGridView2.Rows(0).Cells(1).Value = anguloCuboX
DataGridView2.Rows(1).Cells(1).Value = anguloCuboY
DataGridView2.Rows(2).Cells(1).Value = anguloCuboZ
txtRot.Text = ""
BtnObtener_Click(sender, e)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Timer1.Interval = 100
Timer1.Start()
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click


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

CODIGO DEL MODULO 1

Imports System.IO
Module Module1
Public Const maxfilas As Integer = 24
Public Const maxcol As Integer = 60
Public NombreArchivo As String = "E:\datos\MATRIZ60X24.txt"
Public NombreArchivoGraba As String = "E:\datos\notas4x5Salida.txt"
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 23 -

Public Matriz(maxfilas, maxcol) As String


Public anguloCuboX As Integer = 30 '-45
Public anguloCuboY As Integer = 30
Public anguloCuboZ As Integer = 30
Public VarAngulo As Integer = 10
Public Tipo As Integer = 10
Public Modo3D As Integer = 0
Public ModoAleatorio As Integer = 0
Public ModoPalete As Integer = 0
Public Perspectiva As Integer = 0
Public ModoLuz As Integer = 0
Public A(maxfilas, maxcol) As Integer
Public nf As Integer = 24
Public nc As Integer = 60
Public ng As Integer = 200
Public contador As Integer = 0

Sub Main()
Dim I As Integer
Console.Write("juego de la vida de wonway")
Console.Write("Diseo escecario en excel y grabe archivo con bloque de notas ")
Console.Write("juego de la vida de wonway")
RecuperarMatriz(NombreArchivo, Matriz, nf, nc)
ConvertirMatrizCadenaEntero(Matriz, A, nf, nc)
VerPantalla(A, nf, nc)
Console.ReadLine()
For I = 0 To ng
JuegoVida(A, nf, nc)
VerPantalla(A, nf, nc)
JuegoVida(A, nf, nc)
System.Threading.Thread.Sleep(10) ' 1 segundo
Next
Console.ReadLine()
End Sub
End Module

CODIGO DEL MODULO 2

Imports System.IO
Module Module2
Sub ConvertirMatrizEnteroCadena(ByVal A(,) As Integer, ByVal Matriz(,) As String,
ByVal nf As Integer, ByVal nc As Integer)
Dim fila, col As Integer
For fila = 1 To nf - 1
For col = 1 To nc - 1
Matriz(fila, col) = A(fila, col)
Next
Next
End Sub
Sub ConvertirMatrizCadenaEntero(ByVal Matriz(,) As String, ByVal A(,) As Integer,
ByVal nf As Integer, ByVal nc As Integer)
Dim fila, col As Integer
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 24 -

For fila = 1 To nf - 1
For col = 1 To nc - 1
A(fila, col) = CInt(Matriz(fila, col))
Next
Next
End Sub
Sub IniciarPantalla(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As Integer)
Dim fila, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
A(fila, col) = 0
Next
Next
End Sub
Sub TranferirMatriz(ByVal A(,) As Integer, ByVal B(,) As Integer, ByVal nf As Integer,
ByVal nc As Integer)
Dim fila, col As Integer
For fila = 1 To nf - 1
For col = 1 To nc - 1
B(fila, col) = A(fila, col)
Next
Next
End Sub

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


Dim B(maxfilas, maxcol) As Integer
Dim fila, col, vecinos, x1, y1, x2, y2, fila1, col1 As Integer
For fila = 1 To nf
For col = 1 To nc
vecinos = 0
If fila > 1 Then
y1 = fila - 1
Else
y1 = fila
End If

If fila < nf - 1 Then


y2 = fila + 1
Else
y2 = fila
End If
If col > 1 Then
x1 = col - 1
Else
x1 = col
End If
If col < nc Then
x2 = col + 1
Else
x2 = col
End If
For fila1 = y1 To y2
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 25 -

For col1 = x1 To x2
If (fila1 = fila And col1 = col) Then Continue For
If A(fila1, col1) = 1 Then vecinos = vecinos + 1
Next
Next
Select Case vecinos
Case 0
B(fila, col) = 0
Case 1
B(fila, col) = 0
Case 2
B(fila, col) = A(fila, col)
Case 3
B(fila, col) = 1
Case Else
B(fila, col) = 0
End Select
Next
Next
IniciarPantalla(A, nf, nc)
TranferirMatriz(B, A, nf, nc)
End Sub
Sub VerPantalla(ByVal A(,) As Integer, ByVal nf As Integer, ByVal nc As Integer)
Dim fila, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
Console.SetCursorPosition(col + 1, fila + 1)
If (A(fila, col) > 0) Then
' Console.Write("{0}", ChrW(219))
Console.Write("*")
Else
Console.Write(" ")
End If
Next
Next
End Sub
Sub RecuperarMatriz(ByVal nombrearchivo As String, ByRef A(,) As String, ByVal nf As
Integer, ByVal 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
For fila = 0 To nf - 1
cadena = srLector.ReadLine()
cadena = cadena & Chr(9)
inicio = 1
For col = 0 To nc - 1
pos = InStr(inicio, cadena, Chr(9))
subcadena = Mid(cadena, inicio, pos - inicio)
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 26 -

A(fila, col) = subcadena


inicio = pos + 1
Next
Next
Console.WriteLine("Archivo leido satisfactoriamente")
srLector.Close()
End Sub
End Module

REPORTES EN VISUAL BASIC 2012


CAPA presentacin clic derecho y poner informe

Buscar informe o report


Elaborar reporte de alumnos

Aparece los siguiente


Tecnologia de base de datos 2016B \9 Reportes parte 2 - 27 -

2 Dar clic derecho e insertar

Aparece lo siguiente presionar en nuevo

Elegir base de datos


Tecnologia de base de datos 2016B \9 Reportes parte 2 - 28 -

Luego conjunto de batos

Son casi los mismos pasos para realizar una conexin


Tecnologia de base de datos 2016B \9 Reportes parte 2 - 29 -

Aparece lo siguiente

Escoja la tabla pagos


Tecnologia de base de datos 2016B \9 Reportes parte 2 - 30 -

Finalizar y luego aceptar

Aparece lo siguiente
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 31 -

Ubicarse en el primer recuadro y se ve el smbolo de base de datos

En el primer campo poner numero y asi sucesivmente en lso dems

Elija insertar columna a la derecha


Tecnologia de base de datos 2016B \9 Reportes parte 2 - 32 -

Y se llena los dems campos

Poner encabezado a la hoja

Se Obtiene
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 33 -

Insertamos una imagen en el encabezado

Seleccione la imagen

En opciones de amao de imagen se tiene


Tecnologia de base de datos 2016B \9 Reportes parte 2 - 34 -

Insertar un cuadro de texto


Y escriba informa de pagos PUEDE cambia la fuentes la s propiedades del siguiente
cuadro

SE Tiene

Poner una lnea de 5 puntos de anncho


Tecnologia de base de datos 2016B \9 Reportes parte 2 - 35 -

Acomodar las dimensiones de los campos


Por ejmplo fecha pago es mas ancho

Agregar Report Viewer y arrAstre al formualrioal formulario, si no exsite ete elemento en


la barras de herramientas entonces eligir elemento

Elija el informe preprados y acoplar al formulario(acoplar al contenedor primario)

Y se tiene el informe

Evalue los botones y vea


Tecnologia de base de datos 2016B \9 Reportes parte 2 - 36 -

Por ejemplo diseo de impresin

Configurar pagina

Exportar
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 37 -

PRUEBE buscar

Para llamar reporte de otro formulario

Public Class Form2


Private Sub btnReporte_Click(sender As Object, e As EventArgs) Handles
btnReporte.Click
Form1.Show()
End Sub
End Class
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 38 -

Formatear el datagridview

Imports System.Data.SqlClient
Public Class Form1
Inherits System.Windows.Forms.Form
Dim cadenaconexion = "Data
Source=(LocalDB)\v11.0;AttachDbFilename=D:\datos\alumnos.mdf;Integrated
Security=True;Connect Timeout=30"
Dim Conexion As New SqlConnection(cadenaconexion)
Dim DAlumnos As New SqlDataAdapter("SELECT * FROM Alumnos", Conexion)
Dim DataSet As New DataSet()
Private Sub frmNormal_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles MyBase.Load
DAlumnos.Fill(DataSet, "consulta")
DataGridView1.DataSource = DataSet.Tables(0)
End Sub
Private Sub Btnformatear_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Btnformatear.Click
'DataGridView1.Columns(1).DefaultCellStyle.Font
Dim cellStyle As New DataGridViewCellStyle
Dim fila As Integer
cellStyle.Font = New Font("ARIAL", 14, FontStyle.Bold)
Me.DataGridView1.ColumnHeadersDefaultCellStyle = cellStyle
DataGridView1.DefaultCellStyle.Font = New Font("ARIAL", 10)
DataGridView1.Columns(1).DefaultCellStyle.Font = New Font("ARIAL Black", 10)
For fila = 0 To DataSet.Tables(0).Rows.Count - 1
DataGridView1.Rows(fila).Cells(0).Style.BackColor = Color.FromArgb(0, 255, 0)
DataGridView1.Rows(fila).Cells(1).Style.BackColor = Color.FromArgb(255, 255, 0)
DataGridView1.Rows(fila).Cells(2).Style.BackColor = Color.FromArgb(0, 255, 255)
DataGridView1.Rows(fila).Cells(0).Style.ForeColor = Color.FromArgb(255, 0, 0)
Next
End Sub
Private Sub Btnformatear_Click_1(sender As Object, e As EventArgs) Handles
Btnformatear.Click
End Sub
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 39 -

Private Sub DataGridView1_CellContentClick(sender As Object, e As


DataGridViewCellEventArgs) Handles DataGridView1.CellClick
Dim Fila, Col As Integer
Fila = DataGridView1.CurrentCell.RowIndex
Col = DataGridView1.CurrentCell.ColumnIndex
txtFila.Text = Fila
txtCol.Text = Col
txtValor.Text = DataGridView1.Rows(Fila).Cells(Col).Value
End Sub

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


btnIngresar.Click
Dim fila, col As Integer
Fila = DataGridView1.CurrentCell.RowIndex
Col = DataGridView1.CurrentCell.ColumnIndex
Fila = txtFila.Text
col = txtCol.Text
DataGridView1.Rows(fila).Cells(col).Value = txtValor.Text
End Sub
End Class

DATASET CON TRES TABLAS

Imports System.Data.SqlClient
Public Class Form1
Public cadenaconexion As String = "Data
Source=(LocalDB)\v11.0;AttachDbFilename=E:\DATOS\ALUMNOS.mdf;Integrated
Security=True;Connect Timeout=30"
Public conn As SqlConnection = New SqlConnection(cadenaconexion)
Public Opcion As Integer, Pos As Integer
Public codalumno As String
Public nombrealumno As String
Public FechaNac As String
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 40 -

Public ncol As Integer = 3


Public fila, col As Integer
Public da As SqlDataAdapter = New SqlDataAdapter("", conn)
Public ds As DataSet = New DataSet

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


'da.SelectCommand.CommandText = "SELECT * FROM ALUMNOS"
'da.Fill(ds, "ALUMNOS")
'da.SelectCommand.CommandText = "SELECT * FROM CURSOS"
'da.Fill(ds, "CURSOS")
'da.SelectCommand.CommandText = "SELECT * FROM PAGOS"
'da.Fill(ds, "PAGOS")

da.SelectCommand.CommandText = "SELECT * FROM ALUMNOS;SELECT *


FROM CURSOS; SELECT * FROM PAGOS"
da.Fill(ds, "PAGOS")
DataGridView1.DataSource = ds.Tables(0)
DataGridView2.DataSource = ds.Tables(1)
DataGridView3.DataSource = ds.Tables(2)
End Sub
Private Sub DataGridView1_CellContentClick(sender As Object, e As
DataGridViewCellEventArgs) Handles _
DataGridView1.CellClick, DataGridView2.CellClick, DataGridView3.CellClick
Dim Fila, Col, tabla As Integer
Select Case sender.name
Case "DataGridView1" : tabla = 0
Case "DataGridView2" : tabla = 1
Case "DataGridView3" : tabla = 2
End Select
Fila = sender.CurrentCell.RowIndex
Col = sender.CurrentCell.ColumnIndex
txttabla.Text = tabla
txtFila.Text = Fila
txtcol.Text = Col
txtvalor.Text = sender.Rows(Fila).Cells(Col).Value
End Sub
End Class

CONTROL MULTIMEDIA
control media player
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 41 -

Public Class Form1


Private Sub AbrirToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles
AbrirToolStripMenuItem.Click
OpenFileDialog1.ShowDialog()
AxWindowsMediaPlayer1.URL = OpenFileDialog1.FileName
End Sub

Private Sub CerrarToolStripMenuItem_Click(sender As Object, e As EventArgs)


Handles CerrarToolStripMenuItem.Click
'AxWindowsMediaPlayer1.close()
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 42 -

End Sub
End Class
Poner reporductos de msica archivso wav
EJEMPLO DE ANIMACION EN VISUAL BASIC MOVER BOTONES O IMAGE LIST
El control serial port

Public Class Form1


Sub GetSerialPortNames()
' Show all available COM ports.
For Each sp As String In My.Computer.Ports.SerialPortNames
ListBox1.Items.Add(sp)
Next
End Sub

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


GetSerialPortNames()
End Sub
End Class

Ports (Clase)
.NET Framework (current version)
Otras versiones

Proporciona una propiedad y un mtodo para tener acceso a los puertos serie del equipo.
Espacio de nombres: Microsoft.VisualBasic.Devices
Microsoft.VisualBasic.Devices (Espacio de nombres)
.NET Framework (current version
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 43 -

Public Class Form1

Sub GetSerialPortNames()
' Show all available COM ports.
For Each sp As String In My.Computer.Ports.SerialPortNames
ListBox1.Items.Add(sp)
Next
End Sub

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


ListBox1.Items.Add(" MEMORIA FISICA DISPONILLE EN EL EQUIPO " &
My.Computer.Info.AvailablePhysicalMemory)
ListBox1.Items.Add(" SISTEMA OPERATIVO " & My.Computer.Info.ToString)
ListBox1.Items.Add(" SISTEMA OPERATIVO " & My.Computer.Info.OSFullName)
ListBox1.Items.Add(" AUDIO OPERATIVO " & My.Computer.Audio.ToString)
ListBox1.Items.Add("APLICACION " & My.Application.ToString)
ListBox1.Items.Add("FORM " & My.Forms.ToString)
GetSerialPortNames()
End Sub
End Class

If My.Computer.Keyboard.AltKeyDown Then
MsgBox("ALT key down")
Else
MsgBox("ALT key up")
End If
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 44 -

Public Class Form1

Sub GetSerialPortNames()
' Show all available COM ports.
For Each sp As String In My.Computer.Ports.SerialPortNames
ListBox1.Items.Add(sp)
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
ListBox1.Items.Add(" MEMORIA FISICA DISPONILLE EN EL EQUIPO " &
My.Computer.Info.AvailablePhysicalMemory)
ListBox1.Items.Add(" SISTEMA OPERATIVO " & My.Computer.Info.ToString)
ListBox1.Items.Add(" SISTEMA OPERATIVO " & My.Computer.Info.OSFullName)
ListBox1.Items.Add(" AUDIO OPERATIVO " & My.Computer.Audio.ToString)
ListBox1.Items.Add("APLICACION " & My.Application.ToString)
ListBox1.Items.Add("FORM " & My.Forms.ToString)
TextBox1.Text = My.Computer.Keyboard.AltKeyDown

GetSerialPortNames()
End Sub
End Class

Desarrollo de aplicaciones con Visual Basic Programar en Visual Basic Procesar


unidades, directorios y archivos
Acceso a archivos con Visual Basic
Fundamentos del sistema de archivos y la E/S de archivos en .NET Framework
Tutorial: Manipular archivos utilizando mtodos de .NET Framework
Tutorial: Manipular archivos y directorios en Visual Basic
Para ver el artculo en ingls, active la casilla
Traduccin
Ingls. Tambin puede ver el texto en ingls en una
ventana emergente si pasa el puntero del mouse por Ingls
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 45 -

el texto.
Tutorial: Manipular archivos y directorios en Visual Basic
Visual Studio 2015
Otras versiones

Este tutorial ofrece una introduccin a los fundamentos de la E/S de archivos en Visual
Basic. Describe cmo crear una aplicacin pequea que enumera y examina los archivos
de texto en un directorio. Para cada archivo de texto seleccionado, la aplicacin
proporciona atributos de archivo y la primera lnea de contenido. Hay una opcin para
escribir informacin en un archivo de registro.
Este tutorial utiliza miembros de My.Computer.FileSystem Object, que estn disponibles
en Visual Basic. Vea FileSystem para obtener ms informacin. Al final del tutorial, se
proporciona un ejemplo equivalente que usa clases del espacio de nombres System.IO.
Nota

Es posible que tu equipo muestre nombres o ubicaciones diferentes para algunos de los
elementos de la interfaz de usuario de Visual Studio en las siguientes instrucciones. La
edicin de Visual Studio que se tenga y la configuracin que se utilice determinan estos
elementos. Para obtener ms informacin, consulta Personalizar el IDE de Visual Studio.
Para crear el proyecto
1. En el men Archivo, haga clic en Nuevo proyecto.
Aparecer el cuadro de dilogo Nuevo proyecto.
2. En el panel Plantillas instaladas, expanda Visual Basic y, a continuacin, haga
clic enWindows. En el panel central Plantillas, haga clic en Aplicacin de
Windows Forms.
3. En el cuadro Nombre, escriba FileExplorer para establecer el nombre del proyecto
y, a continuacin, haga clic en Aceptar.
Visual Studio agregar el proyecto al Explorador de soluciones y se abrir el
Diseador de Windows Forms.
4. Agregue los controles de la siguiente tabla al formulario y establezca los
correspondientes valores para sus propiedades.
Control Propiedad. Valor

ListBox Name filesListBox

Button Name browseButton


Text Browse

Button Name examineButton


Text Examine

CheckBox Name saveCheckBox


Text Guardar resultados

FolderBrowserDialog Name FolderBrowserDialog1


Tecnologia de base de datos 2016B \9 Reportes parte 2 - 46 -

Seleccionar una carpeta y enumerar archivos en una carpeta


1. Cree un controlador de eventos Click para browseButton haciendo doble clic en el
control del formulario. Se abrir el Editor de cdigo.
2. Agregue el cdigo siguiente al controlador de eventos Click.
VB
If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
' List files in the folder.
ListFiles(FolderBrowserDialog1.SelectedPath)
End If
La llamada FolderBrowserDialog1.ShowDialog abre el cuadro de dilogo Buscar
carpeta. Una vez que el usuario hace clic en Aceptar, la
propiedad SelectedPath se enva como un argumento al mtodo ListFiles, que se
agrega en el paso siguiente.
3. Agregue el siguiente mtodo ListFiles.
VB
Private Sub ListFiles(ByVal folderPath As String)
filesListBox.Items.Clear()

Dim fileNames = My.Computer.FileSystem.GetFiles(


folderPath, FileIO.SearchOption.SearchTopLevelOnly, "*.txt")

For Each fileName As String In fileNames


filesListBox.Items.Add(fileName)
Next
End Sub
Este cdigo primero borra el control ListBox.
A continuacin, el mtodo GetFiles recupera una coleccin de cadenas, una para
cada archivo del directorio. El mtodo GetFiles acepta un argumento de modelo
de bsqueda para recuperar los archivos que coinciden con un modelo
determinado. En este ejemplo, nicamente se devuelven los archivos que tienen la
extensin .txt.
A continuacin, las cadenas que devuelve el mtodo GetFiles se agregan al
control ListBox.
4. Ejecute la aplicacin. Haga clic en el botn Examinar. En el cuadro de
dilogo Buscar carpeta, busque una carpeta con archivos .txt y, a continuacin,
seleccione la carpeta y haga clic enAceptar.
ListBox contiene una lista de archivos .txt en la carpeta seleccionada.
5. Detenga la ejecucin de la aplicacin.
Obtener atributos de un archivo y contenido de un archivo de texto
1. Cree un controlador de eventos Click para examineButton haciendo doble clic en el
control del formulario.
2. Agregue el cdigo siguiente al controlador de eventos Click.
VB
If filesListBox.SelectedItem Is Nothing Then
MessageBox.Show("Please select a file.")
Exit Sub
End If

' Obtain the file path from the list box selection.
Dim filePath = filesListBox.SelectedItem.ToString

' Verify that the file was not removed since the
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 47 -

' Browse button was clicked.


If My.Computer.FileSystem.FileExists(filePath) = False Then
MessageBox.Show("File Not Found: " & filePath)
Exit Sub
End If

' Obtain file information in a string.


Dim fileInfoText As String = GetTextForOutput(filePath)

' Show the file information.


MessageBox.Show(fileInfoText)
El cdigo comprueba que un elemento est seleccionado en ListBox. A
continuacin, obtiene la entrada de la ruta de acceso del archivo de ListBox. El
mtodo FileExists se utiliza para comprobar si el archivo todava existe.
La ruta de acceso del archivo se enva como un argumento al
mtodo GetTextForOutput, que se agrega en el paso siguiente. Este mtodo
devuelve una cadena que contiene la informacin del archivos. La informacin del
archivo aparece en un MessageBox.
3. Agregue el siguiente mtodo GetTextForOutput.
VB
Private Function GetTextForOutput(ByVal filePath As String) As String
' Verify that the file exists.
If My.Computer.FileSystem.FileExists(filePath) = False Then
Throw New Exception("File Not Found: " & filePath)
End If

' Create a new StringBuilder, which is used


' to efficiently build strings.
Dim sb As New System.Text.StringBuilder()

' Obtain file information.


Dim thisFile As System.IO.FileInfo =
My.Computer.FileSystem.GetFileInfo(filePath)

' Add file attributes.


sb.Append("File: " & thisFile.FullName)
sb.Append(vbCrLf)
sb.Append("Modified: " & thisFile.LastWriteTime.ToString)
sb.Append(vbCrLf)
sb.Append("Size: " & thisFile.Length.ToString & " bytes")
sb.Append(vbCrLf)

' Open the text file.


Dim sr As System.IO.StreamReader =
My.Computer.FileSystem.OpenTextFileReader(filePath)

' Add the first line from the file.


If sr.Peek() >= 0 Then
sb.Append("First Line: " & sr.ReadLine())
End If
sr.Close()
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 48 -

Return sb.ToString
End Function
El cdigo utiliza el mtodo GetFileInfo para obtener los parmetros del
archivo. Los parmetros del archivo se agregan a StringBuilder.
El mtodo OpenTextFileReader lee el contenido del archivo en StreamReader. La
primera lnea del contenido se obtiene de StreamReader y se agrega
a StringBuilder.
4. Ejecute la aplicacin. Haga clic en Browse y vaya a una carpeta que contiene
archivos .txt. Haga clic en Aceptar.
Seleccione un archivo en ListBox y, a continuacin, haga clic
en Examine. MessageBoxmuestra la informacin del archivo.
5. Detenga la ejecucin de la aplicacin.
Agregar una entrada de registro
1. Agregue el siguiente cdigo al final del controlador de
eventos examineButton_Click.
VB
If saveCheckBox.Checked = True Then
' Place the log file in the same folder as the examined file.
Dim logFolder As String =
My.Computer.FileSystem.GetFileInfo(filePath).DirectoryName
Dim logFilePath = My.Computer.FileSystem.CombinePath(logFolder, "log.txt")

Dim logText As String = "Logged: " & Date.Now.ToString &


vbCrLf & fileInfoText & vbCrLf & vbCrLf

' Append text to the log file.


My.Computer.FileSystem.WriteAllText(logFilePath, logText, append:=True)
End If
El cdigo establece la ruta del archivo de registro para colocar el archivo de
registro en el mismo directorio que el archivo seleccionado. El texto de la entrada
de registro se establece en la fecha y hora actual seguido de la informacin del
archivo.
El mtodo WriteAllText, con el argumento append establecido en True, se utiliza
para crear la entrada de registro.
2. Ejecute la aplicacin. Vaya a un archivo de texto, seleccinelo en ListBox, active
la casillaGuardar resultados y, a continuacin, haga clic
en Examine. Compruebe que la entrada de registro est escrita en el
archivo log.txt.
3. Detenga la ejecucin de la aplicacin.
Utilizar el directorio actual
1. Haga doble clic en el formulario para crear un controlador de eventos
para Form1_Load.
2. Agregue el siguiente cdigo al controlador de eventos.
VB
' Set the default directory of the folder browser to the current directory.
FolderBrowserDialog1.SelectedPath = My.Computer.FileSystem.CurrentDirectory
Este cdigo establece el directorio predeterminado del explorador de la carpeta en
el directorio actual.
3. Ejecute la aplicacin. Al hacer clic por primera vez en Examinar, se abre el cuadro
de dilogoBuscar carpeta en el directorio actual.
4. Detenga la ejecucin de la aplicacin.
Habilitar controles de forma selectiva
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 49 -

1. Agregue el siguiente mtodo SetEnabled.


VB
Private Sub SetEnabled()
Dim anySelected As Boolean =
(filesListBox.SelectedItem IsNot Nothing)

examineButton.Enabled = anySelected
saveCheckBox.Enabled = anySelected
End Sub
El mtodo SetEnabled habilita o deshabilita controles dependiendo de si un
elemento se selecciona en ListBox.
2. Cree un controlador de
eventos SelectedIndexChanged para filesListBox haciendo doble clic en el
control ListBox del formulario.
3. Agregue una llamada a SetEnabled en el nuevo controlador de
eventosfilesListBox_SelectedIndexChanged.
4. Agregue una llamada a SetEnabled la final del controlador de
eventos browseButton_Click.
5. Agregue una llamada a SetEnabled la final del controlador de
eventos Form1_Load.
6. Ejecute la aplicacin. La casilla Guardar resultados y el botn Examine se
deshabilitan deshabilitados si no se selecciona un elemento en ListBox.
Ejemplo completo utilizando My.Computer.FileSystem
El ejemplo completo aparece a continuacin.
VB

' This example uses members of the My.Computer.FileSystem


' object, which are available in Visual Basic.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles MyBase.Load
' Set the default directory of the folder browser to the current directory.
FolderBrowserDialog1.SelectedPath = My.Computer.FileSystem.CurrentDirectory

SetEnabled()
End Sub

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


System.EventArgs) Handles browseButton.Click
If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
' List files in the folder.
ListFiles(FolderBrowserDialog1.SelectedPath)
End If
SetEnabled()
End Sub

Private Sub ListFiles(ByVal folderPath As String)


filesListBox.Items.Clear()

Dim fileNames = My.Computer.FileSystem.GetFiles(


folderPath, FileIO.SearchOption.SearchTopLevelOnly, "*.txt")
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 50 -

For Each fileName As String In fileNames


filesListBox.Items.Add(fileName)
Next
End Sub

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


System.EventArgs) Handles examineButton.Click
If filesListBox.SelectedItem Is Nothing Then
MessageBox.Show("Please select a file.")
Exit Sub
End If

' Obtain the file path from the list box selection.
Dim filePath = filesListBox.SelectedItem.ToString

' Verify that the file was not removed since the
' Browse button was clicked.
If My.Computer.FileSystem.FileExists(filePath) = False Then
MessageBox.Show("File Not Found: " & filePath)
Exit Sub
End If

' Obtain file information in a string.


Dim fileInfoText As String = GetTextForOutput(filePath)

' Show the file information.


MessageBox.Show(fileInfoText)

If saveCheckBox.Checked = True Then


' Place the log file in the same folder as the examined file.
Dim logFolder As String =
My.Computer.FileSystem.GetFileInfo(filePath).DirectoryName
Dim logFilePath = My.Computer.FileSystem.CombinePath(logFolder, "log.txt")

Dim logText As String = "Logged: " & Date.Now.ToString &


vbCrLf & fileInfoText & vbCrLf & vbCrLf

' Append text to the log file.


My.Computer.FileSystem.WriteAllText(logFilePath, logText, append:=True)
End If
End Sub

Private Function GetTextForOutput(ByVal filePath As String) As String


' Verify that the file exists.
If My.Computer.FileSystem.FileExists(filePath) = False Then
Throw New Exception("File Not Found: " & filePath)
End If

' Create a new StringBuilder, which is used


' to efficiently build strings.
Dim sb As New System.Text.StringBuilder()
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 51 -

' Obtain file information.


Dim thisFile As System.IO.FileInfo = My.Computer.FileSystem.GetFileInfo(filePath)

' Add file attributes.


sb.Append("File: " & thisFile.FullName)
sb.Append(vbCrLf)
sb.Append("Modified: " & thisFile.LastWriteTime.ToString)
sb.Append(vbCrLf)
sb.Append("Size: " & thisFile.Length.ToString & " bytes")
sb.Append(vbCrLf)

' Open the text file.


Dim sr As System.IO.StreamReader =
My.Computer.FileSystem.OpenTextFileReader(filePath)

' Add the first line from the file.


If sr.Peek() >= 0 Then
sb.Append("First Line: " & sr.ReadLine())
End If
sr.Close()

Return sb.ToString
End Function

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


As System.EventArgs) Handles filesListBox.SelectedIndexChanged
SetEnabled()
End Sub

Private Sub SetEnabled()


Dim anySelected As Boolean =
(filesListBox.SelectedItem IsNot Nothing)

examineButton.Enabled = anySelected
saveCheckBox.Enabled = anySelected
End Sub

Ejemplo completo utilizando System.IO


El siguiente ejemplo equivalente utiliza las clases del espacio de nombres System.IO en
lugar de utilizar los objetos My.Computer.FileSystem.
VB

' This example uses classes from the System.IO namespace.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)


Handles MyBase.Load
' Set the default directory of the folder browser to the current directory.
FolderBrowserDialog1.SelectedPath =
System.IO.Directory.GetCurrentDirectory()

SetEnabled()
End Sub
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 52 -

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


System.EventArgs) Handles browseButton.Click
If FolderBrowserDialog1.ShowDialog() = DialogResult.OK Then
' List files in the folder.
ListFiles(FolderBrowserDialog1.SelectedPath)
SetEnabled()
End If
End Sub

Private Sub ListFiles(ByVal folderPath As String)


filesListBox.Items.Clear()

Dim fileNames As String() =


System.IO.Directory.GetFiles(folderPath,
"*.txt", System.IO.SearchOption.TopDirectoryOnly)

For Each fileName As String In fileNames


filesListBox.Items.Add(fileName)
Next
End Sub

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


System.EventArgs) Handles examineButton.Click
If filesListBox.SelectedItem Is Nothing Then
MessageBox.Show("Please select a file.")
Exit Sub
End If

' Obtain the file path from the list box selection.
Dim filePath = filesListBox.SelectedItem.ToString

' Verify that the file was not removed since the
' Browse button was clicked.
If System.IO.File.Exists(filePath) = False Then
MessageBox.Show("File Not Found: " & filePath)
Exit Sub
End If

' Obtain file information in a string.


Dim fileInfoText As String = GetTextForOutput(filePath)

' Show the file information.


MessageBox.Show(fileInfoText)

If saveCheckBox.Checked = True Then


' Place the log file in the same folder as the examined file.
Dim logFolder As String =
System.IO.Path.GetDirectoryName(filePath)
Dim logFilePath = System.IO.Path.Combine(logFolder, "log.txt")

' Append text to the log file.


Tecnologia de base de datos 2016B \9 Reportes parte 2 - 53 -

Dim logText As String = "Logged: " & Date.Now.ToString &


vbCrLf & fileInfoText & vbCrLf & vbCrLf

System.IO.File.AppendAllText(logFilePath, logText)
End If
End Sub

Private Function GetTextForOutput(ByVal filePath As String) As String


' Verify that the file exists.
If System.IO.File.Exists(filePath) = False Then
Throw New Exception("File Not Found: " & filePath)
End If

' Create a new StringBuilder, which is used


' to efficiently build strings.
Dim sb As New System.Text.StringBuilder()
' Obtain file information.
Dim thisFile As New System.IO.FileInfo(filePath)
' Add file attributes.
sb.Append("File: " & thisFile.FullName)
sb.Append(vbCrLf)
sb.Append("Modified: " & thisFile.LastWriteTime.ToString)
sb.Append(vbCrLf)
sb.Append("Size: " & thisFile.Length.ToString & " bytes")
sb.Append(vbCrLf)

' Open the text file.


Dim sr As System.IO.StreamReader =
System.IO.File.OpenText(filePath)
' Add the first line from the file.
If sr.Peek() >= 0 Then
sb.Append("First Line: " & sr.ReadLine())
End If
sr.Close()
Return sb.ToString
End Function

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


As System.EventArgs) Handles filesListBox.SelectedIndexChanged
SetEnabled()
End Sub

Private Sub SetEnabled()


Dim anySelected As Boolean =
(filesListBox.SelectedItem IsNot Nothing)

examineButton.Enabled = anySelected
saveCheckBox.Enabled = anySelected
End Sub
Vea tambin
System.IO
FileSystem
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 54 -

CurrentDirectory
Tutorial: Manipular archivos utilizando mtodos de .NET Framework (Visual Basic)
ImprimirExportar (0)Compartir
EN ESTE ARTCULO
Ejemplo completo utilizando My.Computer.FileSystem
Ejemplo completo utilizando System.IO
Vea tambin

MACROS EN EXCEL (Ver documento adjunto)

Module Module1
Function MAYORNOTAS(N1 As Single, N2 As Single, N3 As Single) As Single
Dim MENOR As Single = N1
Dim SUMA As Single
If N2 < MENOR Then
MENOR = N2
End If
If N3 < MENOR Then
MENOR = N3
End If
SUMA = N1 + N2 + N3 - MENOR
SUMA = SUMA / 2.0
Return SUMA
'MAYORNOTAS = SUMA
End Function
Sub MAIN()
Dim RES As Single
RES = MAYORNOTAS(1, 2, 3)
Console.WriteLine(" EL PROMEDIO ES {0}", RES)
Console.ReadLine()
End Sub
End Module

Sistema alumnos
Creacion de tablas
CREATE TABLE ALUMNOS
( cui char(8),
Nombre varchar(20),
Foto varchar(50),
primary key (cui))
Tecnologia de base de datos 2016B \9 Reportes parte 2 - 55 -

insert into alumnos (


cui,nombre, foto) values(
'2014a4','PEREZ/QUISPE,JUAN', 'FOTO1')

DSASD ASDSSD

ALUMNOS CURSOS
CUI NOMBRE FOTO CODCURSO NOMBRECURSO PROFESOR
SISTEMAS DE
A1 JUAN FOTO1 C1 INFORMACION CRUZ
A2 PEDRO FOTO2 C2 VISUAL BASIC CARRASCO
AUTOMATIZACION
A3 LUIS FOTO3 C3 INDUSTRIA VELIZ
A4 JULIO FOTO4 C4 BASE DE DATOS MARQUINA

LISTADOS POR
MATRICULAS CURSO
SISTEMAS DE
NRO CUI CODCURSO C1 INFORMACION
1 A1 C1 A1 JUAN
2 A1 C2 A2 PEDRO
3 A2 C1 A3 LUIS
4 A4 C2
5 A1 C3
6 A3 C1
7 A4 C3 VISUAL BASIC
8 A2 C4 A1 JUAN
A4 JULIO

enviar informacion de visual a otro software ejemplo belnder labview proteus etc

You might also like