trying to create my first UDF, I keep getting Compile error: Sub or Function not defined. completely self taught, trying this out as a hobby. I get the first line highlighted on this error, here's my code.
尝试创建我的第一个UDF,我不断收到编译错误:Sub或Function未定义。完全自学成才,尝试将其作为一种爱好。我得到第一行突出显示此错误,这是我的代码。
Function SkillCost(AttrLVL, SkillLVL, E_A_H)
If E_A_H = "E" Then
If SkillLVL - AttrLVL < 0 Then
SkillCost = 0
Else
If SkillLVL - AttrLVL < 1 Then
SkillCost = 1
Else
If SkillLVL - AttrLVL < 2 Then
SkillCost = 2
Else
Skill Cost = ((SkillLVL - AttrLVL) - 1) * 4
End If
End If
End If
Else
If E_A_H = "A" Then
If SkillLVL - AttrLVL < -1 Then
SkillCost = 0
Else
If SkillLVL - AttrLVL < 0 Then
SkillCost = 1
Else
If SkillLVL - AttrLVL < 1 Then
SkillCost = 2
Else
SkillCost = (SkillLVL - AttrLVL) * 4
End If
End If
End If
Else
If E_A_H = "H" Then
If SkillLVL - AttrLVL < -2 Then
SkillCost = 0
Else
If SkillLVL - AttrLVL < -1 Then
SkillCost = 1
Else
If SkillLVL - AttrLVL < 0 Then
SkillCost = 2
Else
SkillCost = ((SkillLVL - AttrLVL) + 1) * 4
End If
End If
End If
End If
End If
End If
End Function
I know this is just a bunch of nested if()'s, but I wanted to start with something simple, and I would be doing this within vlookup()'s. Here's the chart I'm basing this off of. What my function is quantifying basically, just figuring out skill level cost when presented with defining attribute lvl, desired skill lvl, and difficulty of skill.
我知道这只是一堆嵌套的if(),但我想从简单的东西开始,我会在vlookup()中做这个。这是我基于此的图表。我的功能基本上是量化的,只是在提出定义属性lvl,所需技能lvl和技能难度时计算技能水平成本。
2 个解决方案
#1
2
Spelling error here:
这里拼写错误:
Skill Cost = ((SkillLVL - AttrLVL) - 1) * 4
#2
1
As per my comment look into Select Case
:
根据我的评论看看Select Case:
Function SkillCost(AttrLVL, SkillLVL, E_A_H)
If E_A_H = "E" Then
Select Case SkillLVL - AttrLVL
Case Is < 0
SkillCost = 0
Case Is < 1
SkillCost = 1
Case Is < 2
SkillCost = 2
Case Else
SkillCost = ((SkillLVL - AttrLVL) - 1) * 4
End Select
ElseIf E_A_H = "A" Then
Select Case SkillLVL - AttrLVL
Case Is < -1
SkillCost = 0
Case Is < 0
SkillCost = 1
Case Is < 1
SkillCost = 2
Case Else
SkillCost = ((SkillLVL - AttrLVL) - 1) * 4
End Select
ElseIf E_A_H = "H" Then
Select Case SkillLVL - AttrLVL
Case Is < -2
SkillCost = 0
Case Is < -1
SkillCost = 1
Case Is < 0
SkillCost = 2
Case Else
SkillCost = ((SkillLVL - AttrLVL) - 1) * 4
End Select
End If
End Function
This is just here for reference. @Gary'sStudent pointed out the error.
这只是供参考。 @ Gary'sStudent指出错误。
#1
2
Spelling error here:
这里拼写错误:
Skill Cost = ((SkillLVL - AttrLVL) - 1) * 4
#2
1
As per my comment look into Select Case
:
根据我的评论看看Select Case:
Function SkillCost(AttrLVL, SkillLVL, E_A_H)
If E_A_H = "E" Then
Select Case SkillLVL - AttrLVL
Case Is < 0
SkillCost = 0
Case Is < 1
SkillCost = 1
Case Is < 2
SkillCost = 2
Case Else
SkillCost = ((SkillLVL - AttrLVL) - 1) * 4
End Select
ElseIf E_A_H = "A" Then
Select Case SkillLVL - AttrLVL
Case Is < -1
SkillCost = 0
Case Is < 0
SkillCost = 1
Case Is < 1
SkillCost = 2
Case Else
SkillCost = ((SkillLVL - AttrLVL) - 1) * 4
End Select
ElseIf E_A_H = "H" Then
Select Case SkillLVL - AttrLVL
Case Is < -2
SkillCost = 0
Case Is < -1
SkillCost = 1
Case Is < 0
SkillCost = 2
Case Else
SkillCost = ((SkillLVL - AttrLVL) - 1) * 4
End Select
End If
End Function
This is just here for reference. @Gary'sStudent pointed out the error.
这只是供参考。 @ Gary'sStudent指出错误。