2014-07-18 2 views
0

대다수의 코드는 '계산 합계 계산'버튼 이외의 다른 기능을합니다. 세 개의 목록 상자가 있고 '합계 계산'버튼을 사용해야 'lstCosts'목록 상자에서 선택한 비용을 반복 할 수 있습니다. 그러나 Option Strict On에서는 "List가 Double의 멤버가 아니므로"ListCount가 Double의 멤버가 아닙니다 "라는 오류가 표시됩니다. 누군가이 문제를 해결하는 데 도움이 될 수 있습니까? 내 코드가 작동에 가깝다는 것을 안다. 어떻게 해야할지 모르겠다. 다음 루프에서 누적 합계를 계산할 수 없습니다.

다음은 작동하지 않습니다 내 코드입니다 : 내 솔루션을 지원하기 위해 더 많은 코드가 전에 내가 보았다

Private Sub btnAddCourse_Click(sender As System.Object, e As System.EventArgs) Handles btnAddCourse.Click 

    'Declare variables 
    Dim strCourse As String 'To hold the Course Values 
    Dim strLocation As String 'To hold the Location values 

    'Item Indexing 
    'Identifies the four Course strings 
    strCourse = lstCourse.Items(0).ToString() 
    strCourse = lstCourse.Items(1).ToString() 
    strCourse = lstCourse.Items(2).ToString() 
    strCourse = lstCourse.Items(3).ToString() 

    'Identifies the four Location strings 
    strLocation = lstLocation.Items(0).ToString() 
    strLocation = lstLocation.Items(1).ToString() 
    strLocation = lstLocation.Items(2).ToString() 
    strLocation = lstLocation.Items(3).ToString() 


    If lstCourse.SelectedIndex = -1 Then 
     'Error Message for no course selected 
     MessageBox.Show("Select a course.", "Error", _ 
         MessageBoxButtons.OK, MessageBoxIcon.Error) 
    ElseIf lstLocation.SelectedIndex = -1 Then 
     'Error message for no location selected 
     MessageBox.Show("Select a location.", "Error", _ 
         MessageBoxButtons.OK, MessageBoxIcon.Error) 
     'Essential Linux and Belfast selected = £705 
    ElseIf lstCourse.SelectedIndex = 0 And lstLocation.SelectedIndex = 0 Then 
     lstCosts.Items.Add(705) 
     'Essential Linux and Coleraine selected = £600 
    ElseIf lstCourse.SelectedIndex = 0 And lstLocation.SelectedIndex = 1 Then 
     lstCosts.Items.Add(600) 
     'Essential Linux and Jordasntown selected = £600 
    ElseIf lstCourse.SelectedIndex = 0 And lstLocation.SelectedIndex = 2 Then 
     lstCosts.Items.Add(600) 
     'Essential Linux and Magee selected = £630 
    ElseIf lstCourse.SelectedIndex = 0 And lstLocation.SelectedIndex = 3 Then 
     lstCosts.Items.Add(630) 
     'Project Management and Belfast selected £520 
    ElseIf lstCourse.SelectedIndex = 1 And lstLocation.SelectedIndex = 0 Then 
     lstCosts.Items.Add(520) 
     'Project Management and Coleraine selected = £450 
    ElseIf lstCourse.SelectedIndex = 1 And lstLocation.SelectedIndex = 1 Then 
     lstCosts.Items.Add(450) 
     'Project Management and Jordanstown selected = £450 
    ElseIf lstCourse.SelectedIndex = 1 And lstLocation.SelectedIndex = 2 Then 
     lstCosts.Items.Add(450) 
     'Project Management and Magee selected = £470 
    ElseIf lstCourse.SelectedIndex = 1 And lstLocation.SelectedIndex = 3 Then 
     lstCosts.Items.Add(470) 
     'Overview of net and Belfast selected = £705 
    ElseIf lstCourse.SelectedIndex = 2 And lstLocation.SelectedIndex = 0 Then 
     lstCosts.Items.Add(705) 
     'Overview of net and Coleraine selected = £575 
    ElseIf lstCourse.SelectedIndex = 2 And lstLocation.SelectedIndex = 1 Then 
     lstCosts.Items.Add(575) 
     'Overview of net and Jordanstown selected = £575 
    ElseIf lstCourse.SelectedIndex = 2 And lstLocation.SelectedIndex = 2 Then 
     lstCosts.Items.Add(575) 
     'Overview of net and Magee selected = £605 
    ElseIf lstCourse.SelectedIndex = 2 And lstLocation.SelectedIndex = 3 Then 
     lstCosts.Items.Add(605) 
     'PHP and Belfast selected = £780 
    ElseIf lstCourse.SelectedIndex = 3 And lstLocation.SelectedIndex = 0 Then 
     lstCosts.Items.Add(780) 
     'PHP and Coleraine selected = £675 
    ElseIf lstCourse.SelectedIndex = 3 And lstLocation.SelectedIndex = 1 Then 
     lstCosts.Items.Add(675) 
     'PHP and Jordanstown selected = £675 
    ElseIf lstCourse.SelectedIndex = 3 And lstLocation.SelectedIndex = 2 Then 
     lstCosts.Items.Add(675) 
     'PHP and Magee selected = £705 
    ElseIf lstCourse.SelectedIndex = 3 And lstLocation.SelectedIndex = 3 Then 
     lstCosts.Items.Add(705) 
    End If 

End Sub 

Private Sub btnCalculateTotal_Click(sender As Object, e As EventArgs) Handles btnCalculateTotal.Click 

    Dim lstCosts As Double 
    Dim lblTotalCost As Double 

    For lstCosts = 0 To lstCosts.ListCount - 1 
     lblTotalCost = lblTotalCost + CDbl(lstCosts.List(lstCosts)) 
    Next lstCosts 

    lblTotalCost = lstCosts 

End Sub 

Private Sub btnReset_Click(sender As Object, e As EventArgs) Handles btnReset.Click 

    'Clears the fields 
    lstCourse.ClearSelected() 
    lstLocation.ClearSelected() 
    lstCosts.Items.Clear() 
    lblTotalCost.Text = String.Empty 

End Sub 

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click 

    'Closes the Program 
    Me.Close() 

End Sub 

답변

0

. 로컬 네이밍과 할당이라는 두 가지 문제가 있다고 생각합니다.

Private Sub btnCalculateTotal_Click(sender As Object, e As EventArgs) Handles btnCalculateTotal.Click 

'Declare variables 
Dim lvIterate As Double ' 
Dim lvTotalOfCost As Double 

'Calculate Total Cost 
For lvIterate = 0 To lstCosts.ListCount - 1 

    lvTotalOfCost = lvTotalOfCost + CDbl(lstCosts.List(lvIterate)) 
Next 

lblTotalCost.Text = lvTotalOfCost 

최종 하위

은 당신이 발급 해결 바랍니다.

+0

여전히 작동하지 않는 것 같지만 'ListCount'와 '.list'가 Double – user3816555

+0

의 구성원이 아닌 것과 동일한 문제가 계속 발생합니다. 어떤 유형의 컨트롤이 lstCosts입니까? listBox 및 VB에서 listView 사용 "lstCosts.Items.Count" – BoxasFrame

+0

"lstCosts.Items.Count"도 작동하지 않는 것 같습니다 난 꽤 혼란스러워. lstCosts는 비용을 보유하고있는 목록 상자의 이름입니다. 목록 상자의 각 비용을 반복 한 후 총 비용 레이블 "lblTotalCost"에 이러한 모든 비용의 합계가 표시되어야합니다. – user3816555

관련 문제