EJERCIOS DE CALCULADORA DE RESISTENCIAS
Continuación este es un ejercicio de VB.NET para calcular eel valor de las resitencia utilizando formularios:
Aqui estamos ejecutando el formulario con sus respectivos valores
Colocamos un nombre que distingua a cada elemento utilizado en el windows forms
Ahora empezemos:
Public Class Form1
Private Sub btnreiniciar_Click(sender As Object, e As EventArgs) Handles btnreiniciar.Click
ComboBox1.Enabled = True
ComboBox1.ResetText()
ComboBox2.Enabled = True
ComboBox2.ResetText()
ComboBox3.Enabled = True
ComboBox3.ResetText()
ComboBox4.Enabled = True
ComboBox4.ResetText()
txt1.Text = ""
Txt2.Text = ""
txtideal1.Text = ""
txtideal2.Text = ""
btn1.BackColor = Nothing
btn2.BackColor = Nothing
btn3.BackColor = Nothing
btn4.BackColor = Nothing
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
ComboBox2.Enabled = False
ComboBox3.Enabled = False
ComboBox4.Enabled = False
btn1.Enabled = False
btn2.Enabled = False
btn3.Enabled = False
btn4.Enabled = False
End Sub
Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
Select Case ComboBox1.SelectedIndex
Case 0 : btn1.BackColor = Color.Black
Case 1 : txt1.Text = "1"
btn1.BackColor = Color.Maroon
Case 2 : txt1.Text = "2"
btn1.BackColor = Color.Red
Case 3 : txt1.Text = "3"
btn1.BackColor = Color.Orange
Case 4 : txt1.Text = "4"
btn1.BackColor = Color.Yellow
Case 5 : txt1.Text = "5"
btn1.BackColor = Color.Green
Case 6 : txt1.Text = "6"
btn1.BackColor = Color.Blue
Case 7 : txt1.Text = "7"
btn1.BackColor = Color.Violet
Case 8 : txt1.Text = "8"
btn1.BackColor = Color.Gray
Case 9 : txt1.Text = "9"
btn1.BackColor = Color.White
End Select
ComboBox1.Enabled = False
ComboBox2.Enabled = True
ComboBox2.Focus()
End Sub
Private Sub ComboBox2_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox2.SelectedIndexChanged
Select Case ComboBox2.SelectedIndex
Case 0 : btn2.BackColor = Color.Black
Case 1 : txt1.Text += "1"
btn2.BackColor = Color.Maroon
Case 2 : txt1.Text += "2"
btn2.BackColor = Color.Red
Case 3 : txt1.Text += "3"
btn2.BackColor = Color.Orange
Case 4 : txt1.Text += "4"
btn2.BackColor = Color.Yellow
Case 5 : txt1.Text += "5"
btn2.BackColor = Color.Green
Case 6 : txt1.Text += "6"
btn2.BackColor = Color.Blue
Case 7 : txt1.Text += "7"
btn2.BackColor = Color.Violet
Case 8 : txt1.Text += "8"
btn2.BackColor = Color.Gray
Case 9 : txt1.Text += "9"
btn2.BackColor = Color.White
End Select
ComboBox2.Enabled = False
ComboBox3.Enabled = True
ComboBox3.Focus()
End Sub
Private Sub ComboBox3_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox3.SelectedIndexChanged
Select Case ComboBox3.SelectedIndex
Case 0
btn3.BackColor = Color.Black
Case 1 : txt1.Text += "0 Ω"
btn3.BackColor = Color.Maroon
Case 2 : txt1.Text += "00 Ω "
btn3.BackColor = Color.Red
Case 3 : txt1.Text += "000 Ω"
btn3.BackColor = Color.Orange
Case 4 : txt1.Text += "0000 Ω"
btn3.BackColor = Color.Yellow
Case 5 : txt1.Text += "00000 Ω "
btn3.BackColor = Color.Green
Case 6 : txt1.Text += "000000 Ω "
btn3.BackColor = Color.Blue
Case 7 : txt1.Text += "0000000 Ω "
btn3.BackColor = Color.Violet
Case 8 : txt1.Text = txt1.Text * 0.1
btn3.BackColor = Color.Gray
Case 9 : txt1.Text = txt1.Text * 0.01
btn3.BackColor = Color.White
End Select
ComboBox3.Enabled = False
ComboBox4.Enabled = True
End Sub
Private Sub ComboBox4_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox4.SelectedIndexChanged
Select Case ComboBox4.SelectedIndex
Case 0 : btn4.BackColor = Color.Red
txt1.Text = txt1.Text
Txt2.Text = "2"
Case 1 : btn4.BackColor = Color.Transparent
txt1.Text = txt1.Text
Txt2.Text = "0"
Case 2 : btn4.BackColor = Color.Gold
txt1.Text = txt1.Text
Txt2.Text = "5"
Case 3 : btn4.BackColor = Color.Silver
txt1.Text = txt1.Text
Txt2.Text = "10"
End Select
ComboBox4.Enabled = False
ComboBox1.Enabled = True
ComboBox2.Enabled = True
ComboBox3.Enabled = True
End Sub
Private Sub bntcalcular_Click(sender As Object, e As EventArgs) Handles bntcalcular.Click
Dim a As Double
a = (Val(txt1.Text) * Val(Txt2.Text) / 100)
txtideal1.Text = Val(txt1.Text) - a
txtideal2.Text = Val(txt1.Text) + a
End Sub
Private Sub btnsalir_Click(sender As Object, e As EventArgs) Handles btnsalir.Click
End
End Sub
End Class
Comentarios
Publicar un comentario