Click here to Skip to main content
15,904,153 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
How do I write a textbox statement that takes the first 50 characters and discards the rest?
VB
User = TextBox1.Text.Substring(0, 50)

Error Code:
Index and length must refer to a location within the string.
Parameter name: length
Posted
Comments
[no name] 1-Jul-14 17:02pm    
It would be the exact same way that you have already been told. http://www.codeproject.com/Questions/790293/How-do-I-limit-the-data-to-the-first-characters?arn=0
Sergey Alexandrovich Kryukov 1-Jul-14 19:58pm    
Unbelievable. And this is after 25 questions (and I'm sure even more questions was auto-removed for abuse). I just warned OP that it goes nowhere. We are just wasting time; no help is actually used.
—SA

1 solution

Before finding a substring, check up if the original string (TextBox1.Text) length is already less or equal to the required length.
You could figure out this by thinking just a bit, reading original help page or simplest experiment. If you are going to ask such question on each simple problem, you will never become even the beginner. You need to begin.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900