Avatar of D Patel
D Patel
Flag for India asked on

VB.NET Textbox input validation

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
Visual Basic.NET.NET ProgrammingASP.NET

Avatar of undefined
Last Comment
D Patel

8/22/2022 - Mon
SOLUTION
Shalu M

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER CERTIFIED SOLUTION
Chris Jones

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
D Patel

ASKER
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 Patel

ASKER
By the way, thanks for your warm support.

Your solution has resolved my issue.

Regards,
D Patel
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck