Escolar Documentos
Profissional Documentos
Cultura Documentos
Vliz Vilca
-1-
-2-
-3-
Option Explicit On
Module Module1
Dim n1, n2 As Single
Dim opcion As Integer
Sub Main()
Do
Console.WriteLine("1. Ingresar 2.sumar 3.resto 4.multiplico, 5 divido 6 Salir ")
Console.Write("ingrese opcion")
opcion = Console.ReadLine
Select Case opcion
Case 1 ' es la opcion ingresar"
Console.Write("INGRESE PRIMER Numero") : n1 = Console.ReadLine
Console.Write("INGRESE Segundo Numero") : n2 = Console.ReadLine
Case 2 ' es la opcion sumar"
Console.WriteLine("LA SUMA ES {0}", n1 + n2)
Case 3 ' es la opcion RESTA"
Console.WriteLine("LA RESTA ES {0}", n1 - n2)
Case 4 ' es la opcion MULTIPLICACION"
Console.WriteLine("LA MULTIPLICACION ES {0}", n1 * n2)
Case 5 ' es la opcion DIVISION"
Console.WriteLine("LA SUMA ES {0}", n1 / n2)
Case 6
Case Else
Console.WriteLine("opcion erronea")
End Select
Loop While opcion <> 6
End Sub
End Module
Ejercicio Nro 3
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)
Console.ReadLine()
End Sub
End Module
-4-
-5-
opcion = Console.ReadLine
Select Case opcion
Case 1
Console.Write("INGRESE PRIMER NUMERO")
n1 = Console.ReadLine()
Console.Write("INGRESE SEGUNDO NUMERO")
N2 = Console.ReadLine()
Case 2 : Console.WriteLine("la suma es {0} ", n1 + N2)
Case 3
Console.WriteLine("la resta es {0} ", n1 - N2)
Case 4
Console.WriteLine("la multiplicacion es {0} ", n1 * N2)
Case 5
Console.WriteLine("la division reales {0} ", n1 / N2)
Case Else
Console.WriteLine("Numero erroneo ")
End Select
'Loop While opcion <> 6
Loop Until opcion = 6
Console.ReadLine()
End Sub
End Module
-6-
Module Module1
Function fact(ByVal N As Integer) As Integer
Dim f = 1, i As Integer
For i = 1 To N
f=f*i
Next
Return f
End Function
Sub Main()
Dim n, r, combi As Integer
Console.Write("Ingrese un n ")
n = CInt(Console.ReadLine())
Console.Write("Ingrese r ")
r = CInt(Console.ReadLine())
Console.WriteLine("El factorial de {0} es {1} ", n, fact(n))
combi = fact(n) / (fact(r) * fact(n - r))
Console.WriteLine("la combinatoria de {0} en {1} es ={2} ", n, r, combi)
Console.ReadLine()
End Sub
End Module
-7-
-8-
-9-
Module Module1
Sub Main()
Dim Ancho As Integer = 60
Dim alto As Integer = 20
Dim px As Integer = 20
Dim py As Integer = 2
Dim rancho, ralto, rx, ry, color1, color2, frec, duracion As Integer
Randomize()
Dim opcion As Integer = 0
Dim cont As Integer = 0
'Dim frec As inte
Do
rancho = Int(Rnd() * 60)
ralto = Int(Rnd() * 20)
rx = 1 + Int(Rnd() * 60)
ry = 1 + Int(Rnd() * 20)
rx = Int(Rnd() * 15)
ry = Int(Rnd() * 15)
color1 = 1 + Int(Rnd() * 15)
color2 = 1 + Int(Rnd() * 15)
frec = 37 + Int(Rnd() * 5000)
duracion = 10 + Rnd(200)
If (color1 > 15) Then color1 = 15
If (color2 > 15) Then color2 = 15
If (rx + rancho < 80 And ry + ralto < 24) Then
Cuadro(rx, ry, rancho, ralto, color1, color1)
Console.Beep(frec, duracion)
'System.Threading.Thread.Sleep(duracion) ' 1 segundo
End If
cont = cont + 1
If cont Mod 10 = 0 Then
Console.BackgroundColor = 0
Console.Clear()
End If
Loop Until cont > 1000
Console.ReadLine()
End Sub
End Module
4. Modificar el programa para mover aleatoriamente un objeto
Module Module2
Sub Cuadro(cx As Integer, cy As Integer, ancho As Integer, alto As Integer, color1 As
Integer, color2 As Integer)
Console.ForegroundColor = color1
Console.BackgroundColor = color2
Dim fila, col As Integer
For fila = 0 To alto
- 10 -
- 11 -
Dim x As Integer = 40
Dim y As Integer = 12
Console.WriteLine("Press any combination of CTL, ALT, and SHIFT, and a console
key.")
Console.WriteLine("Press the Escape (Esc) key to quit: " + vbCrLf)
Console.SetCursorPosition(x, y)
Console.Write("hola")
Do
cki = Console.ReadKey()
If cki.Key = ConsoleKey.LeftArrow And x > x1 Then x = x - 1
If cki.Key = ConsoleKey.RightArrow And x < x2 Then x = x + 1
If cki.Key = ConsoleKey.UpArrow And y > y1 Then y = y - 1
If cki.Key = ConsoleKey.DownArrow And y < y2 Then y = y + 1
Console.Clear()
Console.SetCursorPosition(x, y)
Console.Write("hola")
Loop While cki.Key <> ConsoleKey.Escape
End Sub
End Module
Module Module1
Sub main()
Dim cki As ConsoleKeyInfo
Dim x1 As Integer = 2 ' limite x inferior
Dim y1 As Integer = 2 ' limite x superior
Dim x2 As Integer = 60 ' limite y inferior
Dim y2 As Integer = 20 ' limite y superior
Dim x As Integer = 40
Dim y As Integer = 12
- 12 -
Option Explicit On
Option Strict On
Module Module1
Function fact(ByVal n As Integer) As Integer
- 13 -
Dim f As Integer
If (n > 1) Then
f = n * fact(n - 1) REM parte recursiva
Else
f = 1 REM parte no recursiva
End If
Return f
End Function
Sub main()
Dim f, n As Integer
Console.Write("Ingrese un numero ")
n = CInt(Console.ReadLine())
Console.WriteLine("El factorial de ese numero es {0} ", fact(n))
Console.ReadLine()
End Sub
End Module
Valor final =120
5!
5!
5!=5*4=120 es regresando
5 * 4!
5 * 4!
4!= 4* 6 = 24 es regresando
4*3!
4 * 3!
3!=3*2 = 6 Regresando
3*2!
3 * 2!
2!=2*1= 2 es regresando
2* 1!
2 * 1!
1 es regresando
A
b
a)Secuencia de llamadas recursivas b) valores regresados de cada llamada recursiva
7 funcin recursiva de tipo void
imprimir(3)
SI
x>1
NO
imprimir(2)
SI
x>1
imprimir(1)
NO
x>1
NO
X=1
X=2
X=3
- 14 -
Option Explicit On
Option Strict On
Module Module1
Sub imprimir(ByVal x As Integer)
If (x > 1) Then imprimir(x - 1)
Console.Write("{0} ", x)
End Sub
Sub main()
Dim num As Integer
Console.Write("Ingrese un Numero ")
num = CInt(Console.ReadLine())
imprimir(num)
Console.ReadLine()
End Sub
End Module
- 15 -
- 16 -
Option Explicit On
Option Strict On
Imports System.IO
Module MODULE1
Function gradosRad(ByVal grados As Single) As Single
gradosRad = CSng(grados * Math.PI / 180)
End Function
Sub Main()
Dim grados As Single, rad As Single
Dim contador As Integer = 1
grados = 5
Console.WriteLine(" {0,4} {1,6} {2,8} {3,8} {4,8} {5,8}", "NRO", "GRADOS",
"RADIANES", "SENO", "COSENO", "TANGENTE")
For grados = 0 To 360 Step 5
rad = gradosRad(grados)
Console.WriteLine(" {0,4:d} {1,6:F2} {2,8:F4} {3,8:F4} {4,8:F4} {5,8:F4} ",
contador, grados, rad, Math.Sin(rad), Math.Cos(rad), Math.Tan(rad))
contador += 1
Next
Console.ReadLine()
REM grabar los datos para exportarlos a excel
Dim NombreArchivo As String = "E:\DATOS\TRIGONOTRIA.txt"
Dim swEscritor As StreamWriter
contador = 0
swEscritor = New StreamWriter(NombreArchivo)
grados = 5
- 17 -
swEscritor.WriteLine(" {0,4} {1} {2,6} {3} {4,8} {5} {6,8} {7}{8,8}{9} {10,10}", "NRO",
Chr(9), "GRADOS", Chr(9), "RADIANES", Chr(9), "SENO", Chr(9), "COSENO", Chr(9),
"TANGENTE")
For grados = 0 To 360 Step 5
rad = gradosRad(grados)
swEscritor.WriteLine("{0,4:d3} {1} {2,6:f2} {3} {4,8:f4} {5} {6,8:F4} {7}{8,8:F4}{9}
{10,10:F4} ", contador, Chr(9), grados, Chr(9), rad, Chr(9), Math.Sin(rad), Chr(9),
Math.Cos(rad), Chr(9), Math.Tan(rad))
contador += 1
Next
swEscritor.Close()
Console.WriteLine(" Archivo {0} grabado satisfactoriamente", NombreArchivo)
Console.ReadLine()
End Sub
End Module
DICCIONARIO. Este diccionario ha sido bajado de internet , se ha hecho el program en
visual basic modo consola y modo formulario
- 18 -
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
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
- 19 -
Module Module2
Const maxcol As Integer = 10
Public Structure punto
Dim nro As Integer
Dim color As Integer
Dim caracter As Integer
Dim x As Single
Dim y As Single
End Structure
Public A(maxcol) As punto
Sub ImprimirSer(ByVal A() As punto, ByVal n As Integer)
Dim fila As Integer
For fila = 0 To n - 1
Console.BackgroundColor = CType(A(fila).color, ConsoleColor)
Console.ForegroundColor = CType(A(fila).color, ConsoleColor)
Console.SetCursorPosition(A(fila).x, A(fila).y)
Console.Write("{0}", Chr(A(fila).caracter))
Next
End Sub
End Module
Imports System.IO
Module Module1
Dim cki As ConsoleKeyInfo
Sub main()
Dim n As Integer = 8, fila As Integer
Dim cx As Integer = 40
Dim cy As Integer = 12
A(0).x = 40 : A(0).y = 10 : A(0).color = 9 : A(0).caracter = 219
A(1).x = 39 : A(1).y = 10 : A(1).color = 10 : A(1).caracter = 219
A(2).x = 38 : A(2).y = 10 : A(2).color = 12 : A(2).caracter = 219
A(3).x = 37 : A(3).y = 10 : A(3).color = 13 : A(3).caracter = 219
A(4).x = 36 : A(4).y = 10 : A(4).color = 14 : A(4).caracter = 177
A(5).x = 35 : A(5).y = 10 : A(5).color = 15 : A(5).caracter = 178
A(6).x = 34 : A(6).y = 10 : A(6).color = 11 : A(6).caracter = 177
A(7).x = 33 : A(7).y = 10 : A(7).color = 7 : A(7).caracter = 220
Call ImprimirSer(A, n)
cx = CInt(A(0).x)
cy = CInt(A(0).y)
Do
cki = Console.ReadKey()
If cki.Key = ConsoleKey.LeftArrow And cx > 1 Then cx = cx - 1
If cki.Key = ConsoleKey.RightArrow And cx < 79 Then cx = cx + 1
If cki.Key = ConsoleKey.UpArrow And cy > 1 Then cy = cy - 1
If cki.Key = ConsoleKey.DownArrow And cy > 1 Then cy = cy + 1
' modificamos el ser
For fila = n - 1 To 1 Step -1
A(fila).x = A(fila - 1).x
A(fila).y = A(fila - 1).y
Next
A(0).x = cx
A(0).y = cy
REM
System.Threading.Thread.Sleep(20)
Console.BackgroundColor = 0
Console.Clear()
Call ImprimirSer(A, n)
Loop While cki.Key <> ConsoleKey.Escape
End Sub
End Module
Modificacin del programa
- 20 -
Module Module2
Const maxcol As Integer = 10
Public coordX As Integer = 40
Public coordY As Integer = 12
Public Structure punto
Dim nro As Integer
Dim color As Integer
Dim caracter As Integer
Dim x As Single
Dim y As Single
End Structure
Public A(maxcol) As punto
Sub Cuadro(cx As Integer, cy As Integer, lado As Integer)
Dim fila, col As Integer
For fila = 0 To lado - 1
For col = 0 To lado - 1
Console.SetCursorPosition(cx - lado / 2 + col, cy - lado / 2 + fila)
Console.Write("*")
Next
Next
'Console.SetCursorPosition(cx, cy)
'Console.Write("X")
End Sub
Sub ImprimirSer(ByVal A() As punto, ByVal n As Integer, lado As Integer)
Dim fila As Integer
For fila = 0 To n - 1
Console.BackgroundColor = CType(A(fila).color, ConsoleColor)
Console.ForegroundColor = CType(A(fila).color, ConsoleColor)
Cuadro(coordX + A(fila).x * lado, coordY + A(fila).y * lado, lado)
Next
End Sub
End Module
CODIGO DEL MODULO 1
Imports System.IO
Module Module1
- 21 -
- 22 -
- 23 -
End Sub
End Module
El mismo ejercicio en modo formulario
- 24 -
cy = CInt(A(0).y)
Dim valor As Integer = 0
Select Case e.KeyCode
Case Keys.Left
If cx > -AnchoFigura / (ancho * 2) + 3 Then
cx = cx - 1
valor = 1
End If
Case Keys.Right
If cx < AnchoFigura / (ancho * 2) - 1 Then
cx = cx + 1
valor = 1
End If
Case Keys.Up
If cy > -AltoFigura / (alto * 2) + 1 Then
cy = cy - 1
valor = 1
End If
Case Keys.Down
If cy < AltoFigura / (alto * 2) - 1 Then
cy = cy + 1
valor = 1
End If
End Select
' modificamos el ser solo si es posible
If valor = 1 Then
For fila = n - 1 To 1 Step -1
A(fila).x = A(fila - 1).x
A(fila).y = A(fila - 1).y
Next
A(0).x = cx
A(0).y = cy
End If
Grafico.Clear(Color.Black)
Call ImprimirSer(n, ancho, alto)
End Sub
End Class
Modifique el programa que en vez de cuadro sea una figura
REALIZAR EJERCICIOS ADICIONALES
- 25 -
- 26 -
- 27 -
- 28 -
")
- 29 -
- 30 -
- 31 -
End If
End If
Console.SetCursorPosition(30 + rx, 5 + ry)
Console.ForegroundColor = A(ry, rx)
Console.Write("{0}", Hex(A(ry, rx)))
REM VerMatriz(30, 5, A, nf, nc)
System.Threading.Thread.Sleep(1)
Console.SetCursorPosition(1, 3)
Console.Write("{0}", i)
Next
Case 6 ' generar funcion
GenerarFuncion(A, nf, nc)
Console.ForegroundColor = 15
Console.SetCursorPosition(1, 4)
Console.WriteLine("presione tecla para continuar")
Console.ReadLine()
Case 7 ' sumar
Iniciar(A, nf, nc, minimo)
'generarSumaResta(A, px, py, nf, nc, 1)
MostrarMatriz(5, 5, A, nf, nc, 2)
' Console.ReadLine()
Console.ForegroundColor = 15
Console.SetCursorPosition(1, 3)
Console.Write("Nro de veces que quiere generar ")
nveces = Console.ReadLine
For i = 1 To nveces
generarSumaResta(A, px, py, nf, nc, 1)
MostrarMatriz(5, 5, A, nf, nc, 2)
System.Threading.Thread.Sleep(1)
Next
Console.ReadLine()
Case 8 ' Restar
Iniciar(A, nf, nc, maximo)
MostrarMatriz(5, 5, A, nf, nc, 2)
Console.SetCursorPosition(1, 3)
Console.Write("Nro de veces que quiere generar ")
nveces = Console.ReadLine
For i = 1 To nveces
generarSumaResta(A, px, py, nf, nc, 2)
MostrarMatriz(5, 5, A, nf, nc, 2)
System.Threading.Thread.Sleep(1)
Next
Console.ReadLine()
End Select
Loop Until opcion = 9
End Sub
End Module
EN MODO FORMULARIO
- 32 -
- 33 -
- 34 -
valor = 1
End If
Case 3
If py > 0 Then
py = py - 1
valor = 1
End If
End Select
If valor = 1 Then
Select Case tipo
Case 1 ' si es suma
If A(py, px) < maximo Then
A(py, px) = A(py, px) + 1
Else
A(py, px) = minimo
End If
Case 2 ' si es resta
If A(py, px) > minimo Then
A(py, px) = A(py, px) - 1
Else
A(py, px) = maximo
End If
End Select
End If
End Sub
Function f(x As Single, y As Single) As Single
Dim funcion As Single = Math.Pow(x, 2) + Math.Pow(y, 2)
Dim valor As Single
If (funcion <> 0) Then
valor = Math.Sin(funcion) / funcion
Else
valor = 1
End If
Return valor
End Function
Sub GenerarMatriz(A(,) As Integer, nf As Integer, nc As Integer, nveces As Integer)
Dim rx, ry As Integer
Dim i As Integer
For i = 1 To nveces
rx = Int(Rnd() * nc)
ry = Int(Rnd() * nf)
If rx < nc And ry < nf Then
If (A(ry, rx) < 255) Then
A(ry, rx) = A(ry, rx) + 1
Else
A(ry, rx) = 0
End If
End If
Next
End Sub
- 35 -
- 36 -
- 37 -
- 38 -
' System.Threading.Thread.Sleep(1)
Next
btnSimularGrafico_Click(sender, e)
End Sub
Private Sub btnrestar_Click(sender As Object, e As EventArgs) Handles
btnrestar.Click
For i = 1 To nveces
generarSumaResta(A, px, py, nf, nc, 2)
MostrarMatriz(A, nf, nc)
' System.Threading.Thread.Sleep(1)
Next
btnSimularGrafico_Click(sender, e)
End Sub
Private Sub btnIniciar_Click(sender As Object, e As EventArgs) Handles
btnIniciarMaximo.Click
Iniciar(A, nf, nc, maximo)
MostrarMatriz(A, nf, nc)
nveces = TextBox1.Text
End Sub
Private Sub btnIniciarMinimo_Click(sender As Object, e As EventArgs) Handles
btnIniciarMinimo.Click
Iniciar(A, nf, nc, minimo)
MostrarMatriz(A, nf, nc)
nveces = TextBox1.Text
End Sub
End Class
JUEGO DE LA VIDA EN VISUAL BASIC
Archivo
0 0
0 0
0 0
0 0
0 0
0 1
0 1
0 0
0 0
0 0
0 0
0 0
usado
0 0
0 0
0 0
0 0
0 0
1 0
1 0
0 0
0 0
0 0
0 0
0 0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
0
0
0
0
0
0
0
0
1
0
0
0
1
0
0
0
0
0
0
1
0
0
0
0
0
1
0
0
0
0
0
1
0
0
0
0
0
1
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
1
0
0
0
1
0
0
0
0
0
0
0
0
1
1
1
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
1
0
0
0
0
0
0
0
0
0
1
1
1
0
0
0
0
0
0
0
0
1
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
- 39 -
- 40 -
- 41 -
End Sub
Sub RecuperarMatriz(ByVal nombrearchivo As String, ByVal A(,) As Integer, ByVal nf
As Integer, ByVal nc As Integer)
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) = CInt(Val(subcadena))
inicio = pos + 1
Next
Next
Console.Write("Archivo leido satisfactoriamente")
srLector.Close()
End Sub
End Module
CODIGO DEL FORMULARIO
Imports System.IO
Public Class Form1
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
Select Case A(fila, col)
Case 0
grafico.FillRectangle(borrador, col * ex, fila * ey, ex, ey)
Case 1
grafico.FillRectangle(brocha, col * ex, fila * ey, ex, ey)
Case 2
grafico.FillRectangle(Brushes.Red, col * ex, fila * ey, ex, ey)
Case 3
grafico.FillRectangle(Brushes.Green, col * ex, fila * ey, ex, ey)
End Select
Next
Next
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
grafico = PictureBox1.CreateGraphics()
brocha = New SolidBrush(Color.Yellow)
borrador = New SolidBrush(Color.Blue)
Timer1.Enabled = False
End Sub
- 42 -
- 43 -
End Sub
Private Sub btnJugar_Click(sender As Object, e As EventArgs) Handles
btnJugar.Click
REM grafico.Clear(Color.Black)
If cont < ng Then
JuegoVida(A, maxfilas, maxcol)
VerPantalla(A, maxfilas, maxcol)
DataGridView1.Rows(6).Cells(1).Value = cont
cont = cont + 1
Else
Dim MiFuente As New Font("Verdana", 24, FontStyle.Bold)
Dim Brocha As New SolidBrush(Color.BurlyWood)
grafico.DrawString("juego terminado GDI+", MiFuente, Brocha, 100, 300)
End If
System.Threading.Thread.Sleep(velocidad) ' 1 segundo
End Sub
Private Sub btnVerPantalla_Click(sender As Object, e As EventArgs) Handles
btnVerPantalla.Click
VerPantalla(A, nf, nc)
End Sub
Private Sub btnSimular_Click(sender As Object, e As EventArgs) Handles
btnSimular.Click
Timer1.Interval = velocidad
Timer1.Enabled = True
End Sub
Private Sub BtnDetener_Click(sender As Object, e As EventArgs) Handles
BtnDetener.Click
Timer1.Enabled = False
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
btnJugar_Click(sender, e)
End Sub
End Class
PRACTICAS DEL MARTES 21 DE ABRIL TURNO 19-21 HORAS
1. HOLA MUNDO
Module Module1
Sub Main()
Console.WriteLine("HOLA")
Console.ReadLine()
End Sub
End Module
EJERCICIO 2
Module Module1
Dim N1, N2 As Single
Sub Main()
Randomize()
Console.Write("INGRESE PRIMER NUMERO")
- 44 -
N1 = Console.ReadLine()
Console.Write("INGRESE SEGUNDO NUMERO")
N2 = Console.ReadLine()
Console.WriteLine("la suma es {0} ", N1 + N2)
Console.WriteLine("la resta es {0} ", N1 - N2)
Console.WriteLine("la multiplicacion es {0} ", N1 * N2)
Console.WriteLine("la division entera es {0} ", N1 \ N2)
Console.WriteLine("la division reales {0} ", N1 / N2)
Console.WriteLine("el modulo es {0} ", N1 Mod N2)
Console.WriteLine("LA potencia de {0} elevado a {1} es = {2} ", N1, N2,
Math.Pow(N1, N2))
Console.WriteLine("LA raiz de {0} es {1} ", N1, Math.Sqrt(N1))
Console.WriteLine("numero aleatorio {0} ", Int(Rnd() * 20))
Console.ReadLine()
End Sub
End Module
- 45 -
Ejercicio 2
Module Module1
Dim a, b As Single
Dim n As Integer
Sub ingresar(ByRef a As Single, ByRef b As Single, ByRef n As Integer)
Console.Write("ingrese li ")
a = Console.ReadLine()
Console.Write("ingrese ls ")
b = Console.ReadLine()
Console.Write("ingrese ni ")
n = Console.ReadLine()
End Sub
Sub main()
Console.WriteLine("Antes a= {0} b ={1} c ={2}", a, b, n)
ingresar(a, b, n)
Console.WriteLine("Despues a= {0} b ={1} c ={2}", a, b, n)
Console.ReadLine()
End Sub
End Module
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 Main()
Iniciar(A, nf, nc)
MostrarMatriz(10, 5, A, nf, nc, 3)
Console.ReadLine()
End Sub
End Module
- 46 -
Dibujar un cuadro
Module Module1
Sub Main()
Dim Ancho As Integer = 14
Dim alto As Integer = 5
Dim px As Integer = 20
Dim py As Integer = 2
Dim color1 As Integer = 9
Dim color2 As Integer = 12
Cuadro(px, py, Ancho, alto, color1, color2)
Cuadro(40, 2, 20, 22, 14, 6)
Cuadro(50, 5, 8, 12, 9, 9)
Console.ReadLine()
End Sub
End Module
Usando la linea recursiva dibuje un cuadriltero
- 47 -
- 48 -
Module Module1
Public A(21, 21) As Integer
Public nf As Integer = 15, nc As Integer = 15
Public nveces As Integer
Sub Iniciar(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
A(fila, col) = Int(Rnd() * 15)
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 Main()
Randomize()
Iniciar(A, nf, nc)
- 49 -
Console.ReadLine()
End Sub
End Module
- 50 -
Option Explicit On
Module Module1
Sub Main()
Dim i As Single = 1
Dim suma As Single = 0
Dim n As Integer = 5
For i = 1 To n Step 0.5
Console.WriteLine("{0,8:f4}", i)
suma += i
Next
Console.WriteLine()
Console.WriteLine(" la suma es {0} ", suma)
Console.ReadLine()
End Sub
End Module
Ejercicio 5. Pase de parmetros por valor y por referencia
Option Explicit On
Option Strict On
Module Module1
Sub cambiar(ByRef a As Single, ByRef b As Single)
Dim temp As Single
temp = a
a=b
b = temp
End Sub
Sub main()
Dim x As Single = 10, y As Single = 50
Console.WriteLine("Antes antes x= {0} y ={1} ", x, y)
cambiar(x, y)
Console.WriteLine("Despues x= {0} y ={1} ", x, y)
Console.ReadLine()
End Sub
End Module
Ejemplo de parametros por referencia
Option Explicit On
Option Strict On
Module Module1
Sub ingresar(ByRef a As Single, ByRef b As Single, ByRef ndiv As Integer)
Console.Write(" ingrese a ")
a = CSng(Console.ReadLine())
Console.Write(" ingrese b ")
b = CSng(Console.ReadLine())
Console.Write(" ingrese n ")
ndiv = CInt(Console.ReadLine())
End Sub
Sub main()
Dim li, ls As Single
- 51 -
- 52 -
Option Explicit On
'Option Strict On
Module Module1
- 53 -
- 54 -
- 55 -
Console.Write("X")
Console.ForegroundColor = 10
linea(x1, y1, cx, cy)
linea(x2, y2, cx, cy)
linea(x3, y3, cx, cy)
Console.ReadLine()
End Sub
End Module
PRACTICA SI 20015 TURNO 19-21 HORAS MARTES 28 DE ABRIL DEL 20015
Parametros por referencia
Module Module1
Dim x, y As Single
Dim n1 As Integer = 10
Sub ingresar(ByRef a As Single, ByRef b As Single, ByRef n As Integer)
Console.Write("ingrese li ")
a = Console.ReadLine()
Console.Write("ingrese ls ")
b = Console.ReadLine()
Console.Write("ingrese ni ")
n = Console.ReadLine()
End Sub
Sub main()
Console.WriteLine("Antes x= {0} y ={1} n1 ={2}", x, y, n1)
ingresar(x, y, n1)
Console.WriteLine("Despues x= {0} y ={1} n1 ={2}", x, y, n1)
Console.ReadLine()
End Sub
End Module
Trazo de lineas
- 56 -
Module Module1
Function distancia(ByVal x1 As Single, ByVal y1 As Single, ByVal x2 As Single, ByVal
y2 As Single) As Single
distancia = CSng(Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2)))
End Function
Sub linea(x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer)
Dim cx, cy As Integer
Console.SetCursorPosition(x1, y1)
Console.Write("*")
Console.SetCursorPosition(x2, y2)
Console.Write("*")
If distancia(x1, y1, x2, y2) >= 2 Then
cx = (x1 + x2) / 2
cy = (y1 + y2) / 2
linea(x1, y1, cx, cy)
linea(cx, cy, x2, y2)
End If
End Sub
Sub Main()
Dim x1 As Integer = 20
Dim y1 As Integer = 20
Dim x2 As Integer = 40
Dim y2 As Integer = 2
Dim x3 As Integer = 64
Dim y3 As Integer = 20
Dim cx As Integer = (x1 + x2 + x3) / 3
Dim cy As Integer = (y1 + y2 + y3) / 3
linea(x1, y1, x2, y2)
linea(x2, y2, x3, y3)
linea(x3, y3, x1, y1)
Console.ForegroundColor = ConsoleColor.Green
linea(x1, y1, cx, cy)
linea(x2, y2, cx, cy)
linea(x3, y3, cx, cy)
Console.SetCursorPosition(cx, cy)
Console.Write("C")
Console.ReadLine()
- 57 -
End Sub
End Module
Graficar puntos exportados de Excel tanto en modo consola como en modo
formulario
Module Module1
Function distancia(ByVal x1 As Single, ByVal y1 As Single, ByVal x2 As Single, ByVal
y2 As Single) As Single
distancia = CSng(Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2)))
End Function
Sub linea(x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer)
Dim cx, cy As Integer
Console.SetCursorPosition(x1, y1)
Console.Write("*")
Console.SetCursorPosition(x2, y2)
Console.Write("*")
If distancia(x1, y1, x2, y2) >= 2 Then
cx = (x1 + x2) / 2
cy = (y1 + y2) / 2
linea(x1, y1, cx, cy)
linea(cx, cy, x2, y2)
End If
End Sub
Sub Main()
Dim X() As Single = {3, 3, 1, 4, 7, 5, 5, 3, 3}
Dim Y() As Single = {1, 3, 3, 6, 3, 3, 1, 1, 1}
Dim ndatos As Integer = 9
Dim x1, y1, x2, y2 As Integer
Dim ex = 4, ey = 2
For i = 0 To ndatos - 2
x1 = X(i) * ex
y1 = Y(i) * ey
x2 = X(i + 1) * ex
y2 = Y(i + 1) * ey
linea(x1, y1, x2, y2)
Next
- 58 -
Console.ReadLine()
End Sub
End Module
PRACTICA MIERCOLES 29 DE ABRIL DEL 2016 TURNO 17 A 19 HORAS
Ej hola mundo
Module Module1
Sub Main()
Console.WriteLine("hola mundo")
Console.ReadLine()
End Sub
End Module
Module Module1
Dim n1, N2 As Single
Sub Main()
Randomize()
Console.Write("INGRESE PRIMER NUMERO") : n1 = Console.ReadLine()
Console.Write("INGRESE SEGUNDO NUMERO")
n2 = Console.ReadLine()
Console.WriteLine("la suma es {0} ", n1 + n2)
Console.WriteLine("la resta es {0} ", n1 - n2)
Console.WriteLine("la multiplicacion es {0} ", n1 * n2)
Console.WriteLine("la division entera es {0} ", n1 \ n2)
Console.WriteLine("la division reales {0} ", n1 / n2)
Console.WriteLine("el modulo es {0} ", n1 Mod n2)
Console.WriteLine("LA potencia de {0} elevado a {1} es = {2} ", _
n1, N2, Math.Pow(n1, N2))
Console.WriteLine("LA raiz de {0} es {1} ", n1, Math.Sqrt(n1))
Console.WriteLine("numero aleatorio {0} ", Int(Rnd() * 20))
Console.ReadLine()
End Sub
End Module
Ejercicio nro 3 colores
Module Module1
Sub Main()
Console.ForegroundColor = ConsoleColor.Green
Console.BackgroundColor = 12
Console.SetCursorPosition(40, 12)
Console.Write("peru")
Console.SetCursorPosition(1, 1)
Console.BackgroundColor = 0
Console.ForegroundColor = 9
Console.Write("AZUL")
Console.ForegroundColor = 10
Console.SetCursorPosition(1, 2)
Console.Write("VERDE")
Console.ForegroundColor = 12
Console.SetCursorPosition(1, 3)
Console.Write("ROJO")
Dim i As Integer
For i = 0 To 15
Console.ForegroundColor = i
Console.SetCursorPosition(40, i)
Console.Write("color {0} ", i)
Next
Console.ReadLine()
End Sub
End Module
Dibujo de una figura
- 59 -
Module Module1
Sub Main()
Dim x1 As Integer = 10
Dim y1 As Integer = 20
Dim x2 As Integer = 40
Dim y2 As Integer = 5
Dim x3 As Integer = 60
Dim y3 As Integer = 22
Dim cx As Integer = (x1 + x2 + x3) / 3
Dim cy As Integer = (y1 + y2 + y3) / 3
Console.ForegroundColor = 9
linea(x1, y1, x2, y2)
linea(x2, y2, x3, y3)
linea(x3, y3, x1, y1)
Console.ForegroundColor = 10
linea(x1, y1, cx, cy)
linea(x2, y2, cx, cy)
linea(x3, y3, cx, cy)
Console.SetCursorPosition(cx, cy)
Console.ForegroundColor = 14
Console.Write("X")
Console.ReadLine()
End Sub
End Module
Dibujo de una figura almacenada en Arreglos
- 60 -
- 61 -
Module Module2
Function distancia(ByVal x1 As Single, ByVal y1 As Single, ByVal x2 As Single, ByVal
y2 As Single) As Single
distancia = CSng(Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2)))
End Function
Sub linea(x1 As Integer, y1 As Integer, x2 As Integer, y2 As Integer)
Dim cx, cy As Integer
Console.SetCursorPosition(x1, y1)
Console.Write("*")
Console.SetCursorPosition(x2, y2)
Console.Write("*")
If distancia(x1, y1, x2, y2) >= 2 Then
cx = (x1 + x2) / 2
cy = (y1 + y2) / 2
linea(x1, y1, cx, cy)
linea(cx, cy, x2, y2)
End If
End Sub
End Module
Module Module1
Dim i As Integer
Dim ex As Integer = 6
Dim ey As Integer = -3
Dim np As Integer = 8
Dim x() = {1, 5, 4, 5, 3, 1, 2, 1, 1}
Dim y() = {0, 0, 3, 3, 5, 3, 3, 0, 0}
Sub figura(cx As Integer, cy As Integer, ex As Integer, ey As Integer)
Dim x1, y1, x2, y2 As Integer
For i = 0 To np - 2
x1 = cx + x(i) * ex
y1 = cy + y(i) * ey
x2 = cx + x(i + 1) * ex
y2 = cy + y(i + 1) * ey
linea(x1, y1, x2, y2)
Next
End Sub
Sub Main()
figura(40, 12, 4, -2)
Console.ForegroundColor = 10
figura(10, 15, 6, -3)
Console.ReadLine()
End Sub
End Module
PRACTICAS SI LAB MIER 29 DE ABRIL DE 17-21 HORAS
Module Module1
Sub Main()
Console.WriteLine("HOLA MUNDO")
Console.ReadLine()
End Sub
End Module
COLORES
Option Explicit On
'Option Strict On
Module Module1
Sub Main()
Console.ForegroundColor = ConsoleColor.Yellow
Console.BackgroundColor = 9
Console.SetCursorPosition(40, 12)
Console.Write("PERU")
- 62 -
Console.BackgroundColor = 0
Console.ForegroundColor = 9
Console.SetCursorPosition(1, 1)
Console.Write("AZUL")
Console.ForegroundColor = 10
Console.SetCursorPosition(10, 1)
Console.Write("VERDE")
Console.ForegroundColor = 12
Console.SetCursorPosition(20, 1)
Console.Write("ROJO")
Console.BackgroundColor = 15
Console.ForegroundColor = 0
Console.SetCursorPosition(70, 1)
Console.Write("UNSA")
Console.BackgroundColor = 2
Console.ForegroundColor = 10
Console.SetCursorPosition(70, 2)
Console.Write("2015")
Dim I As Integer
Console.BackgroundColor = 0
For I = 0 To 15
Console.ForegroundColor = I
Console.SetCursorPosition(70, I + 3)
Console.Write(" COLOR {0} ", I)
Next
Console.ReadLine()
End Sub
End Module
PRACTICA DE LABORATORIO JUEVES 30 DE ABRIL DEL 2015
TURNO DE 9 11 HORAS
REM generar los valores de un funcion
Imports System.IO
Module Module1
Function f(x As Single) As Single
Return Math.Pow(x, 2)
End Function
Sub Main()
Dim x, y As Single
Dim escritor As StreamWriter
'' imprime los valores de la funcion en la pantalla
'For x = -3 To 3 Step 0.5
' y = f(x)
' Console.WriteLine(" {0} {1} ", x, y)
'Next
'' imprime los valores de la funcion en el archivo
'escritor = New StreamWriter("E: \datos\funcion.txt")
'For x = -3 To 3 Step 0.5
' y = f(x)
' escritor.WriteLine(" {0} {1} {2} ", x, vbTab, y)
- 63 -
'Next
'escritor.Close()
' lee los valores
Console.WriteLine("archivo leido")
Dim lector As StreamReader
lector = New StreamReader("E: \datos\animales.txt")
Dim cadena As String
Dim vector(10) As String
For i = 1 To 5
cadena = lector.ReadLine()
vector(i) = cadena
Console.WriteLine("{0}", cadena)
Next
Console.WriteLine("cadsf")
For i = 1 To 5
cadena = lector.ReadLine()
InStr (
Console.WriteLine("{0}", vector(i)\)
Next
lector.Close()
Console.ReadLine()
End Sub
End Module
PRACTICA DE LABORATORIO JUEVES 30 DE ABRIL DEL 2015
TURNO DE 11 13 HORAS
Mostrar una matriz de nmeros aleatorios
Module Module1
Public A(21, 41) As Integer
Public nf As Integer = 14, nc As Integer = 30
Sub Iniciar(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
A(fila, col) = Int(Rnd() * 15)
Next
- 64 -
- 65 -
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 Main()
Iniciar(A, nf, nc)
MostrarMatriz(10, 2, A, nf, nc, 2)
Console.ReadLine()
End Sub
End Module
Sub Main()
Iniciar(A, nf, nc)
Console.Write(" cuantas veces quiere generar ")
nveces = Console.ReadLine
For i = 1 To nveces
GenerarMatriz(A, nf, nc, 1)
MostrarMatriz(10, 2, A, nf, nc, 2)
Console.ReadLine()
Next
End Sub
Graficos animados con barra de dezplazamiento
La barra de desplazamiento vincular con la celda a1
Elabore la Aplicacin de la pagina 26 en macros para Excel
- 66 -
- 67 -
End Sub
Private Sub CmdIniciar_Click()
Call IniciarValores
Call Iniciar(A, nf, nc, minimo)
End Sub
Private Sub cmdProcesar_Click()
Randomize
Dim rx, ry As Integer
rx = Int(Rnd() * nc)
ry = Int(Rnd() * nf)
If rx < nc And ry < nf Then
If (A(ry, rx) < 15) Then
A(ry, rx) = A(ry, rx) + 1
Else
A(ry, rx) = 0
End If
End If
Call MostrarMatriz(cx, cy, A, nf, nc)
End Sub
Private Sub cmdRestar_Click()
Call IniciarValores
Call Iniciar(A, nf, nc, maximo)
For i = 1 To nsim
Call generarSumaResta(A, px, py, nf, nc, 2)
Call MostrarMatriz(cx, cy, A, nf, nc)
DoEvents
Next
End Sub
Private Sub cmdSumar_Click()
Dim i As Integer
Call IniciarValores
Call Iniciar(A, nf, nc, minimo)
For i = 1 To nsim
Call generarSumaResta(A, px, py, nf, nc, 1)
Call MostrarMatriz(cx, cy, A, nf, nc)
DoEvents
Next
End Sub
Private Sub Worksheet_Activate()
Call IniciarTodo
End Sub
CODIGO DE LA HOJA 2
Private Sub BtnGenerarFuncion_Click()
Call GenerarFuncion(A, nf, nc)
End Sub
- 68 -
- 69 -
ry = Int(Rnd() * nf)
If rx < nc And ry < nf Then
If (A(ry, rx) < 15) Then
A(ry, rx) = A(ry, rx) + 1
Else
A(ry, rx) = 0
End If
End If
txtEtapa.Text = i
Hoja2.Cells(cy + ry, cx + rx) = A(ry, rx)
'Application.Wait (Now + TimeValue("0:00:001"))
DoEvents
Next
Call MostrarMatriz(cx, cy, A, nf, nc)
End Sub
Sub IniciarValores()
cx = 7
cy = 2
nf = Hoja2.TextBox21.Text
nc = Hoja2.TextBox22.Text
nsim = Hoja2.txtSimulacion.Text
px = 5
py = 5
maximo = 15
minimo = 0
End Sub
Private Sub CmdIniciar_Click()
Call IniciarValores
Call Iniciar(A, nf, nc, minimo)
End Sub
Private Sub cmdProcesar_Click()
Randomize
Dim rx, ry As Integer
rx = Int(Rnd() * nc)
ry = Int(Rnd() * nf)
If rx < nc And ry < nf Then
If (A(ry, rx) < 15) Then
A(ry, rx) = A(ry, rx) + 1
Else
A(ry, rx) = 0
End If
End If
Call MostrarMatriz(cx, cy, A, nf, nc)
End Sub
Private Sub cmdRestar_Click()
Call IniciarValores
Call Iniciar(A, nf, nc, maximo)
For i = 1 To nsim
Call generarSumaResta(A, px, py, nf, nc, 2)
- 70 -
- 71 -
- 72 -
Public ng As Integer
' Public ancho, alto As Integer
Sub IniciarVariables()
cont = 0
nfilas = 8
velocidad = 10
ex = 16
ey = 16
nf = 12 '20 ' 40 '94 ' 40
nc = 38 ' 20 ' 50 '80 ' 80
ng = 200
End Sub
Sub IniciarPantalla(A() As Integer, ByVal nf As Integer, ByVal nc As Integer,
Semilla As Integer)
Dim fila, col As Integer
For fila = 0 To nf - 1
For col = 0 To nc - 1
A(fila, col) = Semilla
Next
Next
End Sub
Sub TranferirMatriz(A() As Integer, 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(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 = 0 To nf - 1
For col = 0 To nc - 1
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
- 73 -
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
Else
If A(fila1, col1) = 1 Then vecinos = vecinos + 1
End If
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
Call IniciarPantalla(A, nf, nc, 0)
Call TranferirMatriz(B, A, nf, nc)
End Sub
Sub RecuperarMatriz(A() As Integer, ByVal nf As Integer, ByVal nc As Integer)
Dim fila As Integer, col As Integer
For fila = 0 To nf - 1
cadena = cadena & Chr(9)
inicio = 1
For col = 0 To nc - 1
A(fila, col) = Val(Cells(fila + 1, col + 1))
Next
Next
End Sub
CODIGO DE LA HOJA 1
Private Sub cmdIniciar_Click()
Call RecuperarMatriz(A, nf, nc)
End Sub
Sub MostrarMatriz(px, py, A, nf, nc)
- 74 -
Option Explicit
Function proalumnos(n1 As Single, n2 As Single, n3 As Single)
Dim suma As Single, menor As Single
suma = n1 + n2 + n3
menor = n1
If n2 < menor Then
menor = n2
End If
If n3 < menor Then
menor = n3
End If
proalumnos = (suma - menor) / 2
End Function
- 75 -
2.- Estando en Excel llame como cualquier funcin est en el grupo de funciones
definidas por el usuario
1.
APELLID
APELLID
O
O
/ PATERNO , MATERNO
PEREZ/QUISPE,
1 JUAN PEDRO
6 PEREZ
CRUZ/SANTANDE
R,ELIO
2 CELEDONIO
5 CRUZ
VELIZ/VILCA,
3 ISMAEL
6 VELIZ
1
3 QUISPE
1 SANTAND
5 ER
1
2 VILCA
NOMBR
ES
COMPUESTO
JUAN
JUAN
PEDRO,PEREZ
PEDRO QUISPE
ELIO
ELIO
CELED CELEDONIO,CRUZ
ONIO
SANTANDER
ISMAEL,VELIZ
ISMAEL VILCA
En modo formula
N
r APELLIDOS
o Y NOMBRES /
=ENCO
PEREZ/QUIS NTRAR
PE, JUAN
("/",B2,1
1 PEDRO
)
2 CRUZ/SANT =ENCO
ANDER,ELIO NTRAR
CELEDONIO ("/",B3,1
APELL
IDO
PATER
NO
,
=ENCO
=EXTR NTRAR(
AE(B2, ",",B2,C
1,C2-1) 2)
=EXTR =ENCO
AE(B3, NTRAR(
1,C3-1) ",",B3,C
APELLID
O
MATERN
O
=EXTRA
E(B2,C2+
1,E2-C21)
=EXTRA
E(B3,C3+
1,E3-C3-
NOMBRES
=EXTRAE(
B2,E2+1,LA
RGO(B2)E2)
=EXTRAE(
B3,E3+1,LA
RGO(B3)-
COMPUES
TO
=CONCATE
NAR(H2,",",
D2," ",F2)
=CONCATE
NAR(H3,",",
D3," ",F3)
)
3)
=ENCO
=ENCO
NTRAR =EXTR NTRAR(
VELIZ/VILCA ("/",B4,1 AE(B4, ",",B4,C
3 , ISMAEL
)
1,C4-1) 4)
1)
=EXTRA
E(B4,C4+
1,E4-C41)
- 76 -
E3)
=EXTRAE(
B4,E4+1,LA =CONCATE
RGO(B4)NAR(H4,",",
E4)
D4," ",F4)
- 77 -
El ejercicio de la pagina 26
CODIGO DEL MODULO 2
Imports System.IO
Module Module2
Public A(10, 10) As Integer
Public nf As Integer = 10, nc As Integer = 10
Public NombreArchivo As String = "E:\DATOS\DATOS3D.txt"
Public maximo As Integer = 15
Public minimo As Integer = 0
Public opcion As Integer
Function menu() As Integer
Dim op As Integer
Console.ForegroundColor = 15
Console.Clear()
Console.SetCursorPosition(1, 1)
Console.Write("1. Generar 2: Mostrar 3. Recuperar 4. Grabar 5 salir ==opcion==> ")
op = Console.ReadLine()
Return op
End Function
- 78 -
- 79 -
Next
Next
srLector.Close()
End Sub
End Module
CODIGO DEL MODULO 1
Module Module1
Sub Main()
Randomize()
Do
opcion = menu()
Select Case opcion
Case 1 ' generar la matriz
Console.SetCursorPosition(1, 3)
GenerarMatriz(A, nf, nc)
Console.WriteLine("matriz generada presiones enter para continuar")
Console.ReadLine()
Case 2 ' mostrar matriz
MostrarMatriz(5, 5, A, nf, nc, 2)
Console.ForegroundColor = 15
Console.SetCursorPosition(1, 4)
Console.WriteLine("presione tecla para continuar")
Console.ReadLine()
Case 3 ' recuperar
RecuperarMatriz(NombreArchivo, A, nf, nc)
Console.ForegroundColor = 15
Console.SetCursorPosition(1, 3)
Console.WriteLine(" archivo {0} recuperado satisfactoriamente",
NombreArchivo)
Console.SetCursorPosition(1, 4)
Console.WriteLine(" presione tecla para continuar")
Console.ReadLine()
Case 4 ' Grabar
GrabarMatriz(NombreArchivo, A, nf, nc)
Console.ForegroundColor = 15
Console.SetCursorPosition(1, 3)
Console.WriteLine(" archivo {0} grabado satisfactoriamente",
NombreArchivo)
Console.SetCursorPosition(1, 4)
\
Console.WriteLine(" presione tecla para continuar")
Console.ReadLine()
End Select
Loop Until opcion = 5
End Sub
End Module
0 0 0 0 0
1
0 0 0 0 2
1
0 0 0 0 2
1
0 0 0 0 2
1
0 0 0 0 2
1
0 0 0 0 2
1
0 0 0 0 2
1 1
0 0 0 2 2
1 1 1
0 0 2 2 2
1 1 1 1
0 2 2 2 4
1 1 1 1 1
2 2 2 4 4
1
1 1
0 2 0 4 4
1 1
0 0 0 4 4
1 1
0 0 0 4 4
1 1
0 0 0 4 4
1 1
0 0 0 4 4
1 1
0 0 0 4 4
1 1
0 0 0 4 4
1 1
0 0 0 4 4
1 1
0 0 0 4 4
1 1
0 0 0 4 4
1 1
0 0 0 4 4
1 1
0 0 0 4 4
0
1
2
1
2
1
2
1
2
1
2
1
2
1
2
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
0 0 0 0
1
0 0 0 2
1 1
0 0 2 2
1 1 1
0 2 2 2
1 1 1 1
2 2 2 4
1 1 1 1
2 2 4 4
1 1 1 1
2 4 4 4
1 1 1 1
4 4 4 4
1 1 1 1
4 4 4 4
1 1 1 1
4 4 4 4
1
4 9 9 9
1
1 1
4 9 1 1
1
1 1
4 9 1 1
1
1 1
4 9 1 1
1
1 1
4 9 1 1
1
1 1
4 9 3 1
1
1 1
4 9 3 1
1
1 1
4 9 1 1
1
1 1
4 9 1 1
1
1 1
4 9 1 1
1
1 1
4 9 1 1
1
4 9 9 9
- 80 -
1
2
1
2
1
2
1
4
1
4
1
4
1
4
1
4
1
4
1
4
0
1
2
1
2
1
2
1
4
1
4
1
4
1
4
1
4
1
4
0 0 0 0 0 0 0 0 0
0
1
2
1
2
1
2
1
4
1
4
1
4
1
4
1
4
0 0 0 0 0 0 0 0
9
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
9
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
9
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
2
1
2
1
2
1
4
1
4
1
4
1
4
9
9
9
9
9
9
9
9
9
9
9 9 9 9
7 7 7 7 7 7 7 7
0 0 0 0 0 0 0
0
1
2
1
2
1
2
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
0 0 0 0 0 0
0
1
2
1
2
1
2
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
7 4
0 0 0 0 0
0
1
2
1
2
1
2
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
0 0 0 0
0
1
2
1
2
1
2
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
1
4
0 0 0
0
1
2
1
2
1
2
0 0
0
1
2
1
2
1
0 2
0
0
1
2
0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0
1
0
1
0
0
1
0
1
0
0
1
0
1
0
- 81 -
Modifique
Imports System.IO
Module Module2
Public A(25, 25) As Integer
Public nf As Integer = 23, nc As Integer = 21
'Public NombreArchivo As String = "E:\DATOS\DATOS3D.txt"
Public NombreArchivo As String = "E:\DATOS\casita21x23.txt"
Disee otros modelos, grafique lneas de datos recuperados
Convertir una archivo en minsculas a mayscula
Traductor
Buscador de palabras
PRACTICA DE LABORATORIO MARTES 05 DE MAYO DEL 2015
TURNO DE 17 A 21 HORAS
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 = Console.ReadLine()
Do While Not (Linea Is Nothing)
Console.WriteLine(" {0}", Linea)
Linea = Console.ReadLine()
Loop
srLector.Close()
Console.ReadLine()
End Sub
End Module
PRACTICAS DEL 05 DE MAYO DEL 2015 TURNO DE 7 A 9 P,M
Module Module1
Sub Main()
Console.WriteLine("HOLA MUNDO")
Console.ReadLine()
End Sub
End Module
Grabando en el archivo
Imports System.IO
Module Module1
Dim nombreArchivo As String = "E:\datos\hola.txt"
Sub Main()
Dim AEscritor As StreamWriter
AEscritor = New StreamWriter(nombreArchivo)
AEscritor.WriteLine("HOLA MUNDO")
AEscritor.Close()
Console.WriteLine(" El archivo {0}ha sido grabado", nombreArchivo)
Console.ReadLine()
End Sub
End Module
- 82 -
- 83 -
PRACTICA DE ARCHIVOS ( PLAN PARA LAS CLASES DEL MIE 06 DE MAYO DEL
2015 DE 7 A 9 HORAS)
Imports System.IO
Module Module1
Dim NombreArchivo As String = "E:\DATOS\texto1.txt"
Dim opcion As Integer
Dim cadena As String
Sub Main()
Dim cki As ConsoleKeyInfo
Do
Console.WriteLine("1 Ingresar 2. Mostrar 3. Grabar 4 Recuperar 5.Salir ")
Console.Write("Ingrese opcion ==> ")
opcion = Console.ReadLine
Select Case opcion
Case 1
Console.WriteLine(" ingrese texto escape z para terminar")
cadena = ""
Do
cki = Console.ReadKey()
cadena = cadena & Chr(cki.Key)
If cki.Key = 13 Then
cadena = cadena + Chr(10)
Console.WriteLine()
End If
Loop While cki.Key <> ConsoleKey.Escape
Console.WriteLine("fin")
Case 2
Console.WriteLine(" el texto ingresado es ")
Console.WriteLine("{0}", cadena)
Case 3
Dim escritor As StreamWriter
escritor = New StreamWriter(NombreArchivo)
escritor.WriteLine("{0}", cadena)
Console.WriteLine(" archivo {0} grabado ", NombreArchivo)
escritor.Close()
Case 4
Dim lector As StreamReader
Dim linea As String
lector = New StreamReader(NombreArchivo)
cadena = ""
linea = lector.ReadLine
Do While Not (linea Is Nothing)
cadena = cadena & linea & Chr(10) & Chr(13)
linea = lector.ReadLine()
Loop
lector.Close()
Console.WriteLine(" archivo {0} recuperado ", NombreArchivo)
End Select
Loop While opcion <> 5
End Sub
End Module
Recupera cualquier archive de texto
OTRA MANERA
Imports System.IO
Module Module1
Const maximo As Integer = 100
- 84 -
- 85 -
Cdigo
Imports System.IO
Public Class Form1
Dim NombreArchivo As String = "E:\DATOS\texto1.txt"
Private Sub btnGrabar_Click(sender As Object, e As EventArgs) Handles
btnGrabar.Click
Dim escritor As StreamWriter
SaveFileDialog1.ShowDialog()
NombreArchivo = SaveFileDialog1.FileName
escritor = New StreamWriter(NombreArchivo)
escritor.WriteLine("{0}", TextBox1.Text)
escritor.Close()
- 86 -
- 87 -
- 88 -
- 89 -
- 90 -
- 91 -
Imports System.IO
Module Module1
Sub Main()
Dim nombrearchivo As String = "E:\datos\prueba1.txt"
Dim cadena As String
' lectura del teclado
'Console.WriteLine(" leido del teclado ")
'cadena = Console.ReadLine()
'Console.WriteLine("la cadena leida es {0}", cadena)
'Console.ReadLine()
' lectura del archivo
Dim lector As StreamReader = New StreamReader(nombrearchivo)
Console.WriteLine(" leido del archivo ")
cadena = lector.ReadLine()
- 92 -
- 93 -
Imports System.IO
Module Module1
Sub Main()
Dim NombreArchivo As String = "E:\datos\funcion.txt"
' mostrando en la consola
Console.WriteLine("Arequipa 06 de mayo del 2015")
Console.WriteLine("Ingenieria Industrial")
Console.WriteLine(" del 2015")
Console.ReadLine()
' mostrando en el archivo
Dim arch As StreamWriter = New StreamWriter(NombreArchivo)
- 94 -
- 95 -
- 96 -
For col = 0 To nc - 1
A(fila, col) = Int(Rnd() * maximo)
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
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)
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()
End Sub
End Module
- 97 -
FolderBrowserDialog1
Public Class Form1
Dim grafico As Graphics
Dim ancho As Integer = 255
Dim alto As Integer = 255
Dim brocha As SolidBrush
Dim pincel As Pen
Private Sub btnColor_Click(sender As Object, e As EventArgs) Handles
btnColorDialogo.Click
ColorDialog1.ShowDialog()
Panel1.BackColor = ColorDialog1.Color
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
grafico = PictureBox1.CreateGraphics
brocha = New SolidBrush(Color.Red)
pincel = New Pen(Brushes.AliceBlue)
PictureBox1.Width = ancho * 3
PictureBox1.Height = alto * 2
End Sub
Private Sub BtnColor_Click_1(sender As Object, e As EventArgs) Handles
BtnColor.Click
Dim rx As Integer = 0
Dim ry As Integer = 0
Dim vx As Integer = 128
Dim vy As Integer = 128
Dim ax As Integer = 255
Dim ay As Integer = 128
pincel.Color = Color.FromArgb(255, 0, 0)
grafico.DrawEllipse(pincel, rx, ry, ancho, alto)
pincel.Color = Color.FromArgb(0, 255, 0)
grafico.DrawEllipse(pincel, vx, vy, ancho, alto)
pincel.Color = Color.FromArgb(0, 0, 255)
grafico.DrawEllipse(pincel, ax, ay, ancho, alto)
End Sub
End Class