Jump to content




Recent Status Updates

  • Photo
      18 Aug
    KodeKool

    When faced with a wall of errors and no hope to fix them, remember the following "Programs always do what you tell them to, and seldom what you want them to, but eventually you'll run out of things that can go wrong and it'll just work. and that's the secret to good programming."

    Show comments (2)
  • Photo
      11 Aug
    Error

    Should I be practicing programming every day? I feel if I don't, I'll get instantly rusty or something.

    Show comments (4)
View All Updates

Developed by Kemal Taskin
Photo
- - - - -

Doesn't read from textbox and write to it correctly

Managed C++ write to

  • Please log in to reply
2 replies to this topic

#1 Gnomer

Gnomer

    CC Lurker

  • Just Joined
  • Pip
  • 4 posts

Posted 12 October 2011 - 12:12 PM

I write a letter or number to texbox. When I press button it's must to add element from textbox to list. But when I want to show my array in textbox it returns numbers instead of letters. And I don't know why. Here my form code. All methods from class Arraylist(my own class) work correctly.(I tested it in console app.)

#pragma once
#include "stdafx.h"
#include "ATD.h"
namespace Lab3formm {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for Form1
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
	     Arraylist *x;
		Arraylist *y;
		Form1(void)
		{
			InitializeComponent();
			//
			x=new Arraylist();
			y=new Arraylist();
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Label^  label1;
	protected: 
	private: System::Windows::Forms::Label^  label2;
	private: System::Windows::Forms::Button^  button1;
	private: System::Windows::Forms::Button^  button2;
	private: System::Windows::Forms::TextBox^  textBox1;
	private: System::Windows::Forms::TextBox^  textBox2;
	private: System::Windows::Forms::Button^  button3;
	private: System::Windows::Forms::TextBox^  textBox3;
	private: System::Windows::Forms::TextBox^  textBox4;
	private: System::Windows::Forms::Button^  button4;
	private: System::Windows::Forms::TextBox^  textBox5;
	private: System::Windows::Forms::Button^  button5;
	private: System::Windows::Forms::TextBox^  textBox6;
	private: System::Windows::Forms::Button^  button6;
	private: System::Windows::Forms::Button^  button7;
	private: System::Windows::Forms::TextBox^  textBox7;

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
		    this->label1 = (gcnew System::Windows::Forms::Label());
		    this->label2 = (gcnew System::Windows::Forms::Label());
		    this->button1 = (gcnew System::Windows::Forms::Button());
		    this->button2 = (gcnew System::Windows::Forms::Button());
		    this->textBox1 = (gcnew System::Windows::Forms::TextBox());
		    this->textBox2 = (gcnew System::Windows::Forms::TextBox());
		    this->button3 = (gcnew System::Windows::Forms::Button());
		    this->textBox3 = (gcnew System::Windows::Forms::TextBox());
		    this->textBox4 = (gcnew System::Windows::Forms::TextBox());
		    this->button4 = (gcnew System::Windows::Forms::Button());
		    this->textBox5 = (gcnew System::Windows::Forms::TextBox());
		    this->button5 = (gcnew System::Windows::Forms::Button());
		    this->textBox6 = (gcnew System::Windows::Forms::TextBox());
		    this->button6 = (gcnew System::Windows::Forms::Button());
		    this->button7 = (gcnew System::Windows::Forms::Button());
		    this->textBox7 = (gcnew System::Windows::Forms::TextBox());
		    this->SuspendLayout();
		    // 
		    // label1
		    // 
		    this->label1->AutoSize = true;
		    this->label1->Location = System::Drawing::Point(40, 13);
		    this->label1->Name = L"label1";
		    this->label1->Size = System::Drawing::Size(35, 13);
		    this->label1->TabIndex = 0;
		    this->label1->Text = L"label1";
		    // 
		    // label2
		    // 
		    this->label2->AutoSize = true;
		    this->label2->Location = System::Drawing::Point(152, 13);
		    this->label2->Name = L"label2";
		    this->label2->Size = System::Drawing::Size(35, 13);
		    this->label2->TabIndex = 1;
		    this->label2->Text = L"label2";
		    // 
		    // button1
		    // 
		    this->button1->Location = System::Drawing::Point(12, 62);
		    this->button1->Name = L"button1";
		    this->button1->Size = System::Drawing::Size(101, 23);
		    this->button1->TabIndex = 2;
		    this->button1->Text = L"add1";
		    this->button1->UseVisualStyleBackColor = true;
		    this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
		    // 
		    // button2
		    // 
		    this->button2->Location = System::Drawing::Point(119, 62);
		    this->button2->Name = L"button2";
		    this->button2->Size = System::Drawing::Size(100, 23);
		    this->button2->TabIndex = 3;
		    this->button2->Text = L"add2";
		    this->button2->UseVisualStyleBackColor = true;
		    this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
		    // 
		    // textBox1
		    // 
		    this->textBox1->Location = System::Drawing::Point(13, 36);
		    this->textBox1->Name = L"textBox1";
		    this->textBox1->Size = System::Drawing::Size(100, 20);
		    this->textBox1->TabIndex = 4;
		    // 
		    // textBox2
		    // 
		    this->textBox2->Location = System::Drawing::Point(119, 36);
		    this->textBox2->Name = L"textBox2";
		    this->textBox2->Size = System::Drawing::Size(100, 20);
		    this->textBox2->TabIndex = 5;
		    // 
		    // button3
		    // 
		    this->button3->Location = System::Drawing::Point(12, 93);
		    this->button3->Name = L"button3";
		    this->button3->Size = System::Drawing::Size(101, 20);
		    this->button3->TabIndex = 6;
		    this->button3->Text = L"view1";
		    this->button3->UseVisualStyleBackColor = true;
		    this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
		    // 
		    // textBox3
		    // 
		    this->textBox3->Location = System::Drawing::Point(119, 93);
		    this->textBox3->Name = L"textBox3";
		    this->textBox3->Size = System::Drawing::Size(206, 20);
		    this->textBox3->TabIndex = 7;
		    // 
		    // textBox4
		    // 
		    this->textBox4->Location = System::Drawing::Point(119, 122);
		    this->textBox4->Name = L"textBox4";
		    this->textBox4->Size = System::Drawing::Size(207, 20);
		    this->textBox4->TabIndex = 8;
		    // 
		    // button4
		    // 
		    this->button4->Location = System::Drawing::Point(13, 120);
		    this->button4->Name = L"button4";
		    this->button4->Size = System::Drawing::Size(99, 22);
		    this->button4->TabIndex = 9;
		    this->button4->Text = L"view2";
		    this->button4->UseVisualStyleBackColor = true;
		    this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click);
		    // 
		    // textBox5
		    // 
		    this->textBox5->Location = System::Drawing::Point(226, 36);
		    this->textBox5->Name = L"textBox5";
		    this->textBox5->Size = System::Drawing::Size(100, 20);
		    this->textBox5->TabIndex = 10;
		    // 
		    // button5
		    // 
		    this->button5->Location = System::Drawing::Point(226, 62);
		    this->button5->Name = L"button5";
		    this->button5->Size = System::Drawing::Size(99, 23);
		    this->button5->TabIndex = 11;
		    this->button5->Text = L"a==b";
		    this->button5->UseVisualStyleBackColor = true;
		    this->button5->Click += gcnew System::EventHandler(this, &Form1::button5_Click);
		    // 
		    // textBox6
		    // 
		    this->textBox6->Location = System::Drawing::Point(120, 148);
		    this->textBox6->Name = L"textBox6";
		    this->textBox6->Size = System::Drawing::Size(206, 20);
		    this->textBox6->TabIndex = 12;
		    // 
		    // button6
		    // 
		    this->button6->Location = System::Drawing::Point(12, 146);
		    this->button6->Name = L"button6";
		    this->button6->Size = System::Drawing::Size(99, 22);
		    this->button6->TabIndex = 13;
		    this->button6->Text = L"a+b";
		    this->button6->UseVisualStyleBackColor = true;
		    this->button6->Click += gcnew System::EventHandler(this, &Form1::button6_Click);
		    // 
		    // button7
		    // 
		    this->button7->Location = System::Drawing::Point(12, 175);
		    this->button7->Name = L"button7";
		    this->button7->Size = System::Drawing::Size(99, 21);
		    this->button7->TabIndex = 14;
		    this->button7->Text = L"a--";
		    this->button7->UseVisualStyleBackColor = true;
		    this->button7->Click += gcnew System::EventHandler(this, &Form1::button7_Click);
		    // 
		    // textBox7
		    // 
		    this->textBox7->Location = System::Drawing::Point(120, 175);
		    this->textBox7->Name = L"textBox7";
		    this->textBox7->Size = System::Drawing::Size(206, 20);
		    this->textBox7->TabIndex = 15;
		    // 
		    // Form1
		    // 
		    this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
		    this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
		    this->ClientSize = System::Drawing::Size(334, 206);
		    this->Controls->Add(this->textBox7);
		    this->Controls->Add(this->button7);
		    this->Controls->Add(this->button6);
		    this->Controls->Add(this->textBox6);
		    this->Controls->Add(this->button5);
		    this->Controls->Add(this->textBox5);
		    this->Controls->Add(this->button4);
		    this->Controls->Add(this->textBox4);
		    this->Controls->Add(this->textBox3);
		    this->Controls->Add(this->button3);
		    this->Controls->Add(this->textBox2);
		    this->Controls->Add(this->textBox1);
		    this->Controls->Add(this->button2);
		    this->Controls->Add(this->button1);
		    this->Controls->Add(this->label2);
		    this->Controls->Add(this->label1);
		    this->Name = L"Form1";
		    this->Text = L"Form1";
		    this->ResumeLayout(false);
		    this->PerformLayout();

		}
