two question - Big newb needs help
So im using visual basic C++ GUI (playing around) and started making a calculator.
So most of the code is in the .h file, I can put it here but its super long so I was wondering where do I place my classes.
I tried putting it before the section you edit the buttons
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
Lblcalc->Text = "+";
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
Lblcalc->Text = "-";
}
private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
Lblcalc->Text = "*";
}
private: System::Void button4_Click(System::Object^ sender, System::EventArgs^ e) {
Lblcalc->Text = "/";
}
private: System::Void Btn1_Click(System::Object^ sender, System::EventArgs^ e) {
if (Lblcalc->Text == "0"){
Lblcalc->Text = "1";
}
else {
Lblcalc->Text = Convert::ToInt32(Lblcalc->Text) + "1";
}
}
};
}
| |
So basically before that but if you still dont get it I can post the whole code
let me ask another question. so for every number button (e.g. button 1) will need to display its number and the way its done by
1 2 3 4 5 6 7 8 9
|
private: System::Void Btn1_Click(System::Object^ sender, System::EventArgs^ e) {
if (Lblcalc->Text == "0"){
Lblcalc->Text = "1";
}
else {
Lblcalc->Text = Convert::ToInt32(Lblcalc->Text) + "1";
}
| |
but I thought instead of copy and pasting it multiple times I can make a class for it, is this how its done?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
class numbers{
public:
void num();
};
numbers::num(int x){
if (Lblcalc->Text == "0"){
Lblcalc->Text = x;
}
else {
Lblcalc->Text = Convert::ToInt32(Lblcalc->Text) +x;
}
}
| |
then I can just do
1 2 3 4 5
|
[code]private: System::Void Btn1_Click(System::Object^ sender, System::EventArgs^ e) {
numbers one
one.num(1)
| |
will that work?
Topic archived. No new replies allowed.