Hoy vamos a hacer una aplicación en Visual Basic .NET; son ejemplos que hice utilizando VB 2008 Express Edition.
Menú del programa
Calculo el promedio, el valor futuro, operaciones básicas aritméticas,ejemplos de estructuras de control, funciones y el salario neto.
Formulario no.1
Formulario No.2
Formulario no. 3
Formulario no. 5
Formulario no. 6
Formulario no. 7
Menú del programa
Calculo el promedio, el valor futuro, operaciones básicas aritméticas,ejemplos de estructuras de control, funciones y el salario neto.
Formulario no.1
Public Class Form1 Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click MsgBox("Mensaje" & vbCrLf & "" & vbCrLf & " Programa elaborado por:" & vbCrLf & "Fernando Carraro Aguirre") End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If RadioButton1.Checked = True Then Form2.Show() Form3.Hide(): Form4.Hide(): Form5.Hide(): Form6.Hide(): Form7.Hide(): End If If RadioButton2.Checked = True Then Form3.Show(): Form2.Hide(): Form4.Hide(): Form5.Hide(): Form6.Hide(): Form7.Hide(): End If If RadioButton3.Checked = True Then Form4.Show(): Form3.Hide(): Form2.Hide(): Form5.Hide(): Form6.Hide(): Form7.Hide(): End If If RadioButton4.Checked = True Then Form5.Show(): Form4.Hide(): Form3.Hide(): Form2.Hide(): Form6.Hide(): Form7.Hide(): End If If RadioButton5.Checked = True Then Form6.Show() Form5.Hide() Form4.Hide() Form3.Hide() Form2.Hide() Form7.Hide() End If If RadioButton6.Checked = True Then Form6.Hide() Form5.Hide() Form4.Hide() Form3.Hide() Form2.Hide() Form7.Show() End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click End End Sub End Class
Formulario No.2
Public Class Form2 Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click MsgBox("Hola a todos " & vbCrLf & "Mensaje" & vbCrLf & "Hola") End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim numero As Integer Dim valor As Double Dim i As Integer Dim suma As Double Dim promedio As Double numero = Val(TextBox1.Text): i = 0 : suma = 0 For i = 1 To numero valor = Val(InputBox("Valor del elemento" & i, "Promedio en .NET", "")) suma += valor Next i promedio = suma / numero Label2.Text = "La suma es " & CStr(suma) & " el promedio obtenido es " & CStr(promedio) End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click TextBox1.Text = "" : Label2.Text = "" End Sub End Class
Formulario no. 3
Public Class Form3 Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click MsgBox("Mensaje" & vbCrLf & " Hola") End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click TextBox1.Clear() : TextBox2.Clear() : TextBox3.Clear() ListBox1.Items.Clear() : ListBox2.Items.Clear() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim vf As Double, tasa As Double, periodo As Integer Dim x As Integer, vp As Double vf = Val(TextBox1.Text) : tasa = Val(TextBox2.Text) : periodo = Val(TextBox3.Text) For x = 0 To periodo vp = vf / (1 + tasa / 100) ^ x 'ListBox1.Visible = True 'ListBox2.Visible = True ListBox2.Items.Add(vp) ListBox1.Items.Add(x) Next x End Sub End Class
Formulario no.4
Imports System.Math Public Class Form4 Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click MsgBox("Hola a todos " & vbCrLf & "Mensaje" & vbCrLf & "A todos ") End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim num1 As Double, num2 As Double Dim suma As Double, resta As Double, multi As Double, divi As Double If RadioButton1.Checked = True Then num1 = Val(TextBox1.Text) : num2 = Val(TextBox2.Text) suma = num1 + num2 Label3.Text = "Suma " & CStr(suma) End If If RadioButton2.Checked = True Then num1 = Val(TextBox1.Text) : num2 = Val(TextBox2.Text) resta = num1 - num2 Label3.Text = "Resta " & CStr(resta) End If If RadioButton3.Checked = True Then num1 = Val(TextBox1.Text) : num2 = Val(TextBox2.Text) multi = num1 * num2 Label3.Text = "Producto " & CStr(multi) End If If RadioButton4.Checked = True Then num1 = Val(TextBox1.Text) num2 = Val(TextBox2.Text) divi = num1 / num2 Label3.Text = "División " & CStr(divi) End If End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click TextBox1.Text = "" : TextBox2.Text = "" : Label3.Text = "" End Sub End Class
Formulario no. 5
Public Class Form5 Dim num1 As Double, num2 As Double, resultado As Double Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click MsgBox("Hola a todos " & vbCrLf & "A todos " & vbCrLf & "Hola") End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim suma As Integer Dim contador As Integer suma = 0 : contador = 0 Do While suma <> suma += CInt(TextBox1.Text) contador = contador + 1 Loop MsgBox("El bucle está corriendo" & CStr(contador) & "veces") End Sub Private Sub Form5_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing If MessageBox.Show("¿Cerrar la ventana?", _ "Atención", MessageBoxButtons.YesNo, _ MessageBoxIcon.Hand) = DialogResult.No Then e.Cancel = True End If End Sub Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load MessageBox.Show("Haz iniciado") End Sub Private Sub Form5_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove Me.Text = "Coordenadas ratón: X:" & e.X & " Y:" & e.Y End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged If ComboBox1.Text = "SUMA" Then num1 = Val(InputBox("Número 1", "SUMA", "")) num2 = Val(InputBox("Número 2", "SUMA", "")) resultado = num1 + num2 MessageBox.Show(resultado) End If If ComboBox1.Text = "RESTA" Then num1 = Val(InputBox("Número 1", "RESTA", "")) num2 = Val(InputBox("Número 2", "RESTA", "")) resultado = num1 - num2 MessageBox.Show(resultado) End If If ComboBox1.Text = "MULTIPLICACIÓN" Then num1 = Val(InputBox("Número 1", "MULTIPLICACIÓN", "")) num2 = Val(InputBox("Número 2", "MULTIPLICACIÓN", "")) resultado = num1 * num2 MessageBox.Show(resultado) End If If ComboBox1.Text = "DIVISIÓN" Then num1 = Val(InputBox("Número 1", "DIVISIÓN", "")) num2 = Val(InputBox("Número 2", "DIVISIÓN", "")) resultado = num1 / num2 MessageBox.Show(resultado) End If If ComboBox1.Text = "EXPONENCIACIÓN" Then num1 = Val(InputBox("Base", "EXPONENCIACIÓN", "")) num2 = Val(InputBox("Exponente", "EXPONENCIACIÓN", "")) resultado = num1 ^ num2 MessageBox.Show(resultado) End If If ComboBox1.Text = " RADICACIÓN" Then num1 = Val(InputBox("Raíz del número ", "RADICACIÓN", "")) resultado = Math.Sqrt(num1) MessageBox.Show(resultado) End If End Sub End Class
Formulario no. 6
Public Class Form6 Dim numero As Integer Dim valorx As Double Dim result As Double Dim i As Integer Function funcion(ByVal x As Double) As Double funcion = 10 * x ^ 3 + 4 * x ^ 2 + 12 * x End Function Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.Text = "Función 10 * x ^ 3 + 4 * x ^ 2 + 12 * x" Me.Label1.Text = "Número de elementos:" Me.Label2.Text = "QUITAR" End Sub Private Sub Label2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label2.Click Me.Close() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Call limpiar() End Sub Public Sub limpiar() TextBox1.Text = "" : ListBox1.Items.Clear() : ListBox2.Items.Clear() : ListBox3.Items.Clear() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click i = 0 numero = Val(TextBox1.Text) For Me.i = 1 To numero valorx = Val(InputBox("Valor elemento no." & i, "Introduce valor", "")) result = funcion(valorx) ListBox1.Items.Add(i) ListBox2.Items.Add(valorx) ListBox3.Items.Add(result) Next End Sub End Class
Formulario no. 7
Public Class Form7 Private Sub Form7_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Me.Text = "Salario en .NET" End Sub Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click Me.Hide() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim hr As Integer Dim salarioNeto As Double Dim extra As Double Dim tasa As Integer hr = Val(TextBox1.Text) If hr <= 0 Then MsgBox("Error las horas deben cer mayores a cero", MsgBoxStyle.Critical, "Aviso del sistema") End If '---casillas de verificación checkbox--------------------------------------------------------- If CheckBox1.CheckState = 1 Then 'MsgBox("Francés") extra = 0.01 End If If CheckBox2.CheckState = 1 Then 'MsgBox("Alemán") extra = 0.02 End If If CheckBox3.CheckState = 1 Then 'MsgBox("Inglés") extra = 0.03 End If '--------------------------------------------------------------------------------------------- '---radiobuttons------------------------------------------------------------------------------- If RadioButton1.Checked = True Then extra += 0.05 End If If RadioButton2.Checked = True Then extra += 0.25 End If '--------------------------------------------------------------------------------------------- '---comboboxs-------------------------------------------------------------------------------- If ComboBox1.Text = "5%" Then tasa = 5 End If If ComboBox1.Text = "10%" Then tasa = 10 End If If ComboBox1.Text = "25%" Then tasa = 25 End If If ComboBox1.Text = "50%" Then tasa = 50 End If '-------------------------------------------------------------------------------------------- salarioNeto = hr + tasa + extra + 1200 MsgBox(salarioNeto, MsgBoxStyle.Information, "Resultado") End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click TextBox1.Clear() End Sub End Class
Comentarios
Publicar un comentario