Reportes Visual Basic
Reportes Visual Basic
Reportes Visual Basic
-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
-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
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
-3-
-4-
N1
N2
10
11
20
5
11
N3
11
14
18
4
12
12
13
18
8
12
-5-
-6-
Next
End Sub
Sub main()
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
-7-
-8-
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 = "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
-9-
- 10 -
- 11 -
Elabore una simulacin usando este control (por ejemplo el juego de la vida)
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
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)
- 12 -
- 13 -
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
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
- 14 -
- 15 -
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
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
- 16 -
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 = 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
- 17 -
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
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
- 18 -
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))
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)
- 19 -
- 20 -
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"
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)
- 21 -
- 22 -
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
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))
- 23 -
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)
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
- 24 -
- 25 -
Aparece lo siguiente
- 26 -
- 27 -
Aparece lo siguiente
- 28 -
- 29 -
Se Obtiene
Seleccione la imagen
- 30 -
- 31 -
SE Tiene
- 32 -
- 33 -
Y se tiene el informe
Configurar pagina
Exportar
PRUEBE buscar
- 34 -
- 35 -
Formatear el datagridview
- 36 -
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
Private Sub DataGridView1_CellContentClick(sender As Object, e As
DataGridViewCellEventArgs) Handles DataGridView1.CellClick
- 37 -
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
Public ncol As Integer = 3
Public fila, col As Integer
- 38 -
CONTROL MULTIMEDIA
- 39 -
- 40 -
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
- 41 -
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
- 42 -
- 43 -
Sistema alumnos
Creacion de tablas
CREATE TABLE ALUMNOS
( cui char(8),
Nombre varchar(20),
Foto varchar(50),
primary key (cui))
insert into alumnos (
cui,nombre, foto) values(
'2014a4','PEREZ/QUISPE,JUAN', 'FOTO1')
ALUMNO
S
CUI
NOMBRE
FOTO
CURSOS
CODCUR
SO
A1
JUAN
FOTO1
C1
A2
PEDRO
FOTO2
C2
A3
LUIS
FOTO3
C3
VISUAL BASIC
AUTOMATIZACION
INDUSTRIA
A4
JULIO
FOTO4
C4
BASE DE DATOS
C1
A1
A2
A3
A1
A4
VISUAL BASIC
JUAN
JULIO
MATRICULAS
NRO
1
2
3
4
5
6
7
8
CUI
A1
A1
A2
A4
A1
A3
A4
A2
CODCUR
SO
C1
C2
C1
C2
C3
C1
C3
C4
NOMBRECURSO
SISTEMAS DE
INFORMACION
PROFESO
R
CRUZ
CARRASC
O
VELIZ
MARQUIN
A