troubleshooting Question

VB.NET Textbox input validation

Avatar of D Patel
D PatelFlag for India asked on
.NET ProgrammingASP.NETVisual Basic.NET
4 Comments2 Solutions509 ViewsLast Modified:
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

Scenario.PNG
Thanks in advance.

Regards,
D Patel
ASKER CERTIFIED SOLUTION
Chris Jones
Lead Application Web Developer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros