Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Edit fields and hard returns

Status
Not open for further replies.

skim33

Programmer
Apr 7, 2003
4
US
Hi, I'm using MS Visual C++ and noticed that anytime I press Enter in an edit field (regular textbox), that counts as two characters. Reason I observe this is that in a 100-character limit edit field, I can press Enter 50 times before I can't type anymore in the field.

Is there a way to get hard returns to count as only 1 character?

 
Use your own character-limiting scheme. Handle EN_CHANGE messages, count the chars yourself and refuse the change if it is over 100.
 
Well, the heart of the problem is (1) hard returns count as two characters (2) all the text from the field gets stored into a database that specifies a max of 100 characters. (3) If the user (theoretically) types 50 hard returns and is not allowed to enter any more characters into the field, he will be wondering what the heck is going on and submit the issue for resolution.

Instead of widening the max field length in the database, I was wondering if there was a way to denote hard returns in the text field but have each return count only as 1 character. Is this an operating system dependent thing, Visual C++ nuance, or is it changeable?


 
>> Is there a way to get hard returns to count as only 1
>> character?

If you mean is there a way to get two bytes to be one byte... NO. If you just want a \n character instead of \r\n then replace all the \r\n sequences in the string with a single \n character, i guess. I don't think i understand what your trying to accomplish exactly.

-pete
 
Okay, good enough. You answered my question. I thought the hard returns were two characters with just a "\n", but I didn't know that they are stored as "\r\n" as you say. I will try looking for the "\r\n" sequence and replacing it with just a "\n". Thanks.

 
>> I thought the hard returns were two characters with just
>> a "\n"

Yeah, i see... i re-read your initial post. I somehow thought you mentioned them both but you didn't, so i confused myself again! [bugeyed]

Luckily you saw though my haze LOL
-pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top