Click to See Complete Forum and Search --> : Shortening or removing text from textbox->Text string
Alicat
July 10th, 2006, 06:39 PM
Can anybody tell me how to remove characters from the Textbox->Text string.
I'm receiving character from a serial port, reading a line into wchar_t cValue, then using the following code to append the data to a textbox for display, I'm not sure how much text I can actually append using this method so I want to be able to resize the Text string:
this->TRK_RECEIVEDATA_tbox->AppendText(String::Format("{0}", cValue));
Using this code the string is getting too large. I want to be able to limit it to 4096 characters. I've searched and tried these commands (after string grows to 8192 characters) but they don't seem to do anything.
this->TRK_RECEIVEDATA_tbox->Text->TrimStart(4096);
this->TRK_RECEIVEDATA_tbox->Text->Remove(0,4096);
Any help is appreciated.
ThermoSight
July 10th, 2006, 08:57 PM
Hello again, Alicat. I hope your recent business trip was profitable.
You may be mixing StringBuilder and String methods in the examples shown above, but one thing struck me about the examples you gave, and the comment you made.
You say that the methods didn't seem to have any effect. Well, the TrimStart method probably won't, or at least not a huge effect, but the remove certainly should EXCEPT THAT you don't seem to be doing anything with the output of the Remove method.
I believe that the Remove method is in fact removing the first 4096 chars, but you won't see it in the input String *.
I seem to recall that strings are immutable, meaning that the string pointer you present to the Remove method will not change as you have coded it. Rather, the Remove method returns a new String *, (an entirely new String) which is copy of the input string EXCEPT that the first 4096 chars have been removed per your instructions. But you don't seem to be doing anything with the String * Remove is returning.
If I were you, I'd try the following line
TRK_RECEIVEDATA_tbox->Text = TRK_RECEIVEDATA_tbox->Text->Remove(0,4096);
I dunno if it'll work or not, but it's worth a try.
bill
Alicat
July 10th, 2006, 10:35 PM
Thx Thermosight
As usual your suggestion worked though slightly modified.
TRK_RECEIVEDATA_tbox->Text::Set(TRK_RECEIVEDATA_tbox->Text->Remove(0,4096));
This new managed code way of programming is great for beginners but I still need to learn the basics. Right now my code has progress quite a bit but I'm not sure if I'm fighting a Microsoft bug or a problem with my code. I'm reading information line by line from the serial port and it seems to work OK for the most part but it occassionally crashes asking to send information to Microsoft. I thought I was exceeding the string length limit for the Textbox->Text length. It's still happening even though the above code is keeping it below 16384 bytes.
if (TRK_RECEIVEDATA_tbox->Text->Length::get() > 16384) {
TRK_RECEIVEDATA_tbox->Text::set(this->TRK_RECEIVEDATA_tbox->Text->Remove(0,4096));
TRK_DISTANCE->Text::set(String::Format("Status : !!!Warning!! {0} Chr$ in buffer",this->TRK_RECEIVEDATA_tbox->Text->Length::get()));
}
ThermoSight
July 11th, 2006, 01:36 PM
Hi Alicat.
I think the statement differences are due in large part to the different environments we work in. I'm using VS2003. You're using 2005, aren't you?
It seems to me that .NET is so powerful that pretty soon, programmers won't be needed at all. I'm certain that .NET v4.0 will come with a microphone. Users will merely speak into the microphone, describing the program they want and, after a moment or two, a floppy will emerge from the base of the microphone with the specified executable compiled and ready to go.
As it is now, programmers are only marginally required ..... Microsoft has done all the heavy lifting - we programmers need only snap the pieces into place to get the program we want.
Best wishes,
bill
Dave Anderson
July 12th, 2006, 07:36 PM
It seems to me that .NET is so powerful that pretty soon, programmers won't be needed at all. I'm certain that .NET v4.0 will come with a microphone. Users will merely speak into the microphone, describing the program they want and, after a moment or two, a floppy will emerge from the base of the microphone with the specified executable compiled and ready to go.
=======================================================
A little overboard there on the "imagination of programming". That will NEVER happen ANY time soon.
lol.
ThermoSight
July 13th, 2006, 12:34 AM
Hi Dave!
Yeah, you may be right. Years ago when I was one of the Founding Partners of TekSci (www.teksci.com), we had a logo in the early years ... a cartoon featuring a PC with arms extending out from the monitor, tapping out code on the keyboard.
In many ways, Microsoft's .NET reminds me very much of that cartoon/logo.
.NET is **such** a powerful tool that programmers really don't need to know very much about computer science .... about bits and bytes, protocols or structures. They just need to know how to snap the .NET pieces into place. Microsoft has done all the heavy lifting.
Of course, this is merely natural progression. More years ago than I care to admit to, I was drawing contours of the ocean floor on a Houston plotter. It was necessary then to know Bresenham's algorithm. My guess is that most young people today don't have a clue about Bresenham, or how to draw a digit '0' on a plotter ..... they just use the tools the manufacturer has provided. They send the plotter a String and let the plotter figure out how to draw the '0' (or the contour).
Nowadays those tools cover such diverse areas as TCP/IP, RSA, Hashing, MSMQ ..... a programmer doesn't need to know anything about those subjects except how to spell the appropriate class name. As mentioned earlier, Microsoft has done all the heavy lifting.
Hence the natural progression to not even knowing how to spell the names, just speak into the microphone and let Microsoft know what kinda program you want. I'll look for that feature in .NET v 4.0 (tongue-in-cheek).
My hat is off to Microsoft .... they've put out one HELL of a product! And all for a mere $110 at CompUSA. Getting a better deal than that on any product, anywhere requires a gun and a mask.
Best wishes, and thanks for your comment.
bill
Alicat
July 13th, 2006, 07:33 AM
Actually, It cost me $0. I'm using Visual C++ Express edition which is free to download.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.