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

Electrical resistors have three colored bands where each color represents an int

ID: 3812510 • Letter: E

Question

Electrical resistors have three colored bands where each color represents an integer code according to the table below The resistance (in ohms) is found as follows: (1) multiply the code value corresponding to the first band by 10 (2). Add the result to the code value for the second band. (3) Multiply the sum found in step 2 by 10^n, where n is the code value of the third band. For example if the bands are red, yellow and orange (with code values 2, 4, and 3) the resistance would be (2*10+4)*10^3= 24000 ohms. a. Write a VBA function get Value which has the name of the color as an input and returns the numerical value. b. The Excel Resistance Color calculator shown at the right can be used to find the resistance from a pull-down menu of colors in cells A3:C3. Write the macro that takes color data from cells A3:C3, computes the resistance using the function you wrote in part a. and writes the resistance value to cell B5.

Explanation / Answer

VBA function:

Private Sub Form_Load()
' Here is where you declare the variable to hold the return value of your function
Dim myResistor As Double

' Here is where you call your function
myResistor = Resistor("black", "blue", "silver")

' Here is where you display the return value
Me.Caption = CStr(myResistor)

End Sub

Function Resistor(color1 As String, color2 As String, color3 As String) As Double
' Here is where you declare the variables you use to do calculations
Dim dblColor1 As Double
Dim dblColor2 As Double
Dim dblColor3 As Double

' Here is where you convert your parameter to a number
Select Case color1
Case "black", "Black"
dblColor1 = 0
Case "brown", "Brown"
dblColor1 = 1
Case "Red", "red"
dblColor1 = 2
Case "Orange", "orange"
dblColor1 = 3
Case "Yellow", "yellow"
dblColor1 = 4
Case "Green", "green"
dblColor1 = 5
Case "Blue", "blue"
dblColor1 = 6
Case "Violet", "violet", "Purple", "purple"
dblColor1 = 7
Case "Grey", "grey", "Gray", "gray"
dblColor1 = 8
Case "White", "white"
dblColor1 = 9
Case "Gold", "gold"
color1 = 0.1
Case "Silver", "silver"
dblColor1 = 0.001
End Select

' Here is where you convert your next parameter to a number
Select Case color2
Case "black", "Black"
dblColor2 = 0
Case "brown", "Brown"
dblColor2 = 1
Case "Red", "red"
dblColor2 = 2
Case "Orange", "orange"
dblColor2 = 3
Case "Yellow", "yellow"
dblColor2 = 4
Case "Green", "green"
dblColor2 = 5
Case "Blue", "blue"
dblColor2 = 6
Case "Violet", "violet", "Purple", "purple"
dblColor2 = 7
Case "Grey", "grey", "Gray", "gray"
dblColor2 = 8
Case "White", "white"
dblColor2 = 9
Case "Gold", "gold"
dblColor2 = 0.1
Case "Silver", "silver"
dblColor2 = 0.001
End Select

' Here is where you convert your last parameter to a number
Select Case color3
Case "black", "Black"
dblColor3 = 0
Case "brown", "Brown"
dblColor3 = 1
Case "Red", "red"
dblColor3 = 2
Case "Orange", "orange"
dblColor3 = 3
Case "Yellow", "yellow"
dblColor3 = 4
Case "Green", "green"
dblColor3 = 5
Case "Blue", "blue"
dblColor3 = 6
Case "Violet", "violet", "Purple", "purple"
dblColor3 = 7
Case "Grey", "grey", "Gray", "gray"
dblColor3 = 8
Case "White", "white"
dblColor3 = 9
Case "Gold", "gold"
dblColor3 = 0.1
Case "Silver", "silver"
dblColor3 = 0.001
End Select

' Here is where you do your calculation, and set the return value
Resistor = (dblColor1 * 10 + dblColor2) * (10 ^ dblColor3)

End Function

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote