Você está na página 1de 15

Sistemas de Informacion 2015B \1. Modo Consola\ I.

Vliz Vilca

NR
O TEMA
VISUAL BASIC
MODO
1 CONSOLA
FORMULARIOS
2 Y CONTROLES
CLASES Y
3 OBJETOS

SE
MA CALE
NA NDAR
S
IOS
tareas
2 SET

2 SET
2 OCT

4 BASE DE DATOS

1 OCT

5 SQL

2 OCT

6 ADONET
ADO NET EN
7 WINDOWS
8 REPORTES
HERRAMIENTAS
9 WEB
DESARROLLO
10 DEL SISTEMA
EVALUACIONES
11 Y TRABAJOS
TOTAL

2 NOV

1.Cadena y archivos
2.menu y barra de
herramientas y
aplicaciones de
recursividad
3.clase definido por el
grupo
4. creacion de base de
datos y practica de SQL

-1-

FUENTE
Libro Visual Basic

Libro Visual Basic


guia de practicas
semestre anterior
guia de practicas
semestre anterior
guia de practicas
semestre anterior
5. ver sistema de ventas video de sistema de
o similar
ventas

2 NOV
1 DIC
1 DIC
1 DIC
1 DIC
17

6. revisar la parte de
porgrmacion del sistema dejado por le Ing Cruz
7.trabajo de
investigacion opcional
libre

VISUAL BASIC MODO CONSOLA


Se debe realizar los ejercicis de l libro de Visual Basic 2012 hasta archivos
1. operaciones matemticas
Realizar las operaciones matematicas
Module Module1
Dim NRO1, NRO2, suma As Single
Sub Main()
Console.Write("INGRESE PRIMER Numero")
NRO1 = Console.ReadLine
Console.Write("INGRESE Segundo Numero")
NRO2 = Console.ReadLine
Console.WriteLine("LA SUMA ES {0}", NRO1 + NRO2)
Console.WriteLine("LA RESTA ES {0}", NRO1 - NRO2)
Console.WriteLine("LA MULTIPLICACION ES {0}", NRO1 * NRO2)
Console.WriteLine("LA DIVISION ENTERA ES {0}", NRO1 \ NRO2)
Console.WriteLine("LA DIVISION REAL ES {0}", NRO1 / NRO2)
Console.WriteLine("EL MODULO ES ES {0}", NRO1 Mod NRO2)

Sistemas de Informacion 2015B \1. Modo Consola\ I.Vliz Vilca

-2-

Console.WriteLine("EL MODULO ES ES {0}", Int(NRO1) Mod Int(NRO2))


'Console.WriteLine("{0} ELEVADO A {1} es = {2}", NRO1, NRO2,nro )
Console.WriteLine("{0} ELEVADO A {1} es = {2}", NRO1, NRO2, Math.Pow(NRO1,
NRO2))
Console.WriteLine("raiz de {0} es {1}", NRO1, Math.Pow(NRO1, 0.333))
Console.ReadLine()
End Sub
End Module

Ejercicio de Manejo de Consola

Module Module1
Sub Main()
Console.Clear()
Console.SetCursorPosition(30, 12)
Console.ForegroundColor = 10
Console.BackgroundColor = 12
Console.Write("LETRA DE COLOR VERDE EN FONDO ROJO")
Console.ReadLine()
End Sub
End Module
ARCHIVOS
Escritura de archivo
Imports System.IO

Sistemas de Informacion 2015B \1. Modo Consola\ I.Vliz Vilca

-3-

Module Module1
Sub Main()
Dim swEscritor As StreamWriter
Dim NombreArchivo = "E:\DATOS\NOTAS.txt"
swEscritor = New StreamWriter(NombreArchivo)
swEscritor.Write("Ejemplo de archivo de texto")
swEscritor.WriteLine("Ingenieria Industrial")
swEscritor.WriteLine("2015")
swEscritor.Close()
Console.WriteLine(" archivo {0} grabado satisfactoriamente", NombreArchivo)
Console.ReadLine()
End Sub
End Module

