はい - これは "世帯調査"問題のバージョンの場合です。私は特定の部分を理解して、問題全体の答えを得られないようにしようとしています!私は自分の配列に情報を読み込むための "選択事例"を持っており、配列の1つは家計が貧困要件を満たしているかどうかを判断するために使用されます。私はサブルーチンを使用して2番目の選択ケースを実行して、家計が基準を満たしているかどうかを判断し、それを配列に追加するかどうかを判断しています。このコードは動作しますが、これはスパゲッティコードです - 以下のようにそれぞれを使用するのではなく、すべての郡で動作する1つのテストケースを作成するにはどうすればよいですか?Visual Basic - テストケースから関数を呼び出して配列の戻り値を返す方法
'subroutine to load data to arrays, reset the form and call a new random ID number
Private Sub SubmitData()
Dim intHouseHoldIncome As Integer = CInt(txtHouseholdIncome.Text)
'as per the county and state , store values in array
Select Case True
Case cbxCountyState.Text = "Hamilton,OH"
income(0) = income(0) + intHouseHoldIncome
count(0) = count(0) + 1
Call povertystatus_0()
Case cbxCountyState.Text = "Butler,OH"
income(1) = income(1) + intHouseHoldIncome
count(1) = count(1) + 1
Call povertystatus_1()
Case cbxCountyState.Text = "Clermont,OH"
income(2) = income(2) + intHouseHoldIncome
count(2) = count(2) + 1
Call povertystatus_2()
Case cbxCountyState.Text = "Warren,OH"
income(3) = income(3) + intHouseHoldIncome
count(3) = count(3) + 1
Call povertystatus_3()
Case cbxCountyState.Text = "Campbell,KY"
income(4) = income(4) + intHouseHoldIncome
count(4) = count(4) + 1
Call povertystatus_4()
Case cbxCountyState.Text = "Boone,KY"
income(5) = income(5) + intHouseHoldIncome
count(5) = count(5) + 1
Call povertystatus_5()
Case cbxCountyState.Text = "Kenton,KY"
income(6) = income(6) + intHouseHoldIncome
count(6) = count(6) + 1
Call povertystatus_6()
End Select
'Clear and re-focus inputs
lblIdNumber.Text = ""
cbxHouseholdSize.SelectedIndex = -1
cbxCountyState.SelectedIndex = -1
txtHouseholdIncome.Text = String.Empty
'call random function to provide new id number
Call IdNumber()
End Sub
'function to determine poverty status+++++++++++++++++++
Private Sub povertystatus_0()
Dim intHouseHoldIncome As Integer = CInt(txtHouseholdIncome.Text)
Dim intsize As Integer = CInt(cbxHouseholdSize.SelectedItem)
Dim testincome As Integer
Select Case intsize
Case 1
testincome = 10210
Case 2
testincome = 13690
Case 3
testincome = 17170
Case 4
testincome = 20650
Case 5
testincome = 24130
End Select
If intHouseHoldIncome <= testincome Then
povertytrue(0) = povertytrue(0) + 1
End If
End Sub
Private Sub povertystatus_1()
Dim intHouseHoldIncome As Integer = CInt(txtHouseholdIncome.Text)
Dim intsize As Integer = CInt(cbxHouseholdSize.SelectedItem)
Dim testincome As Integer
Select Case intsize
Case 1
testincome = 10210
Case 2
testincome = 13690
Case 3
testincome = 17170
Case 4
testincome = 20650
Case 5
testincome = 24130
End Select
If intHouseHoldIncome <= testincome Then
povertytrue(1) = povertytrue(1) + 1
End If
End Sub
Private Sub povertystatus_2()
Dim intHouseHoldIncome As Integer = CInt(txtHouseholdIncome.Text)
Dim intsize As Integer = CInt(cbxHouseholdSize.SelectedItem)
Dim testincome As Integer
Select Case intsize
Case 1
testincome = 10210
Case 2
testincome = 13690
Case 3
testincome = 17170
Case 4
testincome = 20650
Case 5
testincome = 24130
End Select
If intHouseHoldIncome <= testincome Then
povertytrue(2) = povertytrue(2) + 1
End If
End Sub
Private Sub povertystatus_3()
Dim intHouseHoldIncome As Integer = CInt(txtHouseholdIncome.Text)
Dim intsize As Integer = CInt(cbxHouseholdSize.SelectedItem)
Dim testincome As Integer
Select Case intsize
Case 1
testincome = 10210
Case 2
testincome = 13690
Case 3
testincome = 17170
Case 4
testincome = 20650
Case 5
testincome = 24130
End Select
If intHouseHoldIncome <= testincome Then
povertytrue(3) = povertytrue(3) + 1
End If
End Sub
Private Sub povertystatus_4()
Dim intHouseHoldIncome As Integer = CInt(txtHouseholdIncome.Text)
Dim intsize As Integer = CInt(cbxHouseholdSize.SelectedItem)
Dim testincome As Integer
Select Case intsize
Case 1
testincome = 10210
Case 2
testincome = 13690
Case 3
testincome = 17170
Case 4
testincome = 20650
Case 5
testincome = 24130
End Select
If intHouseHoldIncome <= testincome Then
povertytrue(4) = povertytrue(4) + 1
End If
End Sub
Private Sub povertystatus_5()
Dim intHouseHoldIncome As Integer = CInt(txtHouseholdIncome.Text)
Dim intsize As Integer = CInt(cbxHouseholdSize.SelectedItem)
Dim testincome As Integer
Select Case intsize
Case 1
testincome = 10210
Case 2
testincome = 13690
Case 3
testincome = 17170
Case 4
testincome = 20650
Case 5
testincome = 24130
End Select
If intHouseHoldIncome <= testincome Then
povertytrue(5) = povertytrue(5) + 1
End If
End Sub
Private Sub povertystatus_6()
Dim intHouseHoldIncome As Integer = CInt(txtHouseholdIncome.Text)
Dim intsize As Integer = CInt(cbxHouseholdSize.SelectedItem)
Dim testincome As Integer
Select Case intsize
Case 1
testincome = 10210
Case 2
testincome = 13690
Case 3
testincome = 17170
Case 4
testincome = 20650
Case 5
testincome = 24130
End Select
If intHouseHoldIncome <= testincome Then
povertytrue(6) = povertytrue(6) + 1
End If
End Sub
このハードコードされたデータをどのようにファイルまたはdbaseに格納するかについて考える必要があります。したがって、簡単に変更して拡張することができます。一度それを持っていれば、オプションはありませんが正しく書きます。 –
パラメータを使用します。 – N0Alias