Re: how to impose numerical limits on a textbox??

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



On Oct 24, 10:19 am, we...@xxxxxxxxxx wrote:
Okay, that makes sense. However, I'm still new to VB. Can someone
please list some pseudocode to get me started?

Thanks,
-weg

I would create a class and have it inherit from textbox.
public class NumericTextBox
Inherits TextBox

Then I would define properties for the min and max value
public property MinValue as double
public property MaxValue as double

Grab a hold of the LostFocusEvent of the textbox to validate your box
public sub LostFocus ()
dim dbl as double
if Double.TryParse(me.text, dbl) then
if dbl > me.MaxValue then
me.Text = me.MaxValue.ToString()
throw exception
elseif dbl < me.MinValue then
me.Text = me.Minvalue.ToString()
throw exception
end if
else
'not a number
me.Text = me.MinValue.ToString() 'If you don't reset it you
could run into issues especially in textchanged
throw exception
end if
end sub

You can also do the above in the text changed event if you want to
validate it on every character not letting the user think they can
even input a number that big.

.



Relevant Pages

  • Re: Spell Checker
    ... I have a textbox, that he user can type some information. ... Private m_sTextCorrected As String ... Public Property Get TextCorrectedAs String ... you must add a reference to the Word object library. ...
    (microsoft.public.vb.controls)
  • User control combining TextBox and RadioButtonList
    ... All works fine, but the TextBox, on the PostBack Event, doesn't ... Public Class RadioButtonListOther: Inherits RadioButtonList ... Public Property OtherMessage() As String ... Protected Overrides Sub Render ...
    (microsoft.public.dotnet.framework.aspnet.buildingcontrols)
  • Re: SendKeys between two forms
    ... > I have a form that when you dbl click a textbox it opens ... SendKeys is buggy and inherently unreliable. ...
    (microsoft.public.access.forms)
  • Re: Passing text boxes between forms
    ... Public Property Get TextBoxIn() As Textbox ... Public Property Let TextBoxIn ... : Dim lngPos As Long ... : Dim strFind As String ...
    (microsoft.public.vb.general.discussion)
  • Re: Passing text boxes between forms
    ... >: Dim ourSearch As SearchForm ... Public Property Get TextBoxIn() As Textbox ... Public Property Let TextBoxIn ... >: Dim strFind As String ...
    (microsoft.public.vb.general.discussion)