#pragma endregion
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
			 x->Add(char::Parse(textBox1->Text));
		    }
private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {
		   y->Add(char::Parse(textBox2->Text));
	    }
private: System::Void button5_Click(System::Object^  sender, System::EventArgs^  e) {
		  if (x==y) textBox5->Text="True"; else textBox5->Text="False";
	    }
private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) {
		   System::String^ s="";
		   for(int i=0;i<x->GetElemsCount();i++)
			  {s+=x->GetElemInd(i);
		   s+=" ";}
		  textBox3->Text=s;
	    }
private: System::Void button4_Click(System::Object^  sender, System::EventArgs^  e) {
		   System::String^ s="";
		   for(int i=0;i<y->GetElemsCount();i++)
			  {s+=y->GetElemInd(i);
		   s+=" ";}
		  textBox4->Text=s;
	    }
private: System::Void button6_Click(System::Object^  sender, System::EventArgs^  e) {
		   Arraylist c=*x+*y;
		   System::String^ s="";
		   for(int i=0;i<c.GetElemsCount();i++)
		   {
			  s+=c.GetElemInd(i);
			  s+=" ";
		   }
		   textBox6->Text=s;
	    }
private: System::Void button7_Click(System::Object^  sender, System::EventArgs^  e) {
		   x--;
		   System::String^ s="";
		   for(int i=0;i<x->GetElemsCount();i++)
		   {
			  s+=x->GetElemInd(i);
			  s+=" ";
		   }
		   textBox6->Text=s;
	    }
};
}
List contains array of char
class Arraylist
{
  char *a;
  .......

