我已经研究和阅读了一切,我可以从这里的问题,但没有我已经尝试解决了这个问题。该函数旨在为应用程序输出一个字母等级。这里是类和函数的代码,以获得更好的清晰度。我如何解决'功能不会返回所有代码路径上的值'
Public Class Coursegrade
'names private veriables
Private _Score1 As Integer
Private _Score2 As Integer
Private _Score3 As Integer
Private Letter_grade As String
'gets and returns each veriable
'for application use
Public Property Grade As String
Get
Return Letter_grade
End Get
Set(value As String)
If value > String.Empty Then
Letter_grade = value
Else
Letter_grade = String.Empty
End If
End Set
End Property
Public Property TestScore1 As Integer
Get
Return _Score1
End Get
Set(value As Integer)
If value > 0 Then
_Score1 = value
Else
_Score1 = 0
End If
End Set
End Property
Property TestScore2 As Integer
Get
Return _Score2
End Get
Set(value As Integer)
If value > 0 Then
_Score2 = value
Else
_Score2 = 0
End If
End Set
End Property
Public Property TestScore3 As Integer
Get
Return _Score3
End Get
Set(value As Integer)
If value > 0 Then
_Score3 = value
Else
_Score3 = 0
End If
End Set
End Property
'starts veriables of at 0
Public Sub New()
_Score1 = 0
_Score2 = 0
_Score3 = 0
End Sub
'calculates the adverage
Public Function Gettotal() As Integer
Return _Score1 + _Score2 + _Score3
End Function
Public Function Give_letter_grade() As String
Dim intTotal As Integer
intTotal = Gettotal()
'start your secletion
If intTotal <= 270 AndAlso intTotal >= 300 Then
Letter_grade = "A"
ElseIf intTotal <= 240 AndAlso intTotal >= 269 Then
Letter_grade = "B"
ElseIf intTotal <= 210 AndAlso intTotal >= 239 Then
Letter_grade = "C"
ElseIf intTotal <= 180 AndAlso intTotal >= 290 Then
Letter_grade = "D"
ElseIf intTotal > 180 Then
Letter_grade = "F"
Else
Letter_grade = ""
End If
End Function
错误显示上给予字母等级
结束功能如何'intTotal'永远是<270 and > 300在同一时间?另外vba和VB.NET不一样。由于该方法(函数)不返回任何东西,你会得到消息 – Plutonix
你对此的期望是什么:如果value> String.Empty然后 –
我打算让它为这个数字范围提供相同的输出。 –