2016-10-15 3 views
1

안녕하세요 저는 양식의 확인란 선택을 처리하기 위해 다음 코드를 작성했습니다. 총액은 선거에 기초하여 증분되어 표시되어야합니다. 누군가 이것에 관해서 어떻게에 관해서는 전에 나를 도와주세요. 다음은 선택을 처리하고 총계를 계산하는 방법입니다.vb.net의 확인란 목록에서 소계 계산하기

Private Sub computeCurrentSelection() 
    If chkugalis.Checked = True Then 'ugali fish selected 
     orderAmt = lab.Text 
     total = ugalif * orderAmt 
     subtotal = total 
     lstReceipt.Items.Add(orderAmt & " plates of" & " Ugali n fish " & " Kshs" & total) 
    End If 

    If chkGitheri.Checked = True Then 'ugali dengu slected 
     orderAmt = lab3.Text 
     total = ugalid * orderAmt 
     subtotal = total 
     lstReceipt.Items.Add(orderAmt & " plates of " & "Ugali n dengu " & " Kshs" & total) 
    End If 
    If chkUgaliB.Checked = True Then 'githeri selected 
     orderAmt = lab2.Text 
     total = githeri * orderAmt 
     subtotal = total 
     lstReceipt.Items.Add(orderAmt & " plates of " & "Githeri " & " Kshs" & total) 
    End If 
    If chkPilau.Checked = True Then 
     orderAmt = lab4.Text 
     total = chapo * orderAmt 
     subtotal = total 
     lstReceipt.Items.Add(orderAmt & " plates of " & "Pilau " & " Kshs" & total) 
    End If 
    If chkPizza.Checked = True Then 
     orderAmt = lab5.Text 
     total = pilau * orderAmt 
     subtotal = total 
     lstReceipt.Items.Add(orderAmt & " plates of " & "Pizza " & " Kshs" & total) 
    End If 
    If chkMandazi.Checked = True Then 
     orderAmt = lab6.Text 
     total = pizza * orderAmt 
     subtotal = total 
     lstReceipt.Items.Add(orderAmt & "mandazi " & " Kshs" & total) 
    End If 
    If chkSamosa.Checked = True Then 
     orderAmt = lab7.Text 
     total = mandazi * orderAmt 
     subtotal = total 
     lstReceipt.Items.Add(orderAmt & "Samosa " & " Kshs" & total) 
    End If 
    If chkChapon.Checked = True Then 
     orderAmt = lab8.Text 
     total = samosa * orderAmt 
     subtotal = total 
     lstReceipt.Items.Add(orderAmt & "Chapati " & " Kshs" & total) 
    End If 
    If chkWater.Checked = True And chk300ml.Checked = True Then 
     orderAmt = lab9.Text 
     total = water1 * orderAmt 
     subtotal = total 
     lstReceipt.Items.Add(orderAmt & " Bottles of 300ml Water " & " Kshs" & total) 
    End If 
    If chkWater.Checked = True And chk500ml.Checked = True Then 
     orderAmt = lab9.Text 
     total = water2 * orderAmt 
     subtotal = total 
     lstReceipt.Items.Add(orderAmt & " Bottles of 500ml Water " & " Kshs" & total) 
    ElseIf chkWater.Checked = True And chk1l.Checked = True Then 
     orderAmt = lab9.Text 
     total = water3 * orderAmt 
     subtotal = total 
     lstReceipt.Items.Add(orderAmt & " Bottles of 1l Water " & " Kshs" & total) 
    End If 
    If chkWater.Checked = True And chk2l.Checked = True Then 
     orderAmt = lab9.Text 
     total = water4 * orderAmt 
     subtotal = total 
     lstReceipt.Items.Add(orderAmt & " Bottles of 2l Water " & " Kshs" & total) 
    End If 
    If chkSoda.Checked = True And chk300ml.Checked = True Then 
     orderAmt = lab10.Text 
     total = soda1 * orderAmt 
     subtotal = total 
     lstReceipt.Items.Add(orderAmt & " Bottles of 300ml Soda " & " Kshs" & total) 
    End If 
    If chkSoda.Checked = True And chk500ml.Checked = True Then 
     orderAmt = lab10.Text 
     total = soda2 * orderAmt 
     subtotal = total 
     lstReceipt.Items.Add(orderAmt & " Bottles of 500ml Soda " & " Kshs" & total) 
    End If 
    If chkSoda.Checked = True And chk1l.Checked = True Then 
     orderAmt = lab10.Text 
     total = soda3 * orderAmt 
     subtotal = total 
     lstReceipt.Items.Add(orderAmt & " Bottles of 1l Soda " & " Kshs" & total) 
    End If 
    If chkSoda.Checked = True And chk2l.Checked = True Then 
     orderAmt = lab10.Text 
     total = soda4 * orderAmt 
     lstReceipt.Items.Add(orderAmt & " Bottles of 2l Soda " & " Kshs" & total) 
    End If 
    If chkJuice.Checked = True And chk300ml.Checked = True Then 
     orderAmt = lab11.Text 
     total = juice1 * orderAmt 
     subtotal = total 
     lstReceipt.Items.Add(orderAmt & " Bottles of 300ml juice " & " Kshs" & total) 
    End If 
    If chkJuice.Checked = True And chk500ml.Checked = True Then 
     orderAmt = lab11.Text 
     total = juice2 * orderAmt 
     subtotal = total 
     lstReceipt.Items.Add(orderAmt & " Bottles of 500ml juice " & " Kshs" & total) 
    End If 
    If chkJuice.Checked = True And chk1l.Checked = True Then 
     orderAmt = lab11.Text 
     total = juice3 * orderAmt 
     subtotal = total 
     lstReceipt.Items.Add(orderAmt & " Bottles of 1l juice " & " Kshs" & total) 
    End If 
    If chkJuice.Checked = True And chk2l.Checked = True Then 
     orderAmt = lab11.Text 
     total = juice4 * orderAmt 
     subtotal = total 
     lstReceipt.Items.Add(orderAmt & " Bottles of 2l juice " & " Kshs" & total) 
    End If 
