1

a simple question: can I set the limit for an input through an input box in vb?

When the user inserts a string larger than the database corresponding field, that's a problem obviously.

Like the textBoxes have a MaxLength, is there a way to set a similar restriction to an inputBox?

Thanks

4
  • 3
    The InputBox is a leftover from VB6 days. It is very limited in functionality. I suggest to develop your own class and reuse it. Not very difficult. Commented Dec 19, 2013 at 16:38
  • 2
    @Steve: beat me to it. Commented Dec 19, 2013 at 16:38
  • 1
    Google for custom inputbox vb.net, should get plenty of results, such as this one. Commented Dec 19, 2013 at 16:39
  • Thank you, I know it's very limited and also where it comes from. I know how to achieve what I want but I was just asking if the input box had such feature Commented Dec 19, 2013 at 16:42

1 Answer 1

2

Little easier than creating a custom class...

Instead why not create a temporary string variable and assign it by your input box. . .

then check the count in a do until loop...

EX.

 Dim str As String = InputBox("Name", [Title]:="name", [XPos]:=50, [YPos]:=50)

    Do Until str.Count() > 0 And str.Count() < 8

        MessageBox.Show("I am sorry but you need to input between 1 and 7 characters")

        str = InputBox("Name", [Title]:="name", [XPos]:=50, [YPos]:=50)

    Loop
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.