Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help!! Due in 2 hours. Need the solution in Excel VBA, the working VBA co

ID: 3914317 • Letter: P

Question

Please help!! Due in 2 hours. Need the solution in Excel VBA, the working VBA code

I need the answer very urgently!!

Electrical impedance is the measure of the opposition that a circuit presents to a current (I) when a voltage (V) is applied. Impedance is represented as the complex quantity Z The RLC (Resistance Inductance Capacitance) impedance for both series and parallel circuit is calculated as shown in the table below: RLC IMPEDANCE FORMULAS CIRCUIT CONNECTION COMPLEX FORM ABSOLUTE VALUE RL C 1 .2 Series 1/(1/R+1jwL+jwC) OL Parallel Where R is the resistance, ohms L is the inductance, henrys C is the capacitance, farads f is the frequency, hertz ? is the angular frequency, ?-2tj is the imaginary unit i2--1) a. Write a VBA Sub Program to calculate the RLC impedance for both series and parallel circuit. i. Using Inputbox, get the circuit type from the user and calculate the impedance in both complex form and absolute value for the chosen circuit i. Make sure the value of R, L and C are numeric and non-zero

Explanation / Answer

Note:-

Please insert a new module and copy the code given below

ScreenShot

Program

Sub calculateImpedence()

On Error GoTo ErrHandle ' Error Trap

Dim strCircuitType As String

Dim strTemp As String ' Temporary String to take input value from user

Dim dblResistance As Double

Dim dblInductance As Double

Dim dblCapacitance As Double

Dim dblFrequency As Double

Dim dblComplexImpedence As Double

Dim dblAbsoluteImpedence As Double

  

CType:

strCircuitType = InputBox("Please specify the Circuit Type - ""S"" for Series, ""P"" for Parallel: ", "Impedence Calculation")

If strCircuitType <> "S" And strCircuitType <> "P" Then ' Validation for Series and Parallel Circuit

If MsgBox("Please only specify either ""S"" for Series Circuit or ""P"" for Parallel Circuit. Do you want to Re-Enter?", vbQuestion + vbYesNo + vbDefaultButton1) = vbYes Then

GoTo CType

Else

MsgBox "Impedence Calculation Terminated.", vbCritical

Exit Sub

End If

End If

R:

strTemp = InputBox("Please enter the Resistance(R): ", "Impedence Calculation")

If IsNumeric(strTemp) = False Or Val(strTemp) = 0 Then ' Validation for R

If MsgBox("Resistance(R) Value Must be a Numeric and Must Not Be Equal to Zero. Do you want to Re-Enter?", vbQuestion + vbYesNo + vbDefaultButton1) = vbYes Then

GoTo R

Else

MsgBox "Impedence Calculation Terminated.", vbCritical

Exit Sub

End If

Else

dblResistance = CDbl(strTemp)

End If

  

  

L:

strTemp = InputBox("Please enter the Inductance(L): ", "Impedence Calculation")

If IsNumeric(strTemp) = False Or Val(strTemp) = 0 Then ' Validation for L

If MsgBox("Inductance(L) Value Must be a Numeric and Must Not Be Equal to Zero. Do you want to Re-Enter?", vbQuestion + vbYesNo + vbDefaultButton1) = vbYes Then

GoTo L

Else

MsgBox "Impedence Calculation Terminated.", vbCritical

Exit Sub

End If

Else

dblInductance = CDbl(strTemp)

End If

  

C:

strTemp = InputBox("Please enter the Capacitance(C): ", "Impedence Calculation")

If IsNumeric(strTemp) = False Or Val(strTemp) = 0 Then ' Validation for C

If MsgBox("Capacitance(C) Value Must be a Numeric and Must Not Be Equal to Zero. Do you want to Re-Enter?", vbQuestion + vbYesNo + vbDefaultButton1) = vbYes Then

GoTo C

Else

MsgBox "Impedence Calculation Terminated.", vbCritical

Exit Sub

End If

Else

dblCapacitance = CDbl(strTemp)

End If

  

f:

strTemp = InputBox("Please enter the Frequency(f): ", "Impedence Calculation")

If IsNumeric(strTemp) = False Or Val(strTemp) = 0 Then ' Validation for f

If MsgBox("Frequency(f) Value Must be a Numeric and Must Not Be Equal to Zero. Do you want to Re-Enter?", vbQuestion + vbYesNo + vbDefaultButton1) = vbYes Then

GoTo f

Else

MsgBox "Impedence Calculation Terminated.", vbCritical

Exit Sub

End If

Else

dblFrequency = CDbl(strTemp)

End If

  

dblComplexImpedence = getComplexImpedence(strCircuitType, dblResistance, dblInductance, dblCapacitance, dblFrequency)

  

dblAbsoluteImpedence = getAbsoluteImpedence(strCircuitType, dblResistance, dblInductance, dblCapacitance, dblFrequency)

  

MsgBox "The Impedence Values are shown below:" & vbCrLf & _

"------------------------------------" & vbCrLf & _

"Complex Impedence: " & Round(dblComplexImpedence, 2) & vbCrLf & _

"Absoulte Impedence: " & Round(dblAbsoluteImpedence, 2)

Exit Sub

ErrHandle:

MsgBox "Error Occured: " & vbCrLf & Err.Description

Exit Sub

End Sub

Private Function getComplexImpedence(CT As String, R As Double, L As Double, C As Double, f As Double) As Double

'Function to calculate the Complex Impedence

Dim j As Double

Const PI As Double = 3.14

Dim dblAngularFrequency As Double

Dim dblTemp1 As Double

Dim dblTemp2 As Double

Dim dblTemp3 As Double

  

j = -1 ^ 0.5

  

dblAngularFrequency = 2 * PI * f

  

If CT = "S" Then

dblTemp1 = j * dblAngularFrequency * L

dblTemp2 = 1 / (j * dblAngularFrequency * C)

  

getComplexImpedence = R + dblTemp1 + dblTemp2

Else

dblTemp1 = 1 / R

dblTemp2 = 1 / (j * dblAngularFrequency * L)

dblTemp3 = j * dblAngularFrequency * C

  

getComplexImpedence = 1 / (dblTemp1 + dblTemp2 + dblTemp3)

End If

End Function

Private Function getAbsoluteImpedence(CT As String, R As Double, L As Double, C As Double, f As Double) As Double

Const j As Double = -1 ^ 0.5

Const PI As Double = 3.14

Dim dblAngularFrequency As Double

Dim dblTemp1 As Double

Dim dblTemp2 As Double

Dim dblTemp3 As Double

  

dblAngularFrequency = 2 * PI * f

  

If CT = "S" Then

dblTemp1 = Sqr(R)

dblTemp2 = dblAngularFrequency * L

dblTemp3 = 1 / (dblAngularFrequency * C)

  

getAbsoluteImpedence = (dblTemp1 + ((dblTemp2 - dblTemp3) ^ 2)) ^ 0.5

Else

dblTemp1 = 1 / Sqr(R)

dblTemp2 = dblAngularFrequency * C

dblTemp3 = 1 / (dblAngularFrequency * L)

  

getAbsoluteImpedence = 1 / (dblTemp1 + (dblTemp2 - dblTemp3) ^ 2) ^ 0.5

End If

End Function