Hello! I'm trying to make a simple calculator in Visual C++ and while coding the decimal button, I encountered the error C2228.
Basically, I'm checking if the textBox1 (its name!) already contains a '.'; if yes, then it should return; else, it'll add a '.'.

To check for that, I use:

private: System::Void button18_Click(System::Object^  sender, System::EventArgs^  e) {
			 if (textBox1->Text.Contains("."))
			 {
				 return;
			 }  
			 else
			 {
				 textBox1->Text = textBox1->Text + ".";
			 }

Any ideas?
Here's a picture:
http://i26.tinypic.com/24y9qqe.png

Thank you, forum! :)

Recommended Answers

All 3 Replies

Thank you for your input, Danny_501.
However - after some trial and error - I finally got it. And it works well! :D

For future references,

private: System::Void button18_Click(System::Object^  sender, System::EventArgs^  e) {
			 if (textBox1->Text->Contains("."))
			 {
				 return;
			 }  
			 else
			 {
				 textBox1->Text = textBox1->Text + ".";
			 }
		 }

Basically, no '.'s in C++. :P

oh lol. As I said I'm not familiar with Visual C++. Have only used Unix compilers all my programming life (except for assignments :P).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.