Simple VB.net Code for Parallel Resistors

 

 

 

 

         

Shown below is a simple VB.net code for computing the effective resistance of several resistors in parallel, 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 accepts several different values of resistance, and outputs their effective resistance in parallel connection. For example, in the screenshot of the form below, resistors with values 330, 470, and 220 ohms will exhibit an effective resistance of 103.06 ohms if they're connected in parallel.

 

      

  

Imports System.Math
Public Class frmMain Inherits System.Windows.Forms.Form

  

Dim Dividend As Single
Dim Divisor As Single
Dim Resistance As Single
               

Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
     Dim tmpStr As String
     'Check if input is a valid number
     tmpStr = InputBox("Input resistor value", "Add Resistor")
     If IsNumeric(tmpStr) = False Then
          MsgBox("Please input numbers only.")
          Exit Sub
     End If
     'Add resistor in the listview
     Dim lstitem As New ListViewItem
     lstitem.Text = lvwResistor.Items.Count + 1
     lstitem.SubItems.Add(tmpStr)
     lvwResistor.Items.Add(lstitem)
     lstitem = Nothing
     If lvwResistor.Items.Count = 1 Then
          txtR.Text = tmpStr
     Else
          txtR.Text = GetResistance(Val(txtR.Text), Val(tmpStr))
     End If
End Sub
          
Private Function GetResistance(ByVal R1 As Single, ByVal R2 As Single) As Single
     GetResistance = Round(((R1 * R2) / (R1 + R2)), 2)
End Function
            
Private Sub cmdClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdClear.Click
     Dividend = 0
     Divisor = 0
     txtR.Text = 0
     lvwResistor.Items.Clear()
End Sub

            

End Class