INSTITUTO TECNOLÓGICO SUPERIOR DE LERDO
VISUAL BASIC Y C #
“
”
Ingeniero Ricardo Bustamante González
Alumna:
ROCIO MARISOL DE LA TORRE GONZALEZ
Febrero del 2012 Instituto Tecnológico Superior de Lerdo
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
PROYECTO EN VISUAL BASIC
Objetivo general Aprender a manejar este nuevo lenguaje que se encuentra en Visual Studio; dando a conocer el programa siguiente desarrollándolo en un registro de alumnos con sus respectivas calificaciones. Material: *3 menu *9 textBox *10 Labels *7 Buttons Interfaz Grafica del Programa
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
Continuando con los menús, ahora el de Edición:
Y por ultimo menú es el de Buscar:
Es por eso que se elaboro de esta manera el programa, y por si escriben un dato mal a la hora de crear un registro, solamente se oprime el botón pequeño del lado de la caja de texto marcado con una cruz:
INDICA
CUANTAS
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
CODIGO EN VISUAL BASIC Form1 Imports System.IO Public Class Form1 Private Sub Timer1_Tick( ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles Timer1.Tick If Timer1.Interval = 2000 Then Timer1.Enabled = False Me.Hide() Me .Hide() Form2.Show() Form2 .Show() End If End Sub Private Sub Form1_FormClosing( ByVal sender As System.Object System. Object, , ByVal e As System.Windows.Forms. FormClosingEventArgs ) Handles MyBase MyBase.FormClosing .FormClosing End Sub Private Sub Form1_Load( ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles MyBase MyBase.Load .Load If Directory Directory.Exists( .Exists("C:\Registro" "C:\Registro") ) Then If File File.Exists( .Exists("C:\Registro\registro.txt" "C:\Registro\registro.txt" ) Then Else : File File.Create( .Create("C:\Registro\registro.txt" "C:\Registro\registro.txt" ) MessageBox.Show( MessageBox .Show("El "El directorio fue creado exitosamente." , "Aviso" "Aviso") )//este mensaje aparecerá cuando se haya creado el directorio con un buen resultado End If If//indica //indica fin del ciclo if Else Directory.CreateDirectory( Directory .CreateDirectory( "C:\Registro" "C:\Registro") )//se crea un directorio File.Create( File .Create("C:\Registro\registro.txt" "C:\Registro\registro.txt" ) MessageBox.Show( MessageBox .Show("El "El directorio fue creado exitosamente." , "Aviso" "Aviso") ) End If End Sub End Class
Form2 Imports System.IO Public Class Form2 Form2// // el siguiente codigo se encuentra en el Segundo form, en el cual se declaran dos variables una con el nombre a y otra con el nombre bol Dim a As New Integer Integer//esta //esta variable el tipo de dato que contiene es entero Dim bol As New Boolean Boolean//sin //sin embargo el tipo de dato es boleano
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
Private Sub Form2_Load( ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles MyBase MyBase.Load .Load Dim flujo As New FileStream FileStream( ("c:\Registro\registro.txt" , FileMode FileMode.OpenOrCreate, .OpenOrCreate, FileAccess.ReadWrite) FileAccess .ReadWrite) //en el cual como se ha observado anteriormente que se usa la palabra Dim, es una instruccion en ella se usa para declarer variables de memoria. Declarando otra variable para crear un registro y si ya es creado que se pueda abrir y por ultimo poder escribir. Dim datos As New BinaryReader BinaryReader(flujo) (flujo)//la //la variable datos que en ella se guarde lo que hay de datos para que sean leeidos. If datos.PeekChar <> -1 Then Then//si //si los datos son desiguales a menos uno, entonces entra donde lo que se guardo en datos se guardara en a, con un tamaño de 70 caracteres siendo enteros. a = CType CType( (Math Math.Ceiling(flujo.Length .Ceiling(flujo.Length / 70), Integer Integer) ) End If ToolStripLabel1.Text = "Personas registradas: " + a.ToString() End Sub Sub//en //en la etiqueta 1 aparecera una cadena diciendo cuantas personas han sido registradas en ese momento. Private Sub SalirToolStripMenuItem_Click( ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles SalirToolStripMenuItem.Click Application .Exit()//dentro .Exit() //dentro del form se encuentra un meno, en el cual solo es para salir de la ejecucion. End Sub Private Sub NuevoToolStripMenuItem1_Click( ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles NuevoToolStripMenuItem1.Click limpiar()//es limpiar() //es para limpiar como su nombre lo dice PictureBox1.Visible = False False// // cuando se limpia la imagen no se vera ya que esta en falso Panel1.Enabled = True True// // siendo los dos paneles y el boton para ingresar, en el cual los demas textbox o cajas de texto estaran disponibles para ingresar nuevos registros Panel1.Visible = True Button6.Visible = True Button8.Visible = False TextBox1.Enabled = True TextBox2.Enabled = True TextBox4.Enabled = True TextBox5.Enabled = True TextBox6.Enabled = True TextBox7.Enabled = True TextBox8.Enabled = True TextBox9.Enabled = True End Sub Private Sub PorNombreToolStripMenuItem_Click( ByVal sender As System.Object System. Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles PorNombreToolStripMenuItem.Click limpiar()//es limpiar() //es para limpiar , este menu es para buscar el alumno por el nombre, es
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
TextBox2.Enabled = False TextBox3.Enabled = True TextBox4.Enabled = False TextBox5.Enabled = False TextBox6.Enabled = False TextBox7.Enabled = False TextBox8.Enabled = False TextBox9.Enabled = False Button6.Visible = False Button8.Visible = True End Sub Private Sub TextBox4_KeyPress( ByVal sender As System.Object System. Object, , ByVal e As System.Windows.Forms. KeyPressEventArgs ) Handles TextBox8.KeyPress, TextBox7.KeyPress, TextBox6.KeyPress, TextBox5.KeyPress, TextBox4.KeyPress If Not Char Char.IsNumber(e.KeyChar) .IsNumber(e.KeyChar) Then e.Handled = True End If End Sub Private Sub Button1_Click_1( ByVal sender As System.Object System. Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles Button1.Click TextBox4.Clear() //para cerrar End Sub Private Sub Button3_Click( ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles Button3.Click TextBox5.Clear() //para cerrar End Sub Private Sub Button5_Click( ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles Button5.Click TextBox6.Clear() //para cerrar End Sub Private Sub Button2_Click( ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles Button2.Click TextBox7.Clear() //para cerrar End Sub Private Sub Button4_Click( ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles Button4.Click TextBox8.Clear() //para cerrar End Sub Private Sub Button6_Click( ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles Button6.Click Dim sw As New StreamWriter StreamWriter( ("c:\Registro\registro.txt" , True True) ) sw.WriteLine(TextBox3.Text) sw.WriteLine(TextBox1.Text)
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
TextBox9.Text TextBox9.Text = ((Double (( Double.Parse(TextBox4.Text) .Parse(TextBox4.Text) + Double Double.Parse(TextBox5.Text) .Parse(TextBox5.Text) + Double.Parse(TextBox6.Text) Double .Parse(TextBox6.Text) + Double.Parse(TextBox7.Text) Double .Parse(TextBox7.Text) + Double Double.Parse(TextBox8.Text)) .Parse(TextBox8.Text)) / 5)//para 5)//para sacar el promedio de las calificaciones insertadas en los textobox que se indicant en la cadena sw.WriteLine(TextBox9.Text) //el resultado de este textbox se guarda en el numero nueve sw.Close() MessageBox.Show( MessageBox .Show("El "El usuario " + TextBox3.Text + " fue guardado exitosamente." , "Aviso", "Aviso" , MessageBoxButtons MessageBoxButtons.OK) .OK) Panel1.Enabled = False End Sub Private Sub Button8_Click( ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles Button8.Click Dim sr As New StreamReader StreamReader( ("C:\Registro\registro.txt" ) bol = False While bol = False If sr.ReadLine() = TextBox3.Text Then TextBox1.Text = sr.ReadLine() TextBox2.Text = sr.ReadLine() TextBox4.Text = sr.ReadLine() TextBox5.Text = sr.ReadLine() TextBox6.Text = sr.ReadLine() TextBox7.Text TextBox7.Text = sr.ReadLine() sr.ReadLine() TextBox8.Text = sr.ReadLine() TextBox9.Text = sr.ReadLine() bol = True End If sr.ReadLine() sr.ReadLine() sr.ReadLine() sr.ReadLine() sr.ReadLine() sr.ReadLine() sr.ReadLine()
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
Programa en ejecución
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
PROYECTO EN C #
Objetivo General De igual manera que el anterior proyecto, aunque a unque este fue elaborado en el lenguaje C #, siendo más complejo por el código que se tiene que hacer en cada objeto que se incruste en el formulario.
Materiales: *3 menús *4 textBox *2 Button *1GroupBox Interfaz Grafica del Programa:
De esta forma se vera al momento de ejecutar el programa, pero conforme se avanza para ingresar por ejemplo se desplegaran los campos que se requieren y se vera de esta e sta forma:
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
Como se puede opbservar el programa esta listo para ser utilizado por un usuario como tu, en el cual también se observa el menu de buscar como el siguiente:
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_FormClosing( object sender, FormClosingEventArgs e) { e.Cancel = true true; ; } private void timer1_Tick( object sender, EventArgs e) {//saber si existe el registro if (!File (!File.Exists( .Exists("registro.txt" "registro.txt" )) { File.Create( File .Create("registro.txt" "registro.txt" ); } this.timer1.Enabled this .timer1.Enabled = false false; ; this.Hide(); this .Hide(); Form2 f2 = new Form2 Form2(); ();//para //para enlazar el form1 con el form2 f2.ShowDialog(); } } }
Form2 using using using using using using using using using
System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Linq; System.Text; System.Windows.Forms; System.IO;
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
private void salirToolStripMenuItem_Click( object sender, EventArgs e) { Application .ExitThread(); //salir de la aplicacion } private void Form2_Load(object Form2_Load( object sender, EventArgs e) { textBox1.Focus(); //para que aparezca el punter en el primer textbox o primer caja de texto } private void nuevoToolStripMenuItem_Click( object sender, EventArgs e) { this.Size= this .Size= new Size Size(369, (369, 300);//tamaño 300); //tamaño del programa para ocupar menos memoria groupBox1.Visible = true true; ;//para que aparezca visible lo que se encuentra dentro del grupo button3.Visible = false false; ;//como se ingresara entonces no aparecera el boton de buscar pore so es falso button1.Visible = true true; ;//mientras que el primer boton es para guardar textBox1.Clear(); //para cerrar cuando se haya guardado el dato textBox2.Clear(); textBox3.Clear(); textBox4.Clear(); } private void buscar_Click( object sender, EventArgs e) {
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
private void button1_Click( object sender, EventArgs e) { StreamWriter sw = new StreamWriter ("registro.txt" ); if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" "") )//para ingresar un nuevo dato { MessageBox MessageBox.Show( .Show("Faltan "Faltan datos por ingresar", ingresar" , "Aviso" "Aviso"); ); }//si }//si no se llenan todas las cajas de texto marcara un error mandando este mensaje else {//sino pues sera necesario de llenar todos los campos que se indicant en el programa en su ejecucion sw.WriteLine(textBox1.Text); sw.WriteLine(textBox2.Text); sw.WriteLine(textBox3.Text); sw.WriteLine(textBox4.Text); sw.WriteLine(fecha.Value); sw.Close(); this.Size this .Size = new Size Size(369, (369, 62); groupBox1.Visible = false false; ; button3.Visible = true true; ; button1.Visible = true true; ; textBox1.Clear(); textBox2.Clear(); textBox3.Clear(); textBox4.Clear(); } }
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
The world’s largest digital library
Try Scribd FREE for 30 days to access over 125 million titles without ads or interruptions! Start Free Trial Cancel Anytime.
} } } } private void textBox1_KeyPress( object sender, KeyPressEventArgs e) { if (Char Char.IsNumber(e.KeyChar)) .IsNumber(e.KeyChar)) //se pone esta condicion en el cual es para que acepte nadams caracteres, osea no numeros; en este programa el numero de control será con letras. { e.Handled = true true; ; } } } }