a. Escribir n lneas de texto

Imports System.IO
Module Module1
Sub Main()
Dim swEscritor As StreamWriter
Dim Cadena As String
Dim NombreArchivo = "E:\DATOS\NOTAS1.txt"
swEscritor = New StreamWriter(NombreArchivo)
Console.WriteLine("ingrese lineas de texto vacio para terminar")
Cadena = Console.ReadLine()
Do While Not (Cadena = "")
swEscritor.WriteLine(Cadena)
Cadena = Console.ReadLine()

Sistemas de Informacion 2015B \1. Modo Consola\ I.Vliz Vilca

-4-

Loop
swEscritor.Close()
Console.WriteLine("Archivo grabado satisfactoriamente")
Console.ReadLine()
End Sub
End Module

B Lectura de Archivos
Imports System.IO
Module Module1
Sub main()
Dim srLector As StreamReader = New StreamReader("e:\DATOS\NOTAS.txt")
Dim Linea As String
Console.WriteLine("lectura de archivos")
Linea = srLector.ReadLine()
Do While Not (Linea Is Nothing)
Console.WriteLine(Linea)
Linea = srLector.ReadLine()
Loop
Console.ReadLine()
End Sub
End Module

Lee cadenas de texto copie cualquier dodumento de texto y lo lea

Sistemas de Informacion 2015B \1. Modo Consola\ I.Vliz Vilca

-5-

Imports System.IO
Module Module1
Sub main()
Dim srLector As StreamReader = New StreamReader("e:\DATOS\NOTAS.txt")
Dim Linea As String
Dim ContLinea As Integer = 0
Dim Nletras As Integer = 0
Dim NroCar(26) As Integer
Dim contletras As Integer = 0
Console.WriteLine("Lectura de archivos")
Dim i, j As Integer
Linea = srLector.ReadLine()
Do While Not (Linea Is Nothing)
For i = 0 To 26 - 1
contletras = 0
For j = 0 To Len(Linea) - 1
If Linea(j) = Chr(65 + j) Then contletras = contletras + 1
Next
NroCar(i) = contletras
Next
Console.WriteLine(" {0}= nletras {1} contenido {2} ", ContLinea, Len(Linea), Linea)
Nletras = Nletras + Len(Linea)
Linea = srLector.ReadLine()
ContLinea = ContLinea + 1
Loop
Console.WriteLine("nro lineas {0}, nro letras {1} ", ContLinea, Nletras)
Console.WriteLine("FRECUENCIA DE LETRAS ")
For i = 0 To 26 - 1
Console.WriteLine("{0} = {1} ", Chr(65 + i), NroCar(i))
Next
Console.ReadLine()
End Sub
End Module
Agregar cuantos letras tiene el archivo

Sistemas de Informacion 2015B \1. Modo Consola\ I.Vliz Vilca

-6-

Se quiere grabar los valores en un archivo texto para leer en Excel


Elaborar una aplicacin con las siguientes opciones
1. Generar.- se tiene una matriz de n filas por m columnas que representa las
alturas en un espacio 3d al principio todos las altura son cero , se generar un nro
aleatorio de filas y columnas entonces la celda A(rx,ry) crece en 1 y asi
sucesivamente hasta llegar a altura mxima de 15 , si la altura es mayor que 15
el elemento A(ry,yx) se vuelve a cero
2. Mostrar. Mostrar la matriz generada usando colores de acuerdo a las alturas
3. Recuperar. Recuperar un archivo grabado de Excel
4. Grabar .- graba el contenido de la matriz en un archivo de texto con
delimitadores para Excel
5. Simular. Simula las variaciones de las celdas de la matriz 3D un numero
determinado de veces
6. Salir

' *************modulo 2
Imports System.IO
Module Module2
Public Const maxcol As Integer = 40

