I'm pretty new to c++ and i'm making a program in visual c++. Everything was going great until this error appeared:
error C2440: '==' : cannot convert from 'const char [11]' to'System::Windows::Forms::TextBox ^'
im pretty sure it has something to do with me putting numbers in the text box instead of words.
here's part of the code:
if (fnum==true){
if (phoneNum=="555555555"){ // i think this part causes the problem
//code for when the phone number is correct
} else {
//if phone number is not correct
}
}
i tried putting '5555555555' instead of "5555555555" but it gave me a different errors
error C2015: too many characters in constant
error C2446: '==' : no conversion from 'int' to 'System::Windows::Forms::TextBox ^'
heres the rest of the code:
#pragma once
#include <stdio.h>
#include <Windows.h>
bool fnum = true;
bool vis=true;
namespace Items {
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
{
static int tim = 0;
public:
Form1(void)
{
InitializeComponent();
//
//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::Button^ button1;
private: System::Windows::Forms::TextBox^ Searcher;
private: System::Windows::Forms::Button^ search;
private: System::Windows::Forms::PictureBox^ usb_key;
private: System::Windows::Forms::PictureBox^ help;
private: System::Windows::Forms::PictureBox^ yahoo_passcode;
private: System::Windows::Forms::Timer^ timer1;
private: System::Windows::Forms::PictureBox^ yahoo_Passcode2;
private: System::Windows::Forms::TextBox^ phoneNum;
private: System::ComponentModel::IContainer^ components;
private:
/// <summary>
/// Required designer variable.
/// </summary>
#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->components = (gcnew System::ComponentModel::Container());
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
this->label1 = (gcnew System::Windows::Forms::Label());
this->button1 = (gcnew System::Windows::Forms::Button());
this->Searcher = (gcnew System::Windows::Forms::TextBox());
this->search = (gcnew System::Windows::Forms::Button());
this->usb_key = (gcnew System::Windows::Forms::PictureBox());
this->help = (gcnew System::Windows::Forms::PictureBox());
this->yahoo_passcode = (gcnew System::Windows::Forms::PictureBox());
this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
this->yahoo_Passcode2 = (gcnew System::Windows::Forms::PictureBox());
this->phoneNum = (gcnew System::Windows::Forms::TextBox());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ > (this->usb_key))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->help))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->yahoo_passcode))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->yahoo_Passcode2))->BeginInit();
this->SuspendLayout();
//
// label1
//
this->label1->AutoSize = true;
this->label1->Font = (gcnew System::Drawing::Font(L"Quartz", 20, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->label1->ForeColor = System::Drawing::SystemColors::ActiveCaption;
this->label1->Location = System::Drawing::Point(12, 9);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(84, 30);
this->label1->TabIndex = 0;
this->label1->Text = L"Items";
//
// button1
//
this->button1->BackColor = System::Drawing::SystemColors::ActiveCaption;
this->button1->FlatStyle = System::Windows::Forms::FlatStyle::Flat;
this->button1->Font = (gcnew System::Drawing::Font(L"Quartz", 8.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->button1->Location = System::Drawing::Point(661, 9);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(52, 21);
this->button1->TabIndex = 1;
this->button1->Text = L"Exit";
this->button1->UseVisualStyleBackColor = false;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// Searcher
//
this->Searcher->BackColor = System::Drawing::SystemColors::InactiveCaption;
this->Searcher->BorderStyle = System::Windows::Forms::BorderStyle::None;
this->Searcher->Font = (gcnew System::Drawing::Font(L"Quartz", 14.25F, static_cast<System::Drawing::FontStyle>((System::Drawing::FontStyle::Bold | System::Drawing::FontStyle::Italic)),
System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(0)));
this->Searcher->Location = System::Drawing::Point(12, 82);
this->Searcher->Name = L"Searcher";
this->Searcher->Size = System::Drawing::Size(741, 22);
this->Searcher->TabIndex = 2;
this->Searcher->Click += gcnew System::EventHandler(this, &Form1::Searcher_Click);
this->Searcher->TextChanged += gcnew System::EventHandler(this, &Form1::textBox1_TextChanged);
//
// search
//
this->search->Location = System::Drawing::Point(362, 28);
this->search->Name = L"search";
this->search->Size = System::Drawing::Size(1, 1);
this->search->TabIndex = 3;
this->search->Text = L"button2";
this->search->UseVisualStyleBackColor = true;
this->search->Click += gcnew System::EventHandler(this, &Form1::search_Click);
//
// usb_key
//
this->usb_key->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"usb_key.Image")));
this->usb_key->Location = System::Drawing::Point(-95, 142);
this->usb_key->Name = L"usb_key";
this->usb_key->Size = System::Drawing::Size(866, 464);
this->usb_key->SizeMode = System::Windows::Forms::PictureBoxSizeMode::Zoom;
this->usb_key->TabIndex = 4;
this->usb_key->TabStop = false;
this->usb_key->Visible = false;
//
// help
//
this->help->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"help.Image")));
this->help->Location = System::Drawing::Point(49, 259);
this->help->Name = L"help";
this->help->Size = System::Drawing::Size(664, 234);
this->help->TabIndex = 5;
this->help->TabStop = false;
this->help->Visible = false;
//
// yahoo_passcode
//
this->yahoo_passcode->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"yahoo_passcode.Image")));
this->yahoo_passcode->Location = System::Drawing::Point(49, 142);
this->yahoo_passcode->Name = L"yahoo_passcode";
this->yahoo_passcode->Size = System::Drawing::Size(663, 444);
this->yahoo_passcode->SizeMode = System::Windows::Forms::PictureBoxSizeMode::Zoom;
this->yahoo_passcode->TabIndex = 6;
this->yahoo_passcode->TabStop = false;
this->yahoo_passcode->Visible = false;
//
// timer1
//
this->timer1->Interval = 1000;
this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick);
//
// yahoo_Passcode2
//
this->yahoo_Passcode2->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"yahoo_Passcode2.Image")));
this->yahoo_Passcode2->Location = System::Drawing::Point(50, 142);
this->yahoo_Passcode2->Name = L"yahoo_Passcode2";
this->yahoo_Passcode2->Size = System::Drawing::Size(663, 444);
this->yahoo_Passcode2->SizeMode = System::Windows::Forms::PictureBoxSizeMode::Zoom;
this->yahoo_Passcode2->TabIndex = 7;
this->yahoo_Passcode2->TabStop = false;
this->yahoo_Passcode2->Visible = false;
//
// phoneNum
//
this->phoneNum->BackColor = System::Drawing::SystemColors::InactiveCaptionText;
this->phoneNum->BorderStyle = System::Windows::Forms::BorderStyle::None;
this->phoneNum->Font = (gcnew System::Drawing::Font(L"Garamond", 14, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast<System::Byte>(0)));
this->phoneNum->ForeColor = System::Drawing::Color::Lime;
this->phoneNum->Location = System::Drawing::Point(128, 224);
this->phoneNum->Name = L"phoneNum";
this->phoneNum->Size = System::Drawing::Size(487, 21);
this->phoneNum->TabIndex = 8;
this->phoneNum->Enter += gcnew System::EventHandler(this, &Form1::textBox1_Enter);
this->phoneNum->Leave += gcnew System::EventHandler(this, &Form1::textBox1_Leave);
//
// Form1
//
this->AcceptButton = this->search;
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->BackColor = System::Drawing::SystemColors::ActiveCaptionText;
this->ClientSize = System::Drawing::Size(765, 621);
this->Controls->Add(this->phoneNum);
this->Controls->Add(this->yahoo_Passcode2);
this->Controls->Add(this->yahoo_passcode);
this->Controls->Add(this->help);
this->Controls->Add(this->usb_key);
this->Controls->Add(this->search);
this->Controls->Add(this->Searcher);
this->Controls->Add(this->button1);
this->Controls->Add(this->label1);
this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::None;
this->MaximizeBox = false;
this->Name = L"Form1";
this->StartPosition = System::Windows::Forms::FormStartPosition::CenterScreen;
this->Text = L"Form1";
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->usb_key))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->help))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->yahoo_passcode))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->yahoo_Passcode2))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Application::Exit();
}
private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) {
if (Searcher->Text=="") { //when the text box has no text in it anymore
usb_key->Visible = false;
help->Visible = false;
yahoo_passcode->Visible = false;
yahoo_Passcode2->Visible = false;
timer1->Enabled = false;
}
}
private: System::Void search_Click(System::Object^ sender, System::EventArgs^ e) {
//when the search button is pressed.
/////////////////////////////////////////////////////
if (fnum==true){
if (phoneNum=='5555555555'){
//code for when the phone number is correct
} else {
//if phone number is not correct
}
}
///////////////////////////////////////////////////
if (Searcher->Text=="usb key") {
usb_key->Visible = vis;
}
else if (Searcher->Text=="USB key"){
usb_key->Visible = vis;
}
else if (Searcher->Text=="Usb key") {
usb_key->Visible = true;
}
else if (Searcher->Text=="help") {
help->Visible = true;
}
else if (Searcher->Text=="yahoo password") {
yahoo_passcode->Visible = true;
timer1->Enabled = true;
}
}
private: System::Void Searcher_Click(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
tim++;
if (tim==4) {
timer1->Enabled = false;
yahoo_Passcode2->Visible = true;
yahoo_passcode->Visible = false;
}
}
private: System::Void textBox1_Enter(System::Object^ sender, System::EventArgs^ e) {
fnum = true;
}
private: System::Void textBox1_Leave(System::Object^ sender, System::EventArgs^ e) {
fnum = false;
}
};
}
As i said before i'm new to c++ and i don't really know much, so if you could give the answer in a simple form that would be great. like showing what to change and what it does.
thanks in advanced.
phoneNum is a a TextBox^, not a "string" of some form. You'll want to compare against the Text property of this control, not the control itself.
You likely need:
if (phoneNum->Text == "555555555")
{
Related
I'm italian and I was forced to sign up for tell you what is my problem using Visual C++ (Windows Form Application).
#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>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
protected:
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::FolderBrowserDialog^ folderBrowserDialog1;
protected:
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->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->folderBrowserDialog1 = (gcnew System::Windows::Forms::FolderBrowserDialog());
this->SuspendLayout();
//
// button1
//
this->button1->Location = System::Drawing::Point(316, 9);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(75, 23);
this->button1->TabIndex = 0;
this->button1->Text = L"button1";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// button2
//
this->button2->Location = System::Drawing::Point(316, 53);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(75, 23);
this->button2->TabIndex = 1;
this->button2->Text = L"button2";
this->button2->UseVisualStyleBackColor = true;
this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(28, 9);
this->textBox1->Multiline = true;
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(278, 23);
this->textBox1->TabIndex = 2;
//
// textBox2
//
this->textBox2->Location = System::Drawing::Point(28, 53);
this->textBox2->Multiline = true;
this->textBox2->Name = L"textBox2";
this->textBox2->Size = System::Drawing::Size(278, 23);
this->textBox2->TabIndex = 3;
//
// button3
//
this->button3->Location = System::Drawing::Point(133, 102);
this->button3->Name = L"button3";
this->button3->Size = System::Drawing::Size(75, 23);
this->button3->TabIndex = 4;
this->button3->Text = L"button3";
this->button3->UseVisualStyleBackColor = true;
this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
//
// folderBrowserDialog1
//
this->folderBrowserDialog1->HelpRequest += gcnew System::EventHandler(this, &Form1::folderBrowserDialog1_HelpRequest);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(453, 170);
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->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) {
OpenFileDialog^ chooseDirectory = gcnew OpenFileDialog;
chooseDirectory->ShowDialog();
textBox1->Text = chooseDirectory->FileName;
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
FolderBrowserDialog^ fbd = gcnew FolderBrowserDialog;
fbd->ShowDialog();
textBox2->Text = fbd->SelectedPath;
}
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
File::Move(textBox1->Text, textBox2->Text);
MessageBox::Show("Success","File's directory has been changed!", MessageBoxButtons::OK, MessageBoxIcon::Information);
}
private: System::Void folderBrowserDialog1_HelpRequest(System::Object^ sender, System::EventArgs^ e) {
}
};
}
I don't know the reason, but it doesn't works! I only want to move the file choosen (using OpenFileDialog) to another directory (using FolderBrowserDialog).
I don't know what i should do. PLEASE HELP ME! Thanks!
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
#pragma once
namespace StudentDataSearch {
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:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ btnSearch;
protected:
protected:
private: System::Windows::Forms::Label^ Course_ID1;
protected:
private: System::Windows::Forms::TextBox^ txtTargetID;
private: System::Windows::Forms::GroupBox^ groupBox1;
private: System::Windows::Forms::TextBox^ txtSeats;
private: System::Windows::Forms::Label^ Seats;
private: System::Windows::Forms::TextBox^ txtID;
private: System::Windows::Forms::Label^ Course_ID;
private: System::Windows::Forms::TextBox^ txtName;
private: System::Windows::Forms::Label^ Course_Names2;
private: System::Windows::Forms::Button^ btnSearchName;
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->btnSearch = (gcnew System::Windows::Forms::Button());
this->Course_ID1 = (gcnew System::Windows::Forms::Label());
this->txtTargetID = (gcnew System::Windows::Forms::TextBox());
this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
this->txtSeats = (gcnew System::Windows::Forms::TextBox());
this->Seats = (gcnew System::Windows::Forms::Label());
this->txtID = (gcnew System::Windows::Forms::TextBox());
this->Course_ID = (gcnew System::Windows::Forms::Label());
this->txtName = (gcnew System::Windows::Forms::TextBox());
this->Course_Names2 = (gcnew System::Windows::Forms::Label());
this->btnSearchName = (gcnew System::Windows::Forms::Button());
this->groupBox1->SuspendLayout();
this->SuspendLayout();
//
// btnSearch
//
this->btnSearch->Location = System::Drawing::Point(12, 12);
this->btnSearch->Name = L"btnSearch";
this->btnSearch->Size = System::Drawing::Size(144, 39);
this->btnSearch->TabIndex = 0;
this->btnSearch->Text = L"Search by Course ID";
this->btnSearch->UseVisualStyleBackColor = true;
this->btnSearch->Click += gcnew System::EventHandler(this, &Form1::btnSearch_Click);
//
// Course_ID1
//
this->Course_ID1->AutoSize = true;
this->Course_ID1->Location = System::Drawing::Point(317, 28);
this->Course_ID1->Name = L"Course_ID1";
this->Course_ID1->Size = System::Drawing::Size(54, 13);
this->Course_ID1->TabIndex = 1;
this->Course_ID1->Text = L"Course ID";
//
// txtTargetID
//
this->txtTargetID->Location = System::Drawing::Point(377, 25);
this->txtTargetID->Name = L"txtTargetID";
this->txtTargetID->Size = System::Drawing::Size(100, 20);
this->txtTargetID->TabIndex = 2;
//
// groupBox1
//
this->groupBox1->Controls->Add(this->txtSeats);
this->groupBox1->Controls->Add(this->Seats);
this->groupBox1->Controls->Add(this->txtID);
this->groupBox1->Controls->Add(this->Course_ID);
this->groupBox1->Controls->Add(this->txtName);
this->groupBox1->Controls->Add(this->Course_Names2);
this->groupBox1->Location = System::Drawing::Point(12, 145);
this->groupBox1->Name = L"groupBox1";
this->groupBox1->Size = System::Drawing::Size(465, 140);
this->groupBox1->TabIndex = 3;
this->groupBox1->TabStop = false;
this->groupBox1->Text = L"Search Results";
//
// txtSeats
//
this->txtSeats->Location = System::Drawing::Point(301, 81);
this->txtSeats->Name = L"txtSeats";
this->txtSeats->Size = System::Drawing::Size(100, 20);
this->txtSeats->TabIndex = 5;
//
// Seats
//
this->Seats->AutoSize = true;
this->Seats->Location = System::Drawing::Point(298, 65);
this->Seats->Name = L"Seats";
this->Seats->Size = System::Drawing::Size(34, 13);
this->Seats->TabIndex = 4;
this->Seats->Text = L"Seats";
//
// txtID
//
this->txtID->Location = System::Drawing::Point(204, 81);
this->txtID->Name = L"txtID";
this->txtID->Size = System::Drawing::Size(91, 20);
this->txtID->TabIndex = 3;
//
// Course_ID
//
this->Course_ID->AutoSize = true;
this->Course_ID->Location = System::Drawing::Point(206, 65);
this->Course_ID->Name = L"Course_ID";
this->Course_ID->Size = System::Drawing::Size(54, 13);
this->Course_ID->TabIndex = 2;
this->Course_ID->Text = L"Course ID";
//
// txtName
//
this->txtName->Location = System::Drawing::Point(25, 81);
this->txtName->Name = L"txtName";
this->txtName->Size = System::Drawing::Size(173, 20);
this->txtName->TabIndex = 1;
//
// Course_Names2
//
this->Course_Names2->AutoSize = true;
this->Course_Names2->Location = System::Drawing::Point(22, 65);
this->Course_Names2->Name = L"Course_Names2";
this->Course_Names2->Size = System::Drawing::Size(71, 13);
this->Course_Names2->TabIndex = 0;
this->Course_Names2->Text = L"Course Name";
//
// btnSearchName
//
this->btnSearchName->Location = System::Drawing::Point(12, 57);
this->btnSearchName->Name = L"btnSearchName";
this->btnSearchName->Size = System::Drawing::Size(144, 39);
this->btnSearchName->TabIndex = 4;
this->btnSearchName->Text = L"Search by Course Name";
this->btnSearchName->UseVisualStyleBackColor = true;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(519, 297);
this->Controls->Add(this->btnSearchName);
this->Controls->Add(this->groupBox1);
this->Controls->Add(this->txtTargetID);
this->Controls->Add(this->Course_ID1);
this->Controls->Add(this->btnSearch);
this->Name = L"Form1";
this->Text = L"Student Data Search";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->groupBox1->ResumeLayout(false);
this->groupBox1->PerformLayout();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: array<String^>^ CourseArr;
private: array<String^>^ CourseID;
private: array<Int32>^ SeatsArr;
private: String^ strTarget;
private: String^ strOut;
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
// Course Names
CourseArr = gcnew array<String^>(9);
CourseArr->SetValue("Computer Sci 1511", 0);
CourseArr->SetValue("Computer Sci 1521", 1);
CourseArr->SetValue("Composition 1120", 2);
CourseArr->SetValue("Math 1296", 3);
CourseArr->SetValue("Physics 1120", 4);
CourseArr->SetValue("Biology 1100", 5);
CourseArr->SetValue("Chemistry 1100", 6);
CourseArr->SetValue("Anthropology 1210", 7);
CourseArr->SetValue("Economics 1000", 8);
// Course ID
CourseID = gcnew array<String^>(9);
CourseID->SetValue("123", 0);
CourseID->SetValue("124", 1);
CourseID->SetValue("135", 2);
CourseID->SetValue("145", 3);
CourseID->SetValue("146", 4);
CourseID->SetValue("149", 5);
CourseID->SetValue("155", 6);
CourseID->SetValue("162", 7);
CourseID->SetValue("175", 8);
//Seats Avaliable
SeatsArr = gcnew array<Int32>(9);
SeatsArr->SetValue(0, 0);
SeatsArr->SetValue(25, 1);
SeatsArr->SetValue(14, 2);
SeatsArr->SetValue(5, 3);
SeatsArr->SetValue(0, 4);
SeatsArr->SetValue(20, 5);
SeatsArr->SetValue(17, 6);
SeatsArr->SetValue(0, 7);
SeatsArr->SetValue(12, 8);
}
private: System::Void btnSearch_Click(System::Object^ sender, System::EventArgs^ e) {
int course, small, large;
int id;
int seats;
small = 0;
large = 9;
strTarget = txtTargetID->Text;
if (strTarget == "")
{
MessageBox::Show("Fill in empty fields");
return;
}
help needed here ----------------------------------------------------------
I need to loop through my arrays and used their values (listed above) and put the selected values into certain text boxes but I am unsure if I need another for loop or what please help and all help is appreciated.
for (int small = 0; small <= large; small++)
{
for (int course = 0; course < CourseID->Length; course++)
{
txtName->Text = CourseArr[0];
txtID->Text = CourseID[0];
txtSeats->Text = SeatsArr[0].ToString();
}
}
Referring to CourseArr[0] etc. within the loop will give you the same element each time.
You need to refer to CourseArr[course].
(I suspect this isn't enough to solve your problem, but it's hard to figure out what's required for that!)
I am making a Video game using microsoft Visual c++, I am coding all of this in CLR language, But I this weird problem....
For some reason Whenever I try and open form 2 with Form 1 all I get are these errors...
*1>------ Build started: Project: Retaliation, Configuration: Debug Win32 ------
1> Form2.cpp
1>c:\users\devon\documents\visual studio 2010\projects\retaliation\retaliation\Form1.h(431): error C2065: 'Form2' : undeclared identifier
1>c:\users\devon\documents\visual studio 2010\projects\retaliation\retaliation\Form1.h(431): error C2065: 'f2' : undeclared identifier
1>c:\users\devon\documents\visual studio 2010\projects\retaliation\retaliation\Form1.h(431): error C2061: syntax error : identifier 'Form2'
1>c:\users\devon\documents\visual studio 2010\projects\retaliation\retaliation\Form1.h(432): error C2065: 'f2' : undeclared identifier
1>c:\users\devon\documents\visual studio 2010\projects\retaliation\retaliation\Form1.h(432): error C2227: left of '->Show' must point to class/struct/union/generic type
1> type is ''unknown-type''
1> Retaliation.cpp
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========*
Here is my code for form 1...
#pragma once
#include "stdAfx.h"
#include "Form2.h"
#include "Form1.h"
namespace Retaliation {
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;
using namespace std;
/// <summary>
/// Summary for Form1
/// </summary>
public ref class Form1 : public System::Windows::Forms::Form
{
public:
String^ CharName;
String^ Race;
String^ Gender;
String^ Specialty;
String^ Friend;
int YesorNo;
int ExitChoice;
int TimerValue;
int MonsterN;
int EnemyHp;
int Dm;
int Energy;
int Action;
int Rage;
int MaxMana;
int MaxRage;
int MaxEnergy;
int Save;
// 1 = Earth pony 2 = Pegasus 3 = unicorn
int Lv;
int XpR;
int Xp;
int A;
int D;
int Hp;
int MaxHp;
int Magic;
int Mana;
int Agility;
int Gold;
String ^Enpowerment;
// 1 = Friendship is Magic, 2 = Music is Magic, 3 = Darkness is Magic, 4 = Light is Magic, 5 = Chaos is Magic
// End of leveling thread
int Checkpoint;
int FriendNameN;
int SavePoint;
int MenuChoice;
int RightMenuChoice;
int RestartFile;
int Answer;
int EnemyA;
int EnemyD;
int EnemyLv;
int EnemyMana;
int EnemyMagic;
int EnemyAgility;
int Random;
String ^ EName;
int Damage;
int Survivors;
int SavedSurvivors;
private: System::Windows::Forms::TextBox^ textBox1;
private: System::Windows::Forms::Timer^ timer1;
public:
int MainActions;
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::PictureBox^ pictureBox1;
protected:
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::Button^ button3;
private: System::Windows::Forms::PictureBox^ pictureBox2;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Button^ button4;
private: System::Windows::Forms::Button^ button5;
private: System::Windows::Forms::PictureBox^ pictureBox3;
private: System::ComponentModel::IContainer^ components;
private:
/// <summary>
/// Required designer variable.
/// </summary>
#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->components = (gcnew System::ComponentModel::Container());
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form1::typeid));
this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->button3 = (gcnew System::Windows::Forms::Button());
this->pictureBox2 = (gcnew System::Windows::Forms::PictureBox());
this->label1 = (gcnew System::Windows::Forms::Label());
this->label2 = (gcnew System::Windows::Forms::Label());
this->button4 = (gcnew System::Windows::Forms::Button());
this->button5 = (gcnew System::Windows::Forms::Button());
this->pictureBox3 = (gcnew System::Windows::Forms::PictureBox());
this->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->timer1 = (gcnew System::Windows::Forms::Timer(this- >components));
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ > (this->pictureBox1))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ > (this->pictureBox2))->BeginInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox3))->BeginInit();
this->SuspendLayout();
//
// pictureBox1
//
this->pictureBox1->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"pictureBox1.Image")));
this->pictureBox1->Location = System::Drawing::Point(0, -3);
this->pictureBox1->Name = L"pictureBox1";
this->pictureBox1->Size = System::Drawing::Size(600, 295);
this->pictureBox1->TabIndex = 0;
this->pictureBox1->TabStop = false;
//
// button1
//
this->button1->Location = System::Drawing::Point(13, 230);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(127, 43);
this->button1->TabIndex = 1;
this->button1->Text = L"Start Game";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// button2
//
this->button2->Location = System::Drawing::Point(313, 212);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(120, 42);
this->button2->TabIndex = 2;
this->button2->Text = L"New Game";
this->button2->UseVisualStyleBackColor = true;
this->button2->Visible = false;
this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
//
// button3
//
this->button3->Location = System::Drawing::Point(143, 212);
this->button3->Name = L"button3";
this->button3->Size = System::Drawing::Size(120, 42);
this->button3->TabIndex = 3;
this->button3->Text = L"Load Game";
this->button3->UseVisualStyleBackColor = true;
this->button3->Visible = false;
this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
//
// pictureBox2
//
this->pictureBox2->BackColor = System::Drawing::Color::Transparent;
this->pictureBox2->BackgroundImage = (cli::safe_cast<System::Drawing::Image^ >(resources- >GetObject(L"pictureBox2.BackgroundImage")));
this->pictureBox2->Location = System::Drawing::Point(0, -3);
this->pictureBox2->Name = L"pictureBox2";
this->pictureBox2->Size = System::Drawing::Size(86, 81);
this->pictureBox2->TabIndex = 4;
this->pictureBox2->TabStop = false;
this->pictureBox2->Visible = false;
//
// label1
//
this->label1->AutoSize = true;
this->label1->BackColor = System::Drawing::Color::Transparent;
this->label1->Location = System::Drawing::Point(92, -3);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(22, 13);
this->label1->TabIndex = 5;
this->label1->Text = L" ";
this->label1->Visible = false;
//
// label2
//
this->label2->BackColor = System::Drawing::Color::Transparent;
this->label2->Location = System::Drawing::Point(358, 87);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(199, 98);
this->label2->TabIndex = 9;
this->label2->Text = L"None";
this->label2->Visible = false;
//
// button4
//
this->button4->Location = System::Drawing::Point(463, 13);
this->button4->Name = L"button4";
this->button4->Size = System::Drawing::Size(75, 23);
this->button4->TabIndex = 12;
this->button4->Text = L"Yes";
this->button4->UseVisualStyleBackColor = true;
this->button4->Visible = false;
this->button4->Click += gcnew System::EventHandler(this, &Form1::button4_Click);
//
// button5
//
this->button5->Location = System::Drawing::Point(463, 43);
this->button5->Name = L"button5";
this->button5->Size = System::Drawing::Size(75, 23);
this->button5->TabIndex = 13;
this->button5->Text = L"No";
this->button5->UseVisualStyleBackColor = true;
this->button5->Visible = false;
this->button5->Click += gcnew System::EventHandler(this, &Form1::button5_Click);
//
// pictureBox3
//
this->pictureBox3->BackColor = System::Drawing::Color::Transparent;
this->pictureBox3->Location = System::Drawing::Point(13, 84);
this->pictureBox3->Name = L"pictureBox3";
this->pictureBox3->Size = System::Drawing::Size(165, 208);
this->pictureBox3->TabIndex = 14;
this->pictureBox3->TabStop = false;
this->pictureBox3->Visible = false;
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(463, 212);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(100, 20);
this->textBox1->TabIndex = 15;
this->textBox1->Visible = false;
this->textBox1->TextChanged += gcnew System::EventHandler(this, &Form1::textBox1_TextChanged_1);
//
// timer1
//
this->timer1->Interval = 1000;
this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick);
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(598, 285);
this->Controls->Add(this->textBox1);
this->Controls->Add(this->pictureBox3);
this->Controls->Add(this->button5);
this->Controls->Add(this->button4);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Controls->Add(this->pictureBox2);
this->Controls->Add(this->button3);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Controls->Add(this->pictureBox1);
this->Name = L"Form1";
this->Text = L"Retaliation";
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox1))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox2))->EndInit();
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->pictureBox3))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
public:int MoviePlay;
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
//
this -> button2 -> Visible = true;
this -> button3 -> Visible = true;
this -> button1 -> Visible = false;
this -> pictureBox1 -> Load("Derpy.jpg");
//
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
if (YesorNo == 0){
this -> button4 -> Visible = true;
this -> button2 -> Visible = false;
this -> button5 -> Visible = true;
this -> button3 -> Visible = false;
this -> label2 -> Visible = true;
this -> label2 -> Text = "Are you Sure?";
this -> YesorNo = 1;
}
else if (YesorNo == 5)
{
Gender = "Female";
this -> label2 -> Text = "What is your Race??";
this -> button4 -> Text = "Earth Pony";
this -> button5 -> Text = "Unicorn";
this -> button2 -> Visible = true;
this -> button2 -> Text = "Pegasus";
YesorNo = 6;
}
else if (YesorNo == 6)
{
Race = "Pegasus";
this -> button2 -> Visible = false;
this -> button4 -> Visible = false;
this -> button5 -> Visible = false;
label2 -> Text = "Thank You For Playing!!";
YesorNo = 7;
this -> timer1 -> Start();
}
}
private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
if (YesorNo == 1)
{
this -> label2 -> Text = "To Make your Pony Character, See PonyMakin.txt in your Retaliation Folder, Your pony should have a invisible background... If not check your background color For your pony!";
button4 -> Text = "Show Pony";
YesorNo = 2;
}
else if ( YesorNo == 2)
{
this -> pictureBox3 -> Visible = true;
this -> pictureBox3 -> Load("Outline Body Model.jpg");
this -> pictureBox2 -> Visible = true;
this -> pictureBox2 -> Load("OutlineModel.jpg");
YesorNo = 3;
this -> textBox1 -> Visible = true;
this -> textBox1 -> Text = "Name?";
this -> button5 -> Visible = false;
this -> button4 -> Visible = false;
this -> label2 -> Visible = false;
}
else if (YesorNo == 5)
{
Gender = "Male";
this -> label2 -> Text = "What is your Race??";
this -> button4 -> Text = "Earth Pony";
this -> button5 -> Text = "Unicorn";
this -> button2 -> Visible = true;
this -> button2 -> Text = "Pegasus";
YesorNo = 6;
}
else if (YesorNo == 6)
{
Race = "Earth_Pony";
this -> button2 -> Visible = false;
this -> button4 -> Visible = false;
this -> button5 -> Visible = false;
label2 -> Text = "Thank You For Playing!!";
YesorNo = 7;
this -> timer1 -> Start();
}
}
private: System::Void button5_Click(System::Object^ sender, System::EventArgs^ e) {
if (YesorNo == 1 || YesorNo == 2)
{
Application::Exit();
}
else if (YesorNo == 4)
{
this -> textBox1 -> Visible = false;
this -> label2 -> Visible = true;
this -> label2 -> Text = "What Is Your Gender?";
this -> button4 -> Text = "Male";
this -> button5 -> Text = "Female";
this -> button4 -> Visible = true;
this -> button5 -> Visible = true;
YesorNo = 5;
}
else if (YesorNo == 5)
{
Gender = "Female";
this -> label2 -> Text = "What is your Race??";
this -> button4 -> Text = "Earth Pony";
this -> button5 -> Text = "Unicorn";
this -> button2 -> Visible = true;
this -> button2 -> Text = "Pegasus";
YesorNo = 6;
}
else if (YesorNo == 6)
{
Race = "Unicorn";
this -> button2 -> Visible = false;
this -> button4 -> Visible = false;
this -> button5 -> Visible = false;
label2 -> Text = "Thank You For Playing!!";
YesorNo = 7;
this -> timer1 -> Start();
}
}
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
this -> button3 -> Text = "None yet";
}
private: System::Void textBox1_TextChanged_1(System::Object^ sender, System::EventArgs^ e) {
this -> label1 -> Visible = true;
CharName = textBox1 -> Text;
label1 -> Text = CharName;
this -> button5 -> Visible = true;
this -> button5 -> Text = "Done?";
YesorNo = 4;
}
private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
TimerValue+= 1000;
if (TimerValue == 5000)
{
Form2 ^ f2 = gcnew Form2;
f2->Show();
this->Hide();
MoviePlay = 1;
StreamWriter^ outFile = gcnew StreamWriter("Movie.txt");
String^ Movie = MoviePlay.ToString();
outFile->Write(Movie);
outFile->Close();
this -> timer1 -> Stop();
}
}
};
}
Why can I not open Form 2?
2010\projects\retaliation\retaliation\Form1.h(431): error C2065: 'Form2' : undeclared identifier
Is refering to...
Form2 ^ f2 = gcnew Form2; at the bottom
Just in case it has to do with a problem in Form2...
#pragma once
#include "stdAfx.h"
#include "Form1.h"
#include "Form2.h"
namespace Retaliation {
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 std;
/// <summary>
/// Summary for Form2
/// </summary>
public ref class Form2 : public System::Windows::Forms::Form
{
public:
int MoviePlay;
Form2(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form2()
{
if (components)
{
delete components;
}
}
private: AxWMPLib::AxWindowsMediaPlayer^ MoviePlayer1;
protected:
protected:
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)
{
System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(Form2::typeid));
this->MoviePlayer1 = (gcnew AxWMPLib::AxWindowsMediaPlayer());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->MoviePlayer1))->BeginInit();
this->SuspendLayout();
//
// MoviePlayer1
//
this->MoviePlayer1->Enabled = true;
this->MoviePlayer1->Location = System::Drawing::Point(0, 0);
this->MoviePlayer1->Name = L"MoviePlayer1";
this->MoviePlayer1->OcxState = (cli::safe_cast<System::Windows::Forms::AxHost::State^ >(resources- >GetObject(L"MoviePlayer1.OcxState")));
this->MoviePlayer1->Size = System::Drawing::Size(860, 497);
this->MoviePlayer1->TabIndex = 0;
this->MoviePlayer1->Enter += gcnew System::EventHandler(this, &Form2::axWindowsMediaPlayer1_Enter);
//
// Form2
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(859, 495);
this->Controls->Add(this->MoviePlayer1);
this->Name = L"Form2";
this->Text = L"Form2";
this->Load += gcnew System::EventHandler(this, &Form2::Form2_Load);
(cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->MoviePlayer1))->EndInit();
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void axWindowsMediaPlayer1_Enter(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void Form2_Load(System::Object^ sender, System::EventArgs^ e) {
if (MoviePlay == 1)
{
MoviePlayer1->URL = "\\Scv183\\Scene1.mpeg";
MoviePlayer1 -> Ctlcontrols -> play();
}
}
};
}
You are getting an error because you have a circular dependency in your header files.
Your compiler is trying to compile Form2.cpp, where you include Form1.h, in Form1.h you include Form2.h, and in Form2.h you include Form1.h. You need to use a forward declaration, or to change your design so that you class are less coupled.
Moreover don't include a headerfile in itself..
More generally, you should not implement your function definitions in header files, but use your .cpp files for that. I also don't think you need to use precompiled headers (stdAfx.h), you should disable the check-box when you create a Visual Studio project.
Follow these steps:
Create a new project. Form1 is created by default.
Create a button on Form1, double click it and paste the code below:
Form2^ testDialog = gcnew Form2;
testDialog->ShowDialog (this);
delete testDialog;
Go to solution explorer, right click the project and add a new Form and save it as Form2.
Double click Form1.cpp and you will see that it starts with the following lines:
#include "stdafx.h"
#include "Form1.h"
Edit it as follows:
#include "stdafx.h"
#include "Form2.h"
#include "Form1.h"
Note: The sequence of #include should not be changed.
Go ahead, run your project and enjoy!!!!
Prasanth
#pragma once
namespace StudentDataSearch {
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:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ btnSearch;
private: System::Windows::Forms::Label^ Course_ID1;
protected:
private: System::Windows::Forms::TextBox^ txtTargetID;
private: System::Windows::Forms::GroupBox^ groupBox1;
private: System::Windows::Forms::TextBox^ txtSeats;
private: System::Windows::Forms::Label^ Seats;
private: System::Windows::Forms::TextBox^ txtID;
private: System::Windows::Forms::Label^ Course_ID;
private: System::Windows::Forms::TextBox^ txtName;
private: System::Windows::Forms::Label^ Course_Names2;
private: System::Windows::Forms::Button^ button1;
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->btnSearch = (gcnew System::Windows::Forms::Button());
this->Course_ID1 = (gcnew System::Windows::Forms::Label());
this->txtTargetID = (gcnew System::Windows::Forms::TextBox());
this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
this->txtSeats = (gcnew System::Windows::Forms::TextBox());
this->Seats = (gcnew System::Windows::Forms::Label());
this->txtID = (gcnew System::Windows::Forms::TextBox());
this->Course_ID = (gcnew System::Windows::Forms::Label());
this->txtName = (gcnew System::Windows::Forms::TextBox());
this->Course_Names2 = (gcnew System::Windows::Forms::Label());
this->button1 = (gcnew System::Windows::Forms::Button());
this->groupBox1->SuspendLayout();
this->SuspendLayout();
//
// btnSearch
//
this->btnSearch->Location = System::Drawing::Point(12, 12);
this->btnSearch->Name = L"btnSearch";
this->btnSearch->Size = System::Drawing::Size(144, 39);
this->btnSearch->TabIndex = 0;
this->btnSearch->Text = L"Search by Course ID";
this->btnSearch->UseVisualStyleBackColor = true;
this->btnSearch->Click += gcnew System::EventHandler(this, &Form1::btnSearch_Click);
//
// Course_ID1
//
this->Course_ID1->AutoSize = true;
this->Course_ID1->Location = System::Drawing::Point(317, 28);
this->Course_ID1->Name = L"Course_ID1";
this->Course_ID1->Size = System::Drawing::Size(54, 13);
this->Course_ID1->TabIndex = 1;
this->Course_ID1->Text = L"Course ID";
//
// txtTargetID
//
this->txtTargetID->Location = System::Drawing::Point(377, 25);
this->txtTargetID->Name = L"txtTargetID";
this->txtTargetID->Size = System::Drawing::Size(100, 20);
this->txtTargetID->TabIndex = 2;
//
// groupBox1
//
this->groupBox1->Controls->Add(this->txtSeats);
this->groupBox1->Controls->Add(this->Seats);
this->groupBox1->Controls->Add(this->txtID);
this->groupBox1->Controls->Add(this->Course_ID);
this->groupBox1->Controls->Add(this->txtName);
this->groupBox1->Controls->Add(this->Course_Names2);
this->groupBox1->Location = System::Drawing::Point(12, 145);
this->groupBox1->Name = L"groupBox1";
this->groupBox1->Size = System::Drawing::Size(465, 140);
this->groupBox1->TabIndex = 3;
this->groupBox1->TabStop = false;
this->groupBox1->Text = L"Search Results";
//
// txtSeats
//
this->txtSeats->Location = System::Drawing::Point(301, 81);
this->txtSeats->Name = L"txtSeats";
this->txtSeats->Size = System::Drawing::Size(100, 20);
this->txtSeats->TabIndex = 5;
//
// Seats
//
this->Seats->AutoSize = true;
this->Seats->Location = System::Drawing::Point(298, 65);
this->Seats->Name = L"Seats";
this->Seats->Size = System::Drawing::Size(34, 13);
this->Seats->TabIndex = 4;
this->Seats->Text = L"Seats";
//
// txtID
//
this->txtID->Location = System::Drawing::Point(204, 81);
this->txtID->Name = L"txtID";
this->txtID->Size = System::Drawing::Size(91, 20);
this->txtID->TabIndex = 3;
//
// Course_ID
//
this->Course_ID->AutoSize = true;
this->Course_ID->Location = System::Drawing::Point(206, 65);
this->Course_ID->Name = L"Course_ID";
this->Course_ID->Size = System::Drawing::Size(54, 13);
this->Course_ID->TabIndex = 2;
this->Course_ID->Text = L"Course ID";
//
// txtName
//
this->txtName->Location = System::Drawing::Point(25, 81);
this->txtName->Name = L"txtName";
this->txtName->Size = System::Drawing::Size(173, 20);
this->txtName->TabIndex = 1;
//
// Course_Names2
//
this->Course_Names2->AutoSize = true;
this->Course_Names2->Location = System::Drawing::Point(22, 65);
this->Course_Names2->Name = L"Course_Names2";
this->Course_Names2->Size = System::Drawing::Size(71, 13);
this->Course_Names2->TabIndex = 0;
this->Course_Names2->Text = L"Course Name";
//
// button1
//
this->button1->Location = System::Drawing::Point(12, 57);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(144, 39);
this->button1->TabIndex = 4;
this->button1->Text = L"Search by Course Name";
this->button1->UseVisualStyleBackColor = true;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(519, 297);
this->Controls->Add(this->button1);
this->Controls->Add(this->groupBox1);
this->Controls->Add(this->txtTargetID);
this->Controls->Add(this->Course_ID1);
this->Controls->Add(this->btnSearch);
this->Name = L"Form1";
this->Text = L"Student Data Search";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->groupBox1->ResumeLayout(false);
this->groupBox1->PerformLayout();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
private: array<String^>^ CourseArr;
private: array<String^>^ CourseID;
private: array<Int32^>^ SeatsArr;
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
// Course Names
CourseArr = gcnew array<String^>(9);
CourseArr->SetValue("Computer Sci 1511", 0);
CourseArr->SetValue("Computer Sci 1521", 1);
CourseArr->SetValue("Composition 1120", 2);
CourseArr->SetValue("Math 1296", 3);
CourseArr->SetValue("Physics 1120", 4);
CourseArr->SetValue("Biology 1100", 5);
CourseArr->SetValue("Chemistry 1100", 6);
CourseArr->SetValue("Anthropology 1210", 7);
CourseArr->SetValue("Economics 1000", 8);
// Course ID
CourseID = gcnew array<String^>(9);
CourseID->SetValue("123", 0);
CourseID->SetValue("124", 1);
CourseID->SetValue("135", 2);
CourseID->SetValue("145", 3);
CourseID->SetValue("146", 4);
CourseID->SetValue("149", 5);
CourseID->SetValue("155", 6);
CourseID->SetValue("162", 7);
CourseID->SetValue("175", 8);
//Seats Avaliable
SeatsArr->SetValue("0", 0);
SeatsArr->SetValue("25", 1);
SeatsArr->SetValue("14", 2);
SeatsArr->SetValue("5", 3);
SeatsArr->SetValue("0", 4);
SeatsArr->SetValue("20", 5);
SeatsArr->SetValue("17", 6);
SeatsArr->SetValue("0", 7);
SeatsArr->SetValue("12", 8);
}
private: System::Void btnSearch_Click(System::Object^ sender, System::EventArgs^ e) {
Error below here ----------------------------------------------
I have set up a few array to gather information and so far I have set values to my 3 arrays and set up a for loop to run through the arrays and pick out the desired information based on what is put into my textbox Course ID but it's not printing anything and I'm not sure why I thought by assigning the arrays to variables and then putting the variables in the text box that would work and at this point I am beyond lost and I know my explanation isn't necessarily helpful but all help is appreciated
int course;
int id;
int seats;
for (int i = 0; i < course; i++)
{
txtName->Text = CourseArr[i]->ToString();
txtID->Text =CourseID[i]->ToString();
txtSeats->Text = SeatsArr[i]->ToString();
course = CourseArr[i]->ToString();
id = CourseID[i]->ToString();
seats = SeatsArr[i]->ToString();
}
}
};
}
Your first error is trying to put strings in an array of integers. Also, why did you declare an array of boxed integers?
And why use SetValue instead of indexing the array normally?
#pragma once
namespace VendingMachine {
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:
Form1(void)
{
InitializeComponent();
//
//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;
private: System::Windows::Forms::TextBox^ textBox1;
protected:
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::Button^ button2;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::Label^ label4;
private: System::Windows::Forms::Label^ label5;
private: System::Windows::Forms::Label^ label6;
private: System::Windows::Forms::Label^ label7;
private: System::Windows::Forms::TextBox^ textBox2;
private: System::Windows::Forms::TextBox^ textBox3;
private: System::Windows::Forms::TextBox^ textBox4;
private: System::Windows::Forms::TextBox^ textBox5;
private: System::Windows::Forms::TextBox^ textBox6;
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->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->button2 = (gcnew System::Windows::Forms::Button());
this->label2 = (gcnew System::Windows::Forms::Label());
this->label3 = (gcnew System::Windows::Forms::Label());
this->label4 = (gcnew System::Windows::Forms::Label());
this->label5 = (gcnew System::Windows::Forms::Label());
this->label6 = (gcnew System::Windows::Forms::Label());
this->label7 = (gcnew System::Windows::Forms::Label());
this->textBox2 = (gcnew System::Windows::Forms::TextBox());
this->textBox3 = (gcnew System::Windows::Forms::TextBox());
this->textBox4 = (gcnew System::Windows::Forms::TextBox());
this->textBox5 = (gcnew System::Windows::Forms::TextBox());
this->textBox6 = (gcnew System::Windows::Forms::TextBox());
this->SuspendLayout();
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(14, 14);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(153, 13);
this->label1->TabIndex = 0;
this->label1->Text = L"Amount of change (0-99 cents)";
//
// textBox1
//
this->textBox1->Location = System::Drawing::Point(173, 11);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(95, 20);
this->textBox1->TabIndex = 1;
//
// button1
//
this->button1->Location = System::Drawing::Point(20, 59);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(60, 28);
this->button1->TabIndex = 2;
this->button1->Text = L"Calculate";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// button2
//
this->button2->Location = System::Drawing::Point(190, 59);
this->button2->Name = L"button2";
this->button2->Size = System::Drawing::Size(63, 28);
this->button2->TabIndex = 3;
this->button2->Text = L"Clear";
this->button2->UseVisualStyleBackColor = true;
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(14, 132);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(99, 13);
this->label2->TabIndex = 4;
this->label2->Text = L"Number of Quarters";
//
// label3
//
this->label3->AutoSize = true;
this->label3->Location = System::Drawing::Point(14, 178);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(88, 13);
this->label3->TabIndex = 5;
this->label3->Text = L"Number of Dimes";
//
// label4
//
this->label4->AutoSize = true;
this->label4->Location = System::Drawing::Point(14, 218);
this->label4->Name = L"label4";
this->label4->Size = System::Drawing::Size(0, 13);
this->label4->TabIndex = 6;
//
// label5
//
this->label5->AutoSize = true;
this->label5->Location = System::Drawing::Point(14, 215);
this->label5->Name = L"label5";
this->label5->Size = System::Drawing::Size(94, 13);
this->label5->TabIndex = 7;
this->label5->Text = L"Number of Nickels";
//
// label6
//
this->label6->AutoSize = true;
this->label6->Location = System::Drawing::Point(14, 256);
this->label6->Name = L"label6";
this->label6->Size = System::Drawing::Size(96, 13);
this->label6->TabIndex = 8;
this->label6->Text = L"Number of pennies";
//
// label7
//
this->label7->AutoSize = true;
this->label7->Location = System::Drawing::Point(14, 301);
this->label7->Name = L"label7";
this->label7->Size = System::Drawing::Size(59, 13);
this->label7->TabIndex = 9;
this->label7->Text = L"Total coins";
//
// textBox2
//
this->textBox2->Location = System::Drawing::Point(173, 129);
this->textBox2->Name = L"textBox2";
this->textBox2->Size = System::Drawing::Size(95, 20);
this->textBox2->TabIndex = 10;
//
// textBox3
//
this->textBox3->Location = System::Drawing::Point(173, 178);
this->textBox3->Name = L"textBox3";
this->textBox3->Size = System::Drawing::Size(95, 20);
this->textBox3->TabIndex = 11;
//
// textBox4
//
this->textBox4->Location = System::Drawing::Point(173, 215);
this->textBox4->Name = L"textBox4";
this->textBox4->Size = System::Drawing::Size(95, 20);
this->textBox4->TabIndex = 12;
//
// textBox5
//
this->textBox5->Location = System::Drawing::Point(173, 253);
this->textBox5->Name = L"textBox5";
this->textBox5->Size = System::Drawing::Size(95, 20);
this->textBox5->TabIndex = 13;
//
// textBox6
//
this->textBox6->Location = System::Drawing::Point(173, 294);
this->textBox6->Name = L"textBox6";
this->textBox6->Size = System::Drawing::Size(95, 20);
this->textBox6->TabIndex = 14;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 338);
this->Controls->Add(this->textBox6);
this->Controls->Add(this->textBox5);
this->Controls->Add(this->textBox4);
this->Controls->Add(this->textBox3);
this->Controls->Add(this->textBox2);
this->Controls->Add(this->label7);
this->Controls->Add(this->label6);
this->Controls->Add(this->label5);
this->Controls->Add(this->label4);
this->Controls->Add(this->label3);
this->Controls->Add(this->label2);
this->Controls->Add(this->button2);
this->Controls->Add(this->button1);
this->Controls->Add(this->textBox1);
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) {
// Declare variables
double change, quarters, dimes, nickels, pennies, total_coins;
// Read in data
Double::TryParse(textBox1->Text, change);
Double::TryParse(textBox2->Text, quarters);
Double::TryParse(textBox3->Text, dimes);
Double::TryParse(textBox4->Text, nickels);
Double::TryParse(textBox5->Text, pennies);
the issue is in the Process data section of my code
// Process data
change = change; 0 - 99;
textBox1->Text = change.ToString();
MessageBox::Show(change.ToString());
/*error-I-need-a-whole-number ->*/quarters += change / 25;
MessageBox::Show(quarters.ToString());
// current code above gives me an answer of 3.48 when change equals 87
// Display results
textBox6->Text = total_coins.ToString();
textBox2->Text = quarters.ToString();
}
};
}
Looking past the awkward lines that accomplish nothing like change = change; 0 - 99;, what you want to do is use the int type for your quantities.
Why should you use a double for those quantities anyway? Have you ever heard of a fraction of a quarter or a dime? Make them all of type int. (change is representing cents, not dollars, so making it an int makes sense.)
If you use int, 87 / 25 will be truncated to 3 quarters, which is the result you're expecting.