  • 0

#2 Ancient Dragon

Ancient Dragon

    CC Addict

  • Senior Member
  • PipPipPipPipPip
  • 378 posts

Posted 26 October 2011 - 05:22 AM

>>x->GetElemInd(i);

What does GetElemInd() return? We have no clue from what you posted.
  • 0
Visit Grandpa's Forums, a social networking forum, with family-oriented arcade games, blogs, discussion forums, and photo albums.

#3 kernelcoder

kernelcoder

    CC Devotee

  • Expert Member
  • PipPipPipPipPipPip
  • 990 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal

Posted 19 April 2012 - 08:54 PM

As I don't have your 'Arraylist' class so I use the 'ArrayList' class from .NET library. And I found that the problem is in "char::Parse" method. I was getting 'FormatException' exception. I used System::Char::Parse and it worked for me. Following is the code that worked for me. I did only change those part that I changed from your code.

// First I used 'ArrayList' class
ArrayList^ x;

ArrayList^ y;

Form1(void)

{

InitializeComponent();

//

x=gcnew ArrayList();

y=gcnew ArrayList();

//TODO: Add the constructor code here

//
//////////////////
}


// the events handlers to manupulate the characters
#pragma endregion

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {

x->Add(System::Char::Parse(textBox1->Text));

}

private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) {

y->Add(System::Char::Parse(textBox2->Text));

}

private: System::Void button5_Click(System::Object^  sender, System::EventArgs^  e) {

if (x==y) textBox5->Text="True"; else textBox5->Text="False";

}

private: System::Void button3_Click(System::Object^  sender, System::EventArgs^  e) {

System::String^ s="";

for(int i=0;i<x->Count;i++)

{s+=x[i];

s+=" ";}

textBox3->Text=s;

}

private: System::Void button4_Click(System::Object^  sender, System::EventArgs^  e) {

System::String^ s="";

for(int i=0;i<y->Count;i++)

{s+=y[i];

s+=" ";}

textBox4->Text=s;

}

private: System::Void button6_Click(System::Object^  sender, System::EventArgs^  e) {

ArrayList^ c = gcnew ArrayList();
c->AddRange(x->ToArray());
c->AddRange(y->ToArray());

System::String^ s="";

for(int i=0;i<c->Count;i++)

{

s+=c[i];

s+=" ";

}

textBox6->Text=s;

}

private: System::Void button7_Click(System::Object^  sender, System::EventArgs^  e) {

x->RemoveAt(x->Count - 1);
System::String^ s="";
for(int i=0;i<x->Count;i++)
{

s+=x[i];

s+=" ";

}

textBox6->Text=s;

}

  • 0





Also tagged with one or more of these keywords: Managed C++, write to