How can i limit a txt value between 1->25 and return an error msg if the value was...

Beginner

Well-known member
Joined
Mar 12, 2008
Messages
114
Programming Experience
Beginner
How can i limit a txt value between 1->25 and return an error msg if the value was...

VB.NET:
        Dim PresureA As Integer
        If (pa.Text > 25) Then
            pa.Text = 25
            PresureA = MsgBox("Pressure angle cannot exceed 25!", vbExclamation, "Error!")
        End If
        If (pa.Text < 0) Then
            pa.Text = 0
            PresureA = MsgBox("Pressure angle cannot be less than zero!", vbExclamation, "Error!")
        End If

The only problem now is when i enter a negative number the program fails.

minusgt4.jpg


Edit:Under these circumstances, if the user entered the number -27,
the control wouldn't accept it because the beginning dash isn't
a number
 
Last edited:
I am not sure I agree with using a NUD. This is fine on values between 1-25, but if something changes to where the values are 1 and 2000, then it is not a great solution.
Values of 1 and 2000 are discrete choices that are best served by a RadioButton. Discrete choices of 5 options, up to 20 options are best suited to a combo box, and beyond 20 youre starting to commit HCI foolishness.

If you mean a range between 1 and 2000, then a NUD is still the best option. You might want to set the increment to soemthing sensible like 100 though, depending on the context

Now, back to my original post.
Of using the wrong controls for the task at hand? If you have to drive a nail in, use a hammer, not the back end of a wrench ;)

Can I suggest you take a passing interest in the topic of HCI too? :p
 
To go even further, with NUD's you don't have to use the Text property at all. To "clear" the NUD set the Value property equal to zero (0D) and it'll reset, even if the minimum has to be higher than 0 (if you set it to zero, it'll actually set it to whatever the minimum allowed is)

showthread.php


Values of 1 and 2000 are discrete choices that are best served by a RadioButton. Discrete choices of 5 options, up to 20 options are best suited to a combo box, and beyond 20 youre starting to commit HCI foolishness.

If you mean a range between 1 and 2000, then a NUD is still the best option. You might want to set the increment to soemthing sensible like 100 though, depending on the context


Of using the wrong controls for the task at hand? If you have to drive a nail in, use a hammer, not the back end of a wrench ;)

Can I suggest you take a passing interest in the topic of HCI too? :p


As long as things are done and being taken care off. I guess no need for me to grab a book and read. I believe there is no chapter about the NUD using a .text command to clear the value. :D. So best way to learn is by trying and asking. Anyways thanks for your suggestion , i'll take it into deep consideration ;).
 
Back
Top