As Christian Graus says "It's ugly" and almost impossible to determine what, if anything is wrong with the logic.
Try the following steps to make this easier to read and for you to debug ...
1. TotalBuild, TotalElv, TotalEsc, TotalTrav are already Dim As Integer so there is no need to use Val(TotalBuild), Val(TotalElv), Val(TotalEsc), Val(TotalTrav) !! Get rid of the Val() surrounds.
2. I personally strongly dislike code that either disappears off to the right of the screen so I have to keep scrolling, or wraps around when pasted into CP. To address this consider doing all of the
Val(txtTextBoxName.Text)
stuff outside of your validation section. E.g.
Dim NoOfBuilding As Integer = Val(TxtNoOfBuilding.Text)
Dim NoOfBuildingGrp As Integer = Val(TxtNoOfBuildingGrp.Text)
Dim TotalElevator As Integer = Val(TxtTotalElevator.Text)
Dim TotalTravelator As Integer = Val(TxtTotalTravelator.Text)
Dim BulNoofEscalator As Integer = Val(TxtBulNoofEscalator.Text)
Dim BulNoofEle As Integer = Val(TxtBulNoofEle.Text)
Dim TotalEscalator As Integer = Val(TxtTotalEscalator.Text)
Dim BulNoOfTravelator As Integer = Val(TxtBulNoOfTravelator.Text)
Then replace all the remaining instances of
Val(TxtNoOfBuilding.Text)
with
NoOfBuilding
etc
3. I also like to break down interim "calculations" - it means I can very quickly and easily check them during debugging without having to highlight partial lines of code (yes! I am a bit lazy like that!), so I would pull out some more stuff like this ...
Dim tElev As Integer = TotalElv + BulNoofEle
Dim tEsc As Integer = TotalEsc + BulNoofEscalator
Dim tTrav As Integer = TotalTrav + BulNoOfTravelator
Dim tBuild As Integer = TotalBuild + NoOfBuildingGrp
Dim bElevators As Boolean = (TotalElevator = tElev And TotalEscalator = tEsc And TotalTravelator = tTrav)
4. Your two tests could be combined as they produce the same results. But more importantly the following tests could overwrite anything that you have already put into lblTowerStatus. For example if you enter 0 for the number of buildings and also enter too many Elevators then the error message will read "Total number of elevator exceeded" instead of "Not allow zero". There are a couple of ways to address this... you could use
ElseIf
or a helper function similar to this
Private Sub Helper(ByVal text As String)
If lblTowerStatus.Text.Length = 0 Then
lblTowerStatus.Text = text
End If
End Sub
This also has the advantage that if you change the way you report errors you only have to change one line of code.
So your tests finally become
If NoOfBuilding = 0 Or NoOfBuildingGrp = 0 Then
Helper("Not Allow Zero")
ElseIf TotalBuild > NoOfBuilding Then
Helper("Can't exceed Total Number Of Building")
ElseIf tElev > TotalElevator Then
Helper("Total Number of Elevator exceeded")
ElseIf tEsc > TotalEscalator Then
Helper("Total Number of Escalator exceeded")
ElseIf tTrav > TotalTravelator Then
Helper("Total Number of Travellator exceeded")
ElseIf (NoOfBuilding = tBuild And bElevators = False) Or (NoOfBuilding <> tBuild And bElevators = True) Then
Helper("Total Number of Elevator not utilized")
ElseIf NoOfBuilding <> tBuild And bElevators = True Then
Helper("Total Number of Building not utilized")
End If
NB I tested for bElevators = True and bElevators = False for clarity. You should really just use If bElevators ... Then or If Not bElevators ...Then
It should now be easier to see if the logic is what you actually intended and certainly easier to debug