Sistemas de Informacion 2015B \1. Modo Consola\ I.Vliz Vilca

-7-

Public Const maxfilas As Integer = 20


Public paso As Integer = 20
Public tam As Integer = 20
Public vel As Integer = 1
Public cont As Integer = 0
Public A(maxfilas, maxcol) As Integer
Public nf As Integer = 20, nc As Integer = 40
Public nveces As Integer = 1000
' Public NombreArchivo As String = "E:\DATOS\DATOS3D.txt"
Public NombreArchivo As String = "D:\DATOS\MATRIZ5x5.txt"
Public px As Integer = 5 ' posicion inicial del ser
Public py As Integer = 5 ' fila inicial del ser
Sub GenerarMatriz(A(,) As Integer, nf As Integer, nc As Integer)
Dim rx, ry As Integer
rx = Int(Rnd() * nc)
ry = Int(Rnd() * nf)
If rx < nc And ry < nf Then
If (A(ry, rx) < 255 - paso) Then ' era 16
A(ry, rx) = A(ry, rx) + paso
Else
' A(ry, rx) = 0
End If
End If
End Sub
Sub Iniciar(A(,) As Integer, nf As Integer, nc As Integer, valor As Integer)
Dim fila, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
A(fila, col) = valor
Next
Next
End Sub
Sub MostrarMatriz(cx As Integer, cy As Integer, A(,) As Integer, nf As Integer, nc As
Integer, ex As Integer)
Dim fila, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
Console.SetCursorPosition(cx + col * ex, cy + fila)
Console.ForegroundColor = A(fila, col)
Console.Write("{0}", Hex(A(fila, col)))
Next
Next
End Sub
Sub GrabarMatriz(Nombre As String, A(,) As Integer, nf As Integer, nc As Integer)
Dim swEscritor As StreamWriter
swEscritor = New StreamWriter(NombreArchivo)
Dim fila, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1

Sistemas de Informacion 2015B \1. Modo Consola\ I.Vliz Vilca

-8-

swEscritor.Write("{0}{1}", A(fila, col), vbTab)


Next
swEscritor.WriteLine()
Next
swEscritor.Close()
End Sub
Sub RecuperarMatriz(ByVal nombrearchivo As String, ByVal A(,) As Integer, ByVal nf
As Integer,
ByVal nc As Integer)
Try
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) = Val(subcadena)
inicio = pos + 1
Next
Next
srLector.Close()
Catch ex As Exception
MsgBox(ex.Message)
Finally
End Try
End Sub
End Module
CODIGO DEL MODULO 1
Module Module1
Dim nveces As Integer = 1000
Dim opcion As Integer
Dim i As Integer
Dim cx As Integer = 2
Dim cy As Integer = 2
Dim NombreMatriz2 As String = "D:\datos\matriz5x5copia.txt"
Sub main()
Randomize()
Do
Console.ForegroundColor = 15

Sistemas de Informacion 2015B \1. Modo Consola\ I.Vliz Vilca

-9-

