We help IT Professionals succeed at work.

VB.NET Textbox input validation

488 Views
Last Modified: 2017-03-08
Hi Experts,

I have self designed a webpage .aspx (VB.NET).

It has the label (6 different fields) and textbox (1 field) controls.

I need to validate the text field as user inputs the value.

Conditions :
1. Net weight value should not exceed the balance quantity
2. Net weight value should not cross the order quantity limit (i.e. suppose ordered quantity is 100 and tolerance is 10% (+/-) then net weight field could accept the value between 90 and 110 otherwise alert should be popup.)
3. net weight should be in range between minimum and maximum weight. (respective of order quantity, balance quantity and tolerances)

Scenario :

Suppose,
Order Quantity is 2.500 Ton and tolerance (+/-) is 10%,
So the system should allow me to input net weight in range of 2.250 Ton and 2.750 Ton
if its value crosses that limit then system should prevent.

Now, out to 2.500 Ton some quantity (say 0.500 Ton) is picked. So the balance quantity will be 2.000 Ton. In this case also system will check the net weight value. If it crosses the limit system should prevent.

Accordingly, Minimum Weight and Maximum Weight is 0.500 - 0.600. This means per entry user can enter the value between 0.500 to 0.600 Ton. So, here also net weight field needs validation.

I have written the condition but it's not successful. Can anyone help me out so that I can apply successful validation on Net Weight field?

Please find my VB.NET code and scenario's for your kind reference.

If txtWeight.Text <> "" Then
                If (Val(txtWeight.Text) > Val(txtBalQty.Text)) Then
                    If Not ((Val(txtWeight.Text) >= (lblMinWeightBundle.Text - 0.01)) And (Val(txtWeight.Text) <= (lblMaxWeightBundle.Text + 0.03))) Then
                        MsgBox("Bundle Weight should be Minimum :" & (Val(lblMinWeightBundle.Text) - 0.01) & " Ton and Maximum : " & (Val(lblMaxWeightBundle.Text) + 0.03) & " Ton!!!")
                        txtWeight.Focus()
                        txtWeight.Text = ""
                    Else
                        If (Val(txtWeight.Text) >= (ordqty.text + (ordqty.text / 100) * lblQtyPluse.Text)) Then
                            MsgBox("Please Enter valid Weight as per the tolerance!!! Max :" & (ordqty.text + (ordqty.text / 100) * lblQtyPluse.Text) & " Ton" & vbCrLf & "Also Check Balance Quantity :" & txtBalQty.Text & "")
                            txtWeight.Focus()
                            txtWeight.Text = ""
                        End If
                    End If
                Else
                    If Not ((Val(txtWeight.Text) >= (lblMinWeightBundle.Text - 0.01)) And (Val(txtWeight.Text) <= (lblMaxWeightBundle.Text + 0.03))) Then
                        MsgBox("Bundle Weight should be Minimum :" & (Val(lblMinWeightBundle.Text) - 0.01) & " Ton and Maximum : " & (Val(lblMaxWeightBundle.Text) + 0.03) & " Ton!!!")
                        txtWeight.Focus()
                        txtWeight.Text = ""
                    Else
                        If (Val(txtWeight.Text) <= (ordqty.text - (ordqty.text / 100) * lblQtyMinus.Text)) Then
                            MsgBox("Please Enter valid Weight as per the tolerance!!! Min :" & (ordqty.text - (ordqty.text / 100) * lblQtyMinus.Text) & " Ton" & vbCrLf & "Also Check Balance Quantity :" & txtBalQty.Text & "")
                            txtWeight.Focus()
                            txtWeight.Text = ""
                        End If
                    End If
                End If
            End If

Open in new window


Scenario.PNG
Thanks in advance.

Regards,
D Patel
Comment
Watch Question

Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
Lead Application Web Developer
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION
D PatelD Patel, Software Engineer

Author

Commented:
Hi Experts,

my code is working fine, also there is no error.

Only issue is in my logic (which is posted in my question).

In addition, all conditions will be satisfied at a time then and only then net weight is accepted.

Scenario.PNGPlease suggest if any solution.

Regards,
D Patel
D PatelD Patel, Software Engineer

Author

Commented:
By the way, thanks for your warm support.

Your solution has resolved my issue.

Regards,
D Patel