C++ für Kids//Seelenklempner PROBLEM!



  • hey also bei dem programm soll mir der computer helfen^^und zwar schreib ich etwas was ist der softwarejedoch so zeihmlich egal und wenn ich auf fertig (button2) klicke sol er mir im label1 eine antwort anzeigen die er aus einer txt datei lädt! wenn ich jedoch auf fertig klicke crasht das programm.

    unter anderem habe ich noch eine srcollbar eingebaut die es mir erlaubt zwischen den verschiedenen diagnosen hin un her zu scrollen (jede zeile aus der txt ist eine diagnose)

    hier der code´

    #pragma once
    
    namespace klemp51 {
    
    	using namespace System;
    	using namespace System::ComponentModel;
    	using namespace System::Collections;
    	using namespace System::Windows::Forms;
    	using namespace System::Data;
    	using namespace System::Drawing;
        using namespace System::IO;
    	//const int Max = 10;
    
    	/// <summary>
    	/// Zusammenfassung für Form1
    	///
    	/// Warnung: Wenn Sie den Namen dieser Klasse ändern, müssen Sie auch
    	///          die Ressourcendateiname-Eigenschaft für das Tool zur Kompilierung verwalteter Ressourcen ändern,
    	///          das allen RESX-Dateien zugewiesen ist, von denen diese Klasse abhängt.
    	///          Anderenfalls können die Designer nicht korrekt mit den lokalisierten Ressourcen
    	///          arbeiten, die diesem Formular zugewiesen sind.
    	/// </summary>
    	public ref class Form1 : public System::Windows::Forms::Form
    	{
    	public:
    		Form1(void)
    		{
    			InitializeComponent();
    			//
    			//TODO: Konstruktorcode hier hinzufügen.
    			//
    		}
    
    	protected:
    		/// <summary>
    		/// Verwendete Ressourcen bereinigen.
    		/// </summary>
    		~Form1()
    		{
    			if (components)
    			{
    				delete components;
    			}
    		}
    	private: System::Windows::Forms::GroupBox^  groupBox1;
    	protected: 
    	private: System::Windows::Forms::TextBox^  textBox1;
    	private: System::Windows::Forms::GroupBox^  groupBox2;
    	private: System::Windows::Forms::Label^  label1;
    	private: System::Windows::Forms::GroupBox^  groupBox3;
    	private: System::Windows::Forms::HScrollBar^  hScrollBar1;
    	private: System::Windows::Forms::Button^  button1;
    	private: System::Windows::Forms::Button^  button2;
    
    	private:
    		/// <summary>
    		/// Erforderliche Designervariable.
    		/// </summary>
    		System::ComponentModel::Container ^components;
    
    #pragma region Windows Form Designer generated code
    		/// <summary>
    		/// Erforderliche Methode für die Designerunterstützung.
    		/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
    		/// </summary>
    		void InitializeComponent(void)
    		{
    			this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
    			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
    			this->groupBox2 = (gcnew System::Windows::Forms::GroupBox());
    			this->label1 = (gcnew System::Windows::Forms::Label());
    			this->groupBox3 = (gcnew System::Windows::Forms::GroupBox());
    			this->hScrollBar1 = (gcnew System::Windows::Forms::HScrollBar());
    			this->button1 = (gcnew System::Windows::Forms::Button());
    			this->button2 = (gcnew System::Windows::Forms::Button());
    			this->groupBox1->SuspendLayout();
    			this->groupBox2->SuspendLayout();
    			this->groupBox3->SuspendLayout();
    			this->SuspendLayout();
    			// 
    			// groupBox1
    			// 
    			this->groupBox1->Controls->Add(this->textBox1);
    			this->groupBox1->Location = System::Drawing::Point(49, 43);
    			this->groupBox1->Name = L"groupBox1";
    			this->groupBox1->Size = System::Drawing::Size(603, 112);
    			this->groupBox1->TabIndex = 0;
    			this->groupBox1->TabStop = false;
    			this->groupBox1->Text = L"Das sagst du mir";
    			// 
    			// textBox1
    			// 
    			this->textBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
    				static_cast<System::Byte>(0)));
    			this->textBox1->Location = System::Drawing::Point(33, 48);
    			this->textBox1->Name = L"textBox1";
    			this->textBox1->Size = System::Drawing::Size(527, 29);
    			this->textBox1->TabIndex = 0;
    			// 
    			// groupBox2
    			// 
    			this->groupBox2->Controls->Add(this->label1);
    			this->groupBox2->Location = System::Drawing::Point(49, 161);
    			this->groupBox2->Name = L"groupBox2";
    			this->groupBox2->Size = System::Drawing::Size(603, 112);
    			this->groupBox2->TabIndex = 1;
    			this->groupBox2->TabStop = false;
    			this->groupBox2->Text = L"Das sag ich dir";
    			// 
    			// label1
    			// 
    			this->label1->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
    			this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point, 
    				static_cast<System::Byte>(0)));
    			this->label1->Location = System::Drawing::Point(33, 48);
    			this->label1->Name = L"label1";
    			this->label1->Size = System::Drawing::Size(527, 36);
    			this->label1->TabIndex = 0;
    			// 
    			// groupBox3
    			// 
    			this->groupBox3->Controls->Add(this->hScrollBar1);
    			this->groupBox3->Location = System::Drawing::Point(49, 300);
    			this->groupBox3->Name = L"groupBox3";
    			this->groupBox3->Size = System::Drawing::Size(603, 112);
    			this->groupBox3->TabIndex = 1;
    			this->groupBox3->TabStop = false;
    			this->groupBox3->Text = L"Diagnose Manipulator";
    			// 
    			// hScrollBar1
    			// 
    			this->hScrollBar1->Location = System::Drawing::Point(33, 42);
    			this->hScrollBar1->Name = L"hScrollBar1";
    			this->hScrollBar1->Size = System::Drawing::Size(527, 41);
    			this->hScrollBar1->TabIndex = 0;
    			this->hScrollBar1->Scroll += gcnew System::Windows::Forms::ScrollEventHandler(this, &Form1::hScrollBar1_Scroll);
    			// 
    			// button1
    			// 
    			this->button1->Location = System::Drawing::Point(68, 418);
    			this->button1->Name = L"button1";
    			this->button1->Size = System::Drawing::Size(203, 36);
    			this->button1->TabIndex = 2;
    			this->button1->Text = L"Neu";
    			this->button1->UseVisualStyleBackColor = true;
    			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
    			// 
    			// button2
    			// 
    			this->button2->Location = System::Drawing::Point(372, 418);
    			this->button2->Name = L"button2";
    			this->button2->Size = System::Drawing::Size(203, 36);
    			this->button2->TabIndex = 3;
    			this->button2->Text = L"Fertig";
    			this->button2->UseVisualStyleBackColor = true;
    			this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
    			// 
    			// Form1
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(742, 466);
    			this->Controls->Add(this->button2);
    			this->Controls->Add(this->button1);
    			this->Controls->Add(this->groupBox2);
    			this->Controls->Add(this->groupBox3);
    			this->Controls->Add(this->groupBox1);
    			this->Name = L"Form1";
    			this->Text = L"Form1";
    			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
    			this->groupBox1->ResumeLayout(false);
    			this->groupBox1->PerformLayout();
    			this->groupBox2->ResumeLayout(false);
    			this->groupBox3->ResumeLayout(false);
    			this->ResumeLayout(false);
    
    		}
    #pragma endregion
    		//array<String^>^ Diagnose;
    		Random^ Zufall;
    		int Nr;
    		ArrayList^ Diagnose; //FP
    		String^ Pfad;
    
        private: void LoadText (String^ DateiName)
        {
            try
            {
                String^ Zeile;
                StreamReader^ Datei = gcnew StreamReader(DateiName);
                while (Zeile = Datei->ReadLine())
                {
                    Diagnose->Add(Zeile);
                    // Zeile = Datei->ReadLine();
                }
            }
            catch (...)
            {
                MessageBox::Show ("Datei nicht gefunden!");
                Close();
            }
        }
    
    	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) 
    			 {
    				 Pfad = "c:\\Dokumente und Einstellungen\\John\\Eigene Dateien\\Visual Studio 2008\\Projects\\TXT\\Diagnose.txt";
    //				 LoadText (Pfad + Diagnose2.txt);
    				 Zufall = gcnew Random();
    				 Diagnose = gcnew ArrayList();
    				 hScrollBar1->LargeChange = 1;
    				 hScrollBar1->Maximum = Diagnose->Count - 1;
    				 hScrollBar1->Minimum = 0;
    
    			 }
    private: System::Void button2_Click(System::Object^  sender, System::EventArgs^  e) 
    		 {
    			 Nr = Zufall->Next(Diagnose->Count);
    			 label1->Text = Diagnose[Nr]->ToString();
    		 }
    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
    		 {
    			 label1->Text = "";
    			 textBox1->Text = "";
    			 textBox1->Focus();		
    		 }
    private: System::Void hScrollBar1_Scroll(System::Object^  sender, System::Windows::Forms::ScrollEventArgs^  e) 
    		 {
    			 label1->Text = Diagnose[hScrollBar1->Value]->ToString();
    		 }
    
    };
    }
    


  • mal wieder wie immer falsches Forum, sollte mal zu CLI mit .Net verschoben werden.



  • Kannst Du Deine Frage etweas *konkrekter* Stellen? WO crasht WAS?
    Du kannst es doch debuggen! Schau Dir die Werte der Variablen an!
    WAS kommt für eine Fehlermeldung beim Absturz?



  • Dieser Thread wurde von Moderator/in Martin Richter aus dem Forum MFC (Visual C++) in das Forum C++/CLI mit .NET verschoben.

    Im Zweifelsfall bitte auch folgende Hinweise beachten:
    C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?

    Dieses Posting wurde automatisch erzeugt.



  • wenn ich auf den fertig button(button2) klicke sol er mir eigentlich ine antwort in das label2 geben dann crasht es allerdigs mit der meldung

    Eine nicht behandelte Ausnahme des Typs "System.ArgumentOutOfRangeException" ist in mscorlib.dll aufgetreten.

    Zusätzliche Informationen: Der Index lag außerhalb des Bereichs. Er muss nicht negativ und kleiner als die Auflistung sein.



  • ich hab das genze jetzt einfach vereinfacht ich möchte wenn ich auf button1 clicke eine datei laden aber wenn ich das programm starte kommt die meldung datei nicht gefunden... das liegt aber nicht am ´pfad oder weil die datei falsch gespeichert ist ich weis es nicht.

    #pragma once
    
    namespace test {
    
    	using namespace System;
    	using namespace System::ComponentModel;
    	using namespace System::Collections;
    	using namespace System::Windows::Forms;
    	using namespace System::Data;
    	using namespace System::Drawing;
    	using namespace System::IO;
    
    	/// <summary>
    	/// Zusammenfassung für Form1
    	///
    	/// Warnung: Wenn Sie den Namen dieser Klasse ändern, müssen Sie auch
    	///          die Ressourcendateiname-Eigenschaft für das Tool zur Kompilierung verwalteter Ressourcen ändern,
    	///          das allen RESX-Dateien zugewiesen ist, von denen diese Klasse abhängt.
    	///          Anderenfalls können die Designer nicht korrekt mit den lokalisierten Ressourcen
    	///          arbeiten, die diesem Formular zugewiesen sind.
    	/// </summary>
    	public ref class Form1 : public System::Windows::Forms::Form
    	{
    	public:
    		Form1(void)
    		{
    			InitializeComponent();
    			//
    			//TODO: Konstruktorcode hier hinzufügen.
    			//
    		}
    
    	protected:
    		/// <summary>
    		/// Verwendete Ressourcen bereinigen.
    		/// </summary>
    		~Form1()
    		{
    			if (components)
    			{
    				delete components;
    			}
    		}
    	private: System::Windows::Forms::Button^  button1;
    	protected: 
    
    	private:
    		/// <summary>
    		/// Erforderliche Designervariable.
    		/// </summary>
    		System::ComponentModel::Container ^components;
    
    #pragma region Windows Form Designer generated code
    		/// <summary>
    		/// Erforderliche Methode für die Designerunterstützung.
    		/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
    		/// </summary>
    		void InitializeComponent(void)
    		{
    			this->button1 = (gcnew System::Windows::Forms::Button());
    			this->SuspendLayout();
    			// 
    			// button1
    			// 
    			this->button1->Location = System::Drawing::Point(38, 67);
    			this->button1->Name = L"button1";
    			this->button1->Size = System::Drawing::Size(152, 73);
    			this->button1->TabIndex = 0;
    			this->button1->Text = L"button1";
    			this->button1->UseVisualStyleBackColor = true;
    			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
    			// 
    			// Form1
    			// 
    			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
    			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
    			this->ClientSize = System::Drawing::Size(292, 266);
    			this->Controls->Add(this->button1);
    			this->Name = L"Form1";
    			this->Text = L"Form1";
    			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
    			this->ResumeLayout(false);
    
    		}
    #pragma endregion
        String^ Pfad;
        ArrayList^ Diagnose;
    	int Nr;
    
    	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) 
    			 {
    				 button1->Text = Diagnose[Nr]->ToString();
    			 }
    	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) 
    			 {
    				 Pfad = "c:\\Dokumente und Einstellungen\\John\\Eigene Dateien\\Visual Studio 2008\\Projects\\TXT\\";
    				 LoadText (Pfad + "Diagnose2.txt");
    			 }
        private: void LoadText (String^ DateiName)
        {
            try
            {
                String^ Zeile;
                StreamReader^ Datei = gcnew StreamReader(DateiName);
                while (Zeile = Datei->ReadLine())
                {
                    Diagnose->Add(Zeile);
                    // Zeile = Datei->ReadLine();
                }
            }
            catch (...)
            {
                MessageBox::Show ("Datei nicht gefunden!");
                Close();
            }
        }
    	};
    }
    


  • Debugge es doch bitte.... setze einen Breakpoint auf die "LoadText" Methode und gehe dann mit F10 schritt für schritt durch... dann siehst Du genau was passiert...

    Auch solltest Du Exceptions nie "schlucken", sondern den Fehlertext dazu ausgeben!


Anmelden zum Antworten