Simple VB.net Code for Ohm's Law

 

 

 

 

         

Shown below is a simple VB.net code for Ohm's Law, along with a screenshot of the form used with it, for reference by students learning to program in VB.net in the context of electronics engineering. This VB.net program allows the voltage, current, or resistance to be computed from given values of the two other parameters. For example, in the screenshot of the form below, the voltage is the computed quantity, having been calculated from the given values of current and resistance.

 

  

  

  

Public Class frmMain Inherits System.Windows.Forms.Form

          

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     cbxCompute.Text = "Voltage"
End Sub
          
Private Sub cbxCompute_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbxCompute.SelectedIndexChanged
     txtV.Enabled = True
     txtI.Enabled = True
     txtR.Enabled = True
     Select Case cbxCompute.Text
          Case "Voltage"
               txtV.Enabled = False
          Case "Current"
               txtI.Enabled = False
          Case "Resistance"
               txtR.Enabled = False
      End Select
End Sub
          
Private Sub cmdCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCompute.Click
      Select Case cbxCompute.Text
          Case "Voltage"
               txtV.Text = Val(txtI.Text) * Val(txtR.Text)
          Case "Current"
               txtI.Text = Val(txtV.Text) / Val(txtR.Text)
          Case "Resistance"
               txtR.Text = Val(txtV.Text) / Val(txtI.Text)
      End Select
End Sub

  
End Class