从文本框中读取数据 [英] Reading data from text box
问题描述
我有2个文本框。一个文本框将读取单字节值。
I have 2 textbox. One textbox will read single byte value.
另一个文本框,它将读取2字节的十六进制值。我需要将这两个数据存储在一个字符数组中。
Another textbox which will read 2 byte hexadecimal value. i need to store both these data in a character array.
char OneValue; //
char OneValue; //
short SecondValue;
short SecondValue;
char * Data; //要存储的字符数组
char* Data; //character array to store
OneValue = Convert :: ToInt16(this-> textbox1-> Text);
OneValue=Convert::ToInt16(this->textbox1->Text);
SecondValue =转换: :ToInt16(这 - > textbox2->文字); //在这里获得异常
SecondValue=Convert::ToInt16(this->textbox2->Text); //get exception here
将其存储在字符数组中:
storing it in character array:
Data [0] = OneValue ;
Data[0]=OneValue;
但每当我输入像01C0等十六进制值(十六进制表示)时,我都会遇到异常。
but i get exception whenever i enter hexadecimal value like 01C0 etc (hex representation).
我如何解决这个?
推荐答案
您好,
请尝试以下代码。
//textbox1: 97
int data1 = System::Convert::ToInt32(this->textBox1->Text->Trim());
Char onedata = (Char)data1;
//textbox2: 01C0
int data2 = System::Convert::ToInt32(this->textBox2->Text->Trim(),16);
Char twodata = (Char)data2;
//define char array
array<Char> ^buffer = gcnew array<Char>(2);
buffer[0] = onedata;
buffer[1] = twodata;
希望这可以 对你很有帮助。
Hope this can be helpful to you.
最好的问候,
Bob
这篇关于从文本框中读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!