2016-04-10 22 views
0

Tamamen kodlamak yeni. Erişimdeki bir buton tıklatmasının her biri bağımsız olarak değişken olan ve sürecin neden başarısız olduğuna dair hiçbir fikri olmayan 6 alanı bir araya getirdiği bir olay prosedürü oluşturmaya çalışıyorum. Olay yordamına bağlı Access'te hesapla kutusunu tıklattığımda bir hata bile almıyorum. İşte şimdiye kadar sahip olduğum şey.VB.net Access in Calculator

Opsiyon Veritabanı

Private Sub CalculateButton_Click() 

    Dim TotalIncomeAmt As Integer 
    Dim TotalSocialSecurityIncomeAmt As Integer 
    Dim TotalSocialSecurityBenefitAmt As Integer 
    Dim TotalChildSupportAmt As Integer 
    Dim TotalFoodStampAmt As Integer 
    Dim TotalOtherIncomeAmt As Integer 
    Dim GrandTotalIncome As Integer 

    If IFW - How_often_received = "Weekly" Then 
     TotalIncomeAmt = IFW_Amount * 4.25 
    End If 
    If IFW - How_often_received = "Bi-Monthly" Then 
     TotalIncomeAmt = IFW_Amount * 2 
    End If 
    If IFW - How_often_received = "Monthly" Then 
     TotalIncomeAmt = IFW_Amount 
    End If 
    If IFW - How_often_received = " " Then 
     TotalIncomeAmt = 0 
    End If 

    If SSI - How_often_received = "Weekly" Then 
     TotalSocialSecurityIncomeAmt = SSI_Amount * 4.25 
    End If 
    If SSI - How_often_received = "Bi-Monthly" Then 
     TotalSocialSecurityIncomeAmt = SSI_Amount * 2 
    End If 
    If SSI - How_often_received = "Monthly" Then 
     TotalSocialSecurityIncomeAmt = SSI_Amount 
    End If 
    If SSI - How_often_received = " " Then 
     TotalSocialSecurityIncomeAmt = 0 
    End If 

    If SSB - How_often_received = "Weekly" Then 
     TotalSocialSecurityBenefitAmt = SSB_Amount * 4.25 
    End If 
    If SSI - How_often_received = "Bi-Monthly" Then 
     TotalSocialSecurityBenefitAmt = SSB_Amount * 2 
    End If 
    If SSI - How_often_received = "Monthly" Then 
     TotalSocialSecurityBenefitAmt = SSB_Amount 
    End If 
    If SSI - How_often_received = " " Then 
     TotalSocialSecurityBenefitAmt = 0 
    End If 

    If CH - How_often_received = "Weekly" Then 
     TotalChildSupportAmt = CH_Amount * 4.25 
    End If 
    If CH - How_often_received = "Bi-Monthly" Then 
     TotalChildSupportAmt = CH_Amount * 2 
    End If 
    If CH - How_often_received = "Monthly" Then 
     TotalChildSupportAmt = CH_Amount 
    End If 
    If CH - How_often_receive_benefits = " " Then 
     TotalChildSupportAmt = 0 
    End If 

    If FS - How_often_received = "Weekly" Then 
     TotalFoodStampAmt = FS_Dollar_Amount * 4.25 
    End If 
    If FS - How_often_received = "Bi-Monthly" Then 
     TotalFoodStampAmt = FS_Dollar_Amount * 2 
    End If 
    If FS - How_often_received = "Monthly" Then 
     TotalFoodStampAmt = FS_Dollar_Amount 
    End If 
    If FS - How_often_received = " " Then 
     TotalFoodStampAmt = 0 
    End If 

    If OI - How_often_received = "Weekly" Then 
     TotalOtherIncomeAmt = OI_Amount * 4.25 
    End If 
    If OI - How_often_received = "Bi-Monthly" Then 
     TotalOtherIncomeAmt = OI_Amount * 2 
    End If 
    If OI - How_often_received = "Monthly" Then 
     TotalOtherIncomeAmt = OI_Amount 
    End If 
    If OI - How_often_received = "None" Then 
     TotalOtherIncomeAmt = 0 
    End If 

    GrandTotalIncome = (TotalIncomeAmt + TotalBenefitsAmt + TotalFoodStampAmt + TotalChildSupportAmt + TotalOtherIncomeAmt) 
    Total_Monthly_Income = GrandTotalIncome 
End Sub 
+0

haftalık hesaplama '0.25' ile yapılabilir olmamalı:

Dim GrandTotalIncome As Currency Dim Factor As Currency 

O zaman bu gibi tüm kod blokları revize ? –

+3

bu ne anlama geliyor IFW - How_often_received = "Weekly" '??? Okuduğum şey: 'HowWen' 'HowWert' 'ifadesinden' 'IFW' 'i çıkarmak ve sonucu' Weekly 'dizesiyle karşılaştır. Bunun benim için bir anlamı yok. Bunu her yerdesin. –

+0

@ThomasG'nin revize edilmesine ihtiyaç duyulan ilk şey olduğunu belirtti. Yeniden değerlendirmek isteyebileceğiniz ikinci şey, çoklu koşulların doğru olabileceği ihtimalidir. Eğer durum buysa, değiştirmek istediğiniz: 'TotalIncomeAmt = IFW_Amount * 4.25' -' TotalIncomeAmt = TotalIncomeAmt + (IFW_Amount * 4.25) ' –

cevap

0

İlk karşılaştırın:

Dim TotalIncomeAmt As Currency ' To hold decimals 
' Also, IFW_Amount must be Currency. 


Select Case [IFW - How_often_received] 
    Case "Weekly" 
     Factor = 4.25 
    Case "Bi-Monthly" 
     Factor = 2 
    Case "Monthly" 
     Factor = 1 
    Case Else 
     Factor = 0 
End Select 
TotalIncomeAmt = IFW_Amount * Factor