0

I wrote following code. It's compile properly. when i enter 2 characters in to textbox at run time, it gives an error. Error is :
"String must be exactly one character long."
this is the program, I wote:

#pragma endregion
	private: System::Void btnSend_Click(System::Object^  sender, System::EventArgs^  e) {
				
				char caEntry[10];
				
				String ^ strTextBoxContent;
				strTextBoxContent = txtEntry->Text;

				caEntry[0] = strTextBoxContent[0];
				//caEntry[1] = strTextBoxContent[1];
				
				 serialPort1->Open();
				 serialPort1->Write(Convert::ToString(caEntry[0]));

				// serialPort1->Write(Convert::ToString(caEntry[1]));
				 serialPort1->Close();
			 }

I want to know how to separate the textbox content and it assign to the char array...
thank u...

Edited by roshantha08: n/a

2
Contributors
1
Reply
3
Views
7 Years
Discussion Span
Last Post by jonsca
0

You don't have to go through all this as Write() has an overload that takes a string directly. If you had to go the route you planned you can use the ToCharArray() method of the string to get the array that you need.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.