End Sub 
+0

'즉, = total lstReceipt.Items.Add (orderAmt & "Plague"& "Ugali n fish"& "Kshs"& total) End If'부분 합계는 선택한 모든 확인란의 총 합계 여야합니다. if 하나의 확인란 만 선택하면 부분 합계는 확인란의 합계가되어야하지만 두 개 이상이 선택되면 부분 합계는 선택한 모든 확인란의 합계 합계 –

답변

2

정확하게 이해했는지는 확실하지 않지만 한 번 사용해 보겠습니다.

이 시도 : 참 chkugalis.Checked = 그런 다음 '우갈리 물고기 orderAmt = lab.Text 총 = ugalif * orderAmt 소계를 선택한 경우

이 총은 개인 체크 박스 항목에서 계산되어야한다
Private Function ComputeCurrentSelection() As Integer ' not sure for data type, you decide 
    Dim total As Integer 
    If chkugalis.Checked = True Then 'ugali fish selected 
     orderAmt = lab.Text 
     total += ugalif * orderAmt   
     lstReceipt.Items.Add(orderAmt & " plates of" & " Ugali n fish " & " Kshs" & total) 
    End If 

    If chkGitheri.Checked = True Then 'ugali dengu slected 
     orderAmt = lab3.Text 
     total += ugalid * orderAmt 
     lstReceipt.Items.Add(orderAmt & " plates of " & "Ugali n dengu " & " Kshs" & total) 
    End If 
    If chkUgaliB.Checked = True Then 'githeri selected 
     orderAmt = lab2.Text 
     total += githeri * orderAmt 
     lstReceipt.Items.Add(orderAmt & " plates of " & "Githeri " & " Kshs" & total) 
    End If ... 

    Return total 
End Function 
+0

감사합니다. 작동했습니다. –

1

