'Ohm calculater function by
Function Resistance(Color1, Color2, Color3, Optional Color4)
'First color is The first Number. Second is the second number. If there is no fourth color, then the Third is how many 0's you add at the end. If there is a fourth, then the first three are your first three numbers and the FOURTH is the number of 0's.
If IsMissing(Color4) = True Then
'Checks if there is a fourth color given, and runs one of two sets of code depending on if it is/ isn't.
Select Case Color1
Case black: First = 0
Case brown: First = 10
Case red: First = 20
Case orange: First = 30
Case yellow: First = 40
Case green: First = 50
Case blue: First = 60
Case purple: First = 70
Case violet: First = 70
Case grey: First = 80
Case white: First = 90
End Select
Select Case Color2
Case black: Second = 0
Case brown: Second = 1
Case red: Second = 2
Case orange: Second = 3
Case yellow: Second = 4
Case green: Second = 5
Case blue: Second = 6
Case purple: Second = 7
Case violet: Second = 7
Case grey: Second = 8
Case white: Second = 9
End Select
Select Case Color3
Case black: Third = 10 ^ 0
Case brown: Third = 10 ^ 1
Case red: Third = 10 ^ 2
Case orange: Third = 10 ^ 3
Case yellow: Third = 10 ^ 4
Case green: Third = 10 ^ 5
Case blue: Third = 10 ^ 6
Case purple: Third = 10 ^ 7
Case violet: Third = 10 ^ 7
Case grey: Third = 10 ^ 8
Case white: Third = 10 ^ 9
End Select
Resistance = (First + Second) * Third
Else
'Runs this code if color4 is present
End If
End Function
This is supposed to be a program in VBA that takes 3 or 4 colors as inputs, and then gives you the measure of resistance in ohms. The first two colors give the first two integers, and the third gives the number of 0's. It doesn't work for me, could anybody help me out here and tell me what I am doing wrong?
Well, what doesn't works ? Everything or just a single thing ?
[editline]09:17PM[/editline]
Are colours names already registered ? Does VBA knows that by White you mean "This case's color is white" ?
I don't know anything about programming, I just started last week. But, I just don't know what is wrong
[editline]06:28PM[/editline]
I just don't know, I need some help with it.
I have three arguments. I want the final result to be derived from all three colors, and I use select case to define what the colors are
After that and before that, I don't know what to do. Could you help me? I am also pretty sure that the names of the Variables in the case won't work, like color1 and stuff but I just don't know.
[code]Function Resistance(Color1, Color2, Color3)
'First color is The first Number. Second is the second number. If there is no fourth color, then the Third is how many 0's you add at the end. If there is a fourth, then the first three are your first three numbers and the FOURTH is the number of 0's.
Select Case Color1
Case black: First = 0
Case brown: First = 10
Case red: First = 20
Case orange: First = 30
Case yellow: First = 40
Case green: First = 50
Case blue: First = 60
Case purple: First = 70
Case violet: First = 70
Case grey: First = 80
Case white: First = 90
End Select
Select Case Color2
Case black: Second = 0
Case brown: Second = 1
Case red: Second = 2
Case orange: Second = 3
Case yellow: Second = 4
Case green: Second = 5
Case blue: Second = 6
Case purple: Second = 7
Case violet: Second = 7
Case grey: Second = 8
Case white: Second = 9
End Select
Select Case Color3
Case black: Third = 10 ^ 0
Case brown: Third = 10 ^ 1
Case red: Third = 10 ^ 2
Case orange: Third = 10 ^ 3
Case yellow: Third = 10 ^ 4
Case green: Third = 10 ^ 5
Case blue: Third = 10 ^ 6
Case purple: Third = 10 ^ 7
Case violet: Third = 10 ^ 7
Case grey: Third = 10 ^ 8
Case white: Third = 10 ^ 9
End Select
Resistance = (First + Second) * Third
End Function[/code]
I run it, and it says "argument not optional." and highlights second.
(I decided to give up on the four color part, it was only extra credit anyway)
[editline]06:51PM[/editline]
Help
Try Changing the name of Second. I changed it to SecondPie and had no errors
but the code still doesn't work.
[editline]07:43PM[/editline]
I just need it to work. It says #VALUE when I try to use it.
[editline]07:44PM[/editline]
However, using (1,1,1) gives me 0.
This thread reminds me why I hate VB: types are not required. I want to help you, but I have no idea what type of argument is being passed and what type the function is expecting.
VB = Very Bullshitty
got it anyway
What was your solution?
Sorry, you need to Log In to post a reply to this thread.