是 - 如果是「住戶調查」問題的版本,則爲此。我試圖理解一個特定的部分沒有得到整個問題的答案!我有一個「select case true」將信息加載到我的數組中,其中一個數組用於確定家庭是否符合貧困條件。我正在使用一個子例程來運行第二個選擇案例來確定家庭是否符合條件,以及它是否將其添加到數組中。這段代碼有效,但它是意大利麪代碼 - 我如何創建一個適用於所有縣的測試用例,而不是像下面那樣爲每個用戶都使用一個?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