I이

 Private Sub computeCurrentSelection() 
    If chkugalis.Checked = True Then 'ugali fish selected 
     orderAmt = lab.Text 
     total = ugalif * orderAmt 
     subtotal += total 
     lstReceipt.Items.Add(orderAmt & " plates of" & " Ugali n fish " & " Kshs" & total) 
    End If 

    If chkGitheri.Checked = True Then 'ugali dengu slected 
     orderAmt = lab3.Text 
     total = ugalid * orderAmt 
     subtotal += total 
     lstReceipt.Items.Add(orderAmt & " plates of " & "Ugali n dengu " & " Kshs" & total) 
    End If 
    If chkUgaliB.Checked = True Then 'githeri selected 
     orderAmt = lab2.Text 
     total = githeri * orderAmt 
     subtotal += total 
     lstReceipt.Items.Add(orderAmt & " plates of " & "Githeri " & " Kshs" & total) 
    End If 
    If chkPilau.Checked = True Then 
     orderAmt = lab4.Text 
     total = chapo * orderAmt 
     subtotal += total 
     lstReceipt.Items.Add(orderAmt & " plates of " & "Pilau " & " Kshs" & total) 
    End If 
    If chkPizza.Checked = True Then 
     orderAmt = lab5.Text 
     total = pilau * orderAmt 
     subtotal += total 
     lstReceipt.Items.Add(orderAmt & " plates of " & "Pizza " & " Kshs" & total) 
    End If 
    If chkMandazi.Checked = True Then 
     orderAmt = lab6.Text 
     total = pizza * orderAmt 
     subtotal += total 
     lstReceipt.Items.Add(orderAmt & "mandazi " & " Kshs" & total) 
    End If 
    If chkSamosa.Checked = True Then 
     orderAmt = lab7.Text 
     total = mandazi * orderAmt 
     subtotal += total 
     lstReceipt.Items.Add(orderAmt & "Samosa " & " Kshs" & total) 
    End If 
    If chkChapon.Checked = True Then 
     orderAmt = lab8.Text 
     total = samosa * orderAmt 
     subtotal += total 
     lstReceipt.Items.Add(orderAmt & "Chapati " & " Kshs" & total) 
    End If 
    If chkWater.Checked = True And chk300ml.Checked = True Then 
     orderAmt = lab9.Text 
     total = water1 * orderAmt 
     subtotal += total 
     lstReceipt.Items.Add(orderAmt & " Bottles of 300ml Water " & " Kshs" & total) 
    End If 
    If chkWater.Checked = True And chk500ml.Checked = True Then 
     orderAmt = lab9.Text 
     total = water2 * orderAmt 
     subtotal += total 
     lstReceipt.Items.Add(orderAmt & " Bottles of 500ml Water " & " Kshs" & total) 
    ElseIf chkWater.Checked = True And chk1l.Checked = True Then 
     orderAmt = lab9.Text 
     total = water3 * orderAmt 
     subtotal += total 
     lstReceipt.Items.Add(orderAmt & " Bottles of 1l Water " & " Kshs" & total) 
    End If 
    If chkWater.Checked = True And chk2l.Checked = True Then 
     orderAmt = lab9.Text 
     total = water4 * orderAmt 
     subtotal += total 
     lstReceipt.Items.Add(orderAmt & " Bottles of 2l Water " & " Kshs" & total) 
    End If 
    If chkSoda.Checked = True And chk300ml.Checked = True Then 
     orderAmt = lab10.Text 
     total = soda1 * orderAmt 
     subtotal += total 
     lstReceipt.Items.Add(orderAmt & " Bottles of 300ml Soda " & " Kshs" & total) 
    End If 
    If chkSoda.Checked = True And chk500ml.Checked = True Then 
     orderAmt = lab10.Text 
     total = soda2 * orderAmt 
     subtotal += total 
     lstReceipt.Items.Add(orderAmt & " Bottles of 500ml Soda " & " Kshs" & total) 
    End If 
    If chkSoda.Checked = True And chk1l.Checked = True Then 
     orderAmt = lab10.Text 
     total = soda3 * orderAmt 
     subtotal += total 
     lstReceipt.Items.Add(orderAmt & " Bottles of 1l Soda " & " Kshs" & total) 
    End If 
    If chkSoda.Checked = True And chk2l.Checked = True Then 
     orderAmt = lab10.Text 
     total += soda4 * orderAmt 
     lstReceipt.Items.Add(orderAmt & " Bottles of 2l Soda " & " Kshs" & total) 
    End If 
    If chkJuice.Checked = True And chk300ml.Checked = True Then 
     orderAmt = lab11.Text 
     total = juice1 * orderAmt 
     subtotal += total 
     lstReceipt.Items.Add(orderAmt & " Bottles of 300ml juice " & " Kshs" & total) 
    End If 
    If chkJuice.Checked = True And chk500ml.Checked = True Then 
     orderAmt = lab11.Text 
     total = juice2 * orderAmt 
     subtotal += total 
     lstReceipt.Items.Add(orderAmt & " Bottles of 500ml juice " & " Kshs" & total) 
    End If 
    If chkJuice.Checked = True And chk1l.Checked = True Then 
     orderAmt = lab11.Text 
     total = juice3 * orderAmt 
     subtotal += total 
     lstReceipt.Items.Add(orderAmt & " Bottles of 1l juice " & " Kshs" & total) 
    End If 
    If chkJuice.Checked = True And chk2l.Checked = True Then 
     orderAmt = lab11.Text 
     total = juice4 * orderAmt 
     subtotal += total 
     lstReceipt.Items.Add(orderAmt & " Bottles of 2l juice " & " Kshs" & total) 
    End If 
End Sub 

시도하며 일했지만 소계 10이었다 호출 제의 경우는, 예를 들면, 계산 및 I는 computeCurrentSelection을 (호출 목적지)을 갱신하므로 부분합을 저장 이전 전체를 삭제하고, 삭제가 작동하지 않습니다이

Private Sub updateTotal() 
    lstTotal.Items.Clear() 
    lstTotal.Items.Add("Sub Total =" & subtotal) 
End Sub  

처럼 업데이트 시도 대신 previ하여 서브 총의 현재 값을 증가 계속해서 내가 프로그램을 새로 고칠 때까지. 어떻게 해결할 수 있습니까?