Click here to Skip to main content
15,912,897 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
if (textBox1.Text.Length == 7)
            {
                string x=textbox1.Text;
                textBox1.Clear();
                MessageBox.Show(x);
            }

How can I use this code for non fixed length ?
Posted
Updated 19-Apr-11 0:55am
v2
Comments
Tarun.K.S 19-Apr-11 6:55am    
Question is unclear. Please elaborate.
Sunasara Imdadhusen 19-Apr-11 6:56am    
Not clear!!
Abhinav S 19-Apr-11 7:48am    
Non-fixed length of what?
Sergey Alexandrovich Kryukov 19-Apr-11 13:35pm    
Did you remove this question after you got some answers:
http://www.codeproject.com/Answers/183826/How-can-I-check-if-an-event-has-fired-or-not.aspx
--SA
Mohammed Ahmed Gouda 20-Apr-11 4:08am    
no i didnt delete any of my questions

just remove this line

if (textBox1.Text.Length == 7)


and MessageBox will be shown for any length of (textBox1.Text)
 
Share this answer
 
Use App.config to assign the value for non fixed length
XML
<configuration>
<appSettings>
<add key ="MaxLength" value = "7"/>
</appSettings>
</configuration>


Fetch the value using the following code
int maxLength = ConfigurationSettings.AppSettings [ "MaxLength" ] ;


Use it in functionality
C#
if (textBox1.Text.Length == maxLength)
{
         string x=textbox1.Text;
         textBox1.Clear();
         MessageBox.Show(x);
}


Post back for more queries :)

Rgds / GV
 
Share this answer
 
v2
Please check following

C#
int MaxLength = 7;
if (textBox1.Text.Length == MaxLength )
 
Share this answer
 
Comments
Ashish Tyagi 40 11-Jul-11 23:46pm    
I guess we both solved his problem Ha ha ha :-)... Here is my 5

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