Click here to Skip to main content
15,910,083 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
How to get calculations done if a check state changes?
I am trying to do some calculations by checkstate.change event args but if i run it, it does not work.
The results is 0 whiles the results is not suppose to be 0.

This is what i have done so far:

VB
Private Sub Vehicle_Fuel_DriverCheckBox_CheckStateChanged(sender As Object, e As EventArgs) Handles Vehicle_Fuel_DriverCheckBox.CheckStateChanged
    Try
        If Vehicle_Fuel_DriverCheckBox.CheckState = True Then
            Dim TotalCashEmoluments As Integer
            Dim VFDLmt As Integer
            Dim VHF As Integer
            Dim TotalVHF As Integer
            ' Calculating VFD

            VHF = TotalCashEmoluments * 0.125

            'Checking and deducting with limits
            If VHF = VFDLmt Then
                TotalVHF = VFDLmt
            End If

            If VHF > VFDLmt Then
                TotalVHF = VFDLmt
            End If

            If VHF < VFDLmt Then
                TotalVHF = VFDLmt + 0
            End If
        End If
    Catch ex As Exception
        MessageBox.Show(ex.StackTrace, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
    End Try
End Sub
Posted
Updated 4-Nov-15 0:00am
v2

1 solution

When you do

VB
VHF = TotalCashEmoluments * 0.125


your variable TotalCashEmolument is not initialized at all!
That means in VB.NET that it is 0. That is why your result is 0 as well!
 
Share this answer
 
v3
Comments
Masta Pee 4-Nov-15 6:28am    
yes please so what do i do about it now
Leo Chapiro 4-Nov-15 7:19am    
You need to assign a value to this variable, it depends on what you want to calculate ...
Masta Pee 4-Nov-15 7:29am    
okay i have modified it like this now..
Private Sub FuelOnlyCheckBox_CheckStateChanged(sender As Object, e As EventArgs) Handles FuelOnlyCheckBox.CheckStateChanged

Try
If FuelOnlyCheckBox.CheckState = True Then

Dim TotalCashEmolumentsint As Integer
Dim FOLmtint As Integer
Dim VHFint As Integer
Dim TotalVHFint As Integer

TotalCashEmolumentsint = Val(TotalCashEmoluments.Text)
TotalVHFint = Val(TotalVHF.Text)
VHFint = Val(VHF.Text)
FOLmtint = Val(VFDLmt.Text)

' Calculating FO

VHFint = TotalCashEmolumentsint * 0.05

'Checking and deducting with limits
If VHFint = FOLmtint Then
TotalVHF = FOLmt
End If

If VHFint > FOLmtint Then
TotalVHF = FOLmt
End If

If VHFint < FOLmtint Then
TotalVHFint = VHFint + 0
End If
End If
Catch ex As Exception
MessageBox.Show(ex.StackTrace, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Leo Chapiro 4-Nov-15 8:13am    
It looks very good now, does it work as you want it to?
Masta Pee 4-Nov-15 8:22am    
it is still given 0 as a the answer... i have a deadline to present this project at school... please i really need help i must pass this exam... please.. if you want i can send you the source code the when u look at it you will be able to help me better please

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900