男性、女性の2つのフィールドの範囲の値を取得して、パーセンテージを計算しようとしています。
EmployeesData.vb で
Public Function getPercentMen() As Double
Dim result As Double
result = 0
If Men + Women > 0 Then result = (Men * 100) / (Men + Women)
End If
Return result
End Function
私の Demographics.vb には、次の出力があります。
Private Sub updateView()
' The percentage Men and Women recorded is displayed in
' the appropriate text boxes.
percentMenTextBox.Text = fEmployeesData.getPercentMen().ToString()
percentWomenTextBox.Text = fEmployeesData.getPercentWomen().ToString()
updateView()
End Sub
私が得るエラーは
An unhandled exception of type 'System.StackOverflowException' occurred in mscorlib.dll
Visual Studio は次の行を示します
percentMenTextBox.Text = fEmployeesData.getPercentMen().ToString()
問題は、Double を String に誤って強制しようとしている、またはそのようなことだと思います
クラス全体を追加しました
Public Class EmployeesData
Private fMen As Integer
Private fWomen As Integer
Public Sub New()
fMen = 0
fWomen = 0
End Sub
Public ReadOnly Property Men As Integer
Get
Return fMen
End Get
End Property
Public ReadOnly Property Women As Integer
Get
Return fWomen
End Get
End Property
Public Sub addMen()
fMen = fMen + 1
End Sub
Public Sub addWomen()
fWomen = fWomen + 1
End Sub
Public Function getPercentMen() As Double
Dim result As Double
result = 0
If Men + Women > 0 Then
result = (Men * 100) / (Men + Women)
End If
Return result
End Function
Public Function getPercentWomen() As Double
Dim result As Double
result = 0
If Men + Women > 0 Then
result = (Women * 100) / (Men + Women)
End If
Return result
End Function
Public Sub reset()
fMen = 0
fWomen = 0
End Sub
End Class