ArmandoCircuitos
Inicio
Electronica
Programacion
Resultado
Codigo
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace Ley_de_Ohm_01 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } double v,i,r; int a = 0; int b = 0; int c = 0; double tension, corriente, impedancia; double[] multiplos = { 0.000001, 0.001, 1, 1000, 1000000 }; string cadena; private void Form1_Load(object sender, EventArgs e) { cmbTension.SelectedIndex = 2; cmbCorriente.SelectedIndex = 1; cmbImpedancia.SelectedIndex = 0; } private void calcular(string param) { v = v * multiplos[a]; i = i * multiplos[b]; r = r * multiplos[c+2]; tension = v; corriente = i; impedancia = r; if (param == "amp") corriente = v / r; else { if (param == "volt") tension = i * r; else impedancia = v / i; } lblTension.Text = prefijo(tension) + "V"; lblCorriente.Text = prefijo(corriente) + "A"; lblImpedancia.Text = prefijo(impedancia) + "Ω"; } private string prefijo(double numero) { if (numero >= 1000000) { numero = numero / 1000000; cadena = Math.Round(numero, 1) + "M"; } else { if (numero >= 1000) { numero = numero / 1000; cadena = Math.Round(numero,1) + "K"; } else { if (numero >= 1) { if (numero % 1 != 0) numero = Math.Round(numero,1); cadena = numero.ToString(); } else { if (numero >= 0.001) { numero = numero * 1000; cadena = Math.Round(numero,1) + "m"; } else { numero = numero * 1000000; cadena = Math.Round(numero,1) + "u"; } } } } return (cadena); } private void cmbTension_SelectedIndexChanged(object sender, EventArgs e) { a = cmbTension.SelectedIndex; } private void cmbCorriente_SelectedIndexChanged(object sender, EventArgs e) { b = cmbCorriente.SelectedIndex; } private void cmbImpedancia_SelectedIndexChanged(object sender, EventArgs e) { c = cmbImpedancia.SelectedIndex; } private void btn_v_Click(object sender, EventArgs e) { i = Convert.ToDouble( txtCorriente.Text); r = Convert.ToDouble(txtImpedancia.Text); calcular("volt"); lbl_resultado.Text = lblTension.Text; } private void btn_i_Click(object sender, EventArgs e) { v = Convert.ToDouble(txtTension.Text); r = Convert.ToDouble(txtImpedancia.Text); calcular("amp"); lbl_resultado.Text = lblCorriente.Text; } private void btn_r_Click(object sender, EventArgs e) { v = Convert.ToDouble(txtTension.Text); i = Convert.ToDouble(txtCorriente.Text); calcular("ohm"); lbl_resultado.Text = lblImpedancia.Text; } } }
Descarga del archivo
Descargar archivo