2017-05-29 90 views
-1

我已經研究和閱讀了一切,我可以從這裏的問題,但沒有我已經嘗試解決了這個問題。該函數旨在爲應用程序輸出一個字母等級。這裏是類和函數的代碼,以獲得更好的清晰度。我如何解決'功能不會返回所有代碼路徑上的值'

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 

錯誤顯示上給予字母等級

+2

結束功能如何'intTotal'永遠是<270 and > 300在同一時間?另外vba和VB.NET不一樣。由於該方法(函數)不返回任何東西,你會得到消息 – Plutonix

+0

你對此的期望是什麼:如果value> String.Empty然後 –

+0

我打算讓它爲這個數字範圍提供相同的輸出。 –

回答

1
Public Function Give_letter_grade() As String 
Dim intTotal As Integer 
intTotal = Gettotal() 

'start your secletion 
If intTotal <= 300 AndAlso intTotal >= 270 Then 
    Letter_grade = "A" 
ElseIf intTotal <= 269 AndAlso intTotal >= 240 Then 
    Letter_grade = "B" 
ElseIf intTotal <= 239 AndAlso intTotal >= 210 Then 
    Letter_grade = "C" 
ElseIf intTotal < 210 AndAlso intTotal >= 180 Then 
    Letter_grade = "D" 
ElseIf intTotal < 180 Then 
    Letter_grade = "F" 
Else 

    Letter_grade = "" 
End If 

Return Letter_grade '<--- you are missing the 'Return' statement 
End Function 
+0

@catsrull您需要將答案標記爲已接受,如果它回答您的問題 – alwaysVBNET

+0

感謝您也解釋我做錯的一切,而不是粗魯的不做它 –

相關問題