Console.WriteLine("1. iniciar 2. mostrar 3. recuperar 4. grabar 5. simular 6


simular")
Console.WriteLine("Ingrese opcion ")
opcion = Console.ReadLine
Select Case opcion
Case 1 'iniciar
Iniciar(A, nf, nc, 0)
Case 2 'mostrar
Console.Clear()
MostrarMatriz(2, 2, A, nf, nc, 2)
Console.ReadLine()
Case 3 'mostrar
RecuperarMatriz(NombreArchivo, A, nf, nc)
Console.WriteLine(" archivo {0} recuperado satisfactoriamente",
NombreArchivo)
Case 4 ' Grabar
GrabarMatriz(NombreMatriz2, A, nf, nc)
Console.WriteLine(" archivo {0} grabdaod sistisfactoriamente",
NombreMatriz2)
Case 5 ' sinularr
Console.WriteLine("Cuantas veces hay que simular")
nveces = Console.ReadLine
For i = 0 To nveces - 1
GenerarMatriz(A, nf, nc)
MostrarMatriz(cx, cy, A, nf, nc, 2)
System.Threading.Thread.Sleep(1)
Next
End Select
Loop While opcion <> 6
Console.ReadLine()
End Sub
End Module

Hacerlo lo mimo pero en programacion visual

Sistemas de Informacion 2015B \1. Modo Consola\ I.Vliz Vilca

- 10 -

CODIGO DEL FORMULARIO


Imports System.Drawing
Public Class Form1
Dim grafico As Graphics
Dim brocha As SolidBrush
Dim pincel As Pen
Dim cx As Integer = 10
Dim cy As Integer = 10
Sub MostrarMatrizCuadricula(A(,) As Integer, nf As Integer, nc As Integer)
Dim fila, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
DataGridView1.Rows(fila).Cells(col).Value = A(fila, col)
Next
Next
End Sub
Private Sub btnInicair_Click(sender As Object, e As EventArgs) Handles
btnIniciar.Click
Iniciar(A, nf, nc, 0)
End Sub
Private Sub BtnMostrar_Click(sender As Object, e As EventArgs) Handles
btnMostrar.Click
MostrarMatrizCuadricula(A, nf, nc)
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DataGridView1.ColumnCount = nc
DataGridView1.RowCount = nf
For col = 0 To nc - 1
DataGridView1.Columns(col).Width = 30
Next
TextBox1.Text = vel
grafico = PictureBox1.CreateGraphics
brocha = New SolidBrush(Color.Red)
pincel = New Pen(Brushes.Red, 2)
End Sub
Private Sub BtnRecuperar_Click(sender As Object, e As EventArgs) Handles
BtnRecuperar.Click
OpenFileDialog1.ShowDialog()
NombreArchivo = OpenFileDialog1.FileName
RecuperarMatriz(NombreArchivo, A, nf, nc)
MostrarMatrizCuadricula(A, nf, nc)
End Sub
Private Sub btnGrabar_Click(sender As Object, e As EventArgs) Handles
btnGrabar.Click

Sistemas de Informacion 2015B \1. Modo Consola\ I.Vliz Vilca

- 11 -

SaveFileDialog1.ShowDialog()
NombreArchivo = SaveFileDialog1.FileName
GrabarMatriz(NombreArchivo, A, nf, nc)
MsgBox(" matriz grabada satisfactoriamente")
End Sub
Private Sub BtnSimular_Click(sender As Object, e As EventArgs) Handles
BtnSimular.Click
vel = Val(TextBox1.Text)
Timer1.Interval = vel
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
GenerarMatriz(A, nf, nc)
MostrarMatrizCuadricula(A, nf, nc)
btnGraficar_Click(sender, e)
TextBox2.Text = cont
cont = cont + 1
End Sub
Private Sub btnDetener_Click(sender As Object, e As EventArgs) Handles
btnDetener.Click
Timer1.Stop()
End Sub
Private Sub btncambiarColor_Click(sender As Object, e As EventArgs) Handles
btncambiarColor.Click
ColorDialog1.ShowDialog()
Me.BackColor = ColorDialog1.Color
btnIniciar.ForeColor = ColorDialog1.Color
End Sub
Private Sub btnCambiarLetra_Click(sender As Object, e As EventArgs) Handles
btnCambiarLetra.Click
FontDialog1.ShowDialog()
TextBox2.Font = FontDialog1.Font
btnIniciar.Font = FontDialog1.Font
End Sub
Private Sub btnDirectorio_Click(sender As Object, e As EventArgs) Handles
btnDirectorio.Click
Dim cadena As String
FolderBrowserDialog1.ShowDialog()
cadena = FolderBrowserDialog1.SelectedPath
Me.Text = cadena
End Sub

Sistemas de Informacion 2015B \1. Modo Consola\ I.Vliz Vilca

- 12 -

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


btnGraficar.Click
Dim fila, col As Integer
Dim rojo, verde, azul As Integer
verde = 0
azul = 0
grafico = PictureBox1.CreateGraphics
pincel = New Pen(Color.Red, 2)
For fila = 0 To nf - 1
For col = 0 To nc - 1
rojo = A(fila, col)
brocha = New SolidBrush(Color.FromArgb(rojo, verde, azul))
grafico.FillRectangle(brocha, cx + col * tam, cy + fila * tam, tam, tam)
Next
Next
End Sub
Private Sub btnManual_Click(sender As Object, e As EventArgs) Handles
btnManual.Click
GenerarMatriz(A, nf, nc)
MostrarMatrizCuadricula(A, nf, nc)
TextBox2.Text = cont
cont = cont + 1
End Sub
End Class

TAREA. MOSTRAR EL resultado en grafico


Hacer grafico en Excel
Aumentar erosion
DICCIONARIO. Este diccionario ha sido bajado de internet , se ha hecho el program en
visual basic modo consola y modo formulario

Sistemas de Informacion 2015B \1. Modo Consola\ I.Vliz Vilca

- 13 -

Imports System.IO
Module Module1
Public A(25000, 2) As String
Public nf As Integer
Sub LeerArchivo(A(,) As String, ByRef nf As Integer)
Dim srLector As StreamReader = New StreamReader("e:\DATOS\DIC1.txt")
Dim Linea As String
Dim cont As Integer = 0
Dim pos As Integer
Linea = srLector.ReadLine()
Do While Not (Linea Is Nothing)
pos = InStr(1, Linea, Chr(9))
A(cont, 0) = Mid(Linea, 1, pos - 1)
A(cont, 1) = Mid(Linea, pos + 1, Len(Linea))
cont = cont + 1
Linea = srLector.ReadLine()
Loop

Sistemas de Informacion 2015B \1. Modo Consola\ I.Vliz Vilca

- 14 -

nf = cont
End Sub
Sub BuscarInglesCastellano(A(,) As String, Ingles As String, nf As Integer)
Dim i As Integer
Dim largo As Integer
Dim cont1 As Integer = 0
For i = 0 To nf - 1
largo = InStr(A(i, 0), Ingles)
If largo > 0 Then
Console.WriteLine(" {0}===> {1} ====>{2}", cont1, A(i, 0), A(i, 1))
cont1 = cont1 + 1
End If
Next
Console.WriteLine("Palabras encontradas{0}", cont1)
End Sub
Sub BuscarCastellanoIngles(A(,) As String, Castellano As String, nf As Integer)
Dim i As Integer
Dim largo As Integer
Dim cont1 As Integer = 0
For i = 0 To nf - 1
largo = InStr(A(i, 1), Castellano)
If largo > 0 Then
Console.WriteLine(" {0}===> {1} ====>{2}", cont1, A(i, 1), A(i, 0))
cont1 = cont1 + 1
End If
Next
Console.WriteLine("Palabras encontradas{0}", cont1)
End Sub
Sub Main()
LeerArchivo(A, nf)
Dim opcion As Integer
Dim Ingles, Castellano As String
Do
Console.WriteLine("1. Ingles castellano 2. Castellano Ingles 3.Salir ")
Console.Write("ingrese opcion ")
opcion = Console.ReadLine()
Select Case opcion
Case 1
Console.WriteLine("Ingrese palabra en Ingls ")
Ingles = Console.ReadLine
BuscarInglesCastellano(A, Ingles, nf)
Case 2
Console.WriteLine("Ingrese palabra en Castellano ")
Castellano = Console.ReadLine
BuscarCastellanoIngles(A, Castellano, nf)
End Select
Loop While opcion <> 3
End Sub
End Module

Sistemas de Informacion 2015B \1. Modo Consola\ I.Vliz Vilca

ELABORAR MENU
RICHTEXTBOX

BARRA DE

HERRAMIENTAS

- 15 -

CON

EL

CONTROL

Você também pode gostar