Jump to content

Help w/ visual C++

- - - - -

  • Please log in to reply
2 replies to this topic

#1
Osnarf

Osnarf

    Learning Programmer

  • Members
  • PipPipPip
  • 31 posts
Hi everybody.

I'm just trying to make a small one-form program to calculate grades for a class (the grading system is ridiculous nobody could figure it out :P I told the teacher I'd make a program he could distribute with the syllabus). The problem is I only know C - I've never done any C++. I wanted to make it as a form instead of a console, though. Most people in the class would probably feel awkward working with a console-program.

I made a form, and when I tried to access the text field of a text box in a button's "click" event, using

this->textBox22->text = L"A"

it gave me an error. I'm not near the code right now but I remember it was an error telling me I couldn't access it because it was declared as private. I dont know what that means, but I did a find-replace to change every private to a public. It's not pretty but it will work for now, lol.

It worked, and i tried to convert the text field to a double, with atof(this->textBox22->text), but it gave me an error. I don't remember what that error was, though, and I can't get it to occur again because now it's giving me the error about accessing a private member again. The word private doesn't occur once in the code.

Any ideas?

#2
outsid3r

outsid3r

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 623 posts
Yes, i have an ideia.

Cprogramming.com - Programming Tutorials: C++ Made Easy and C Made Easy

#3
Firebird_38

Firebird_38

    Programmer

  • Members
  • PipPipPipPip
  • 126 posts
We're talking object oriented now.

And you're not allowed to touch "text" because it ain't for you to touch. Just because it's stored there, doesn't mean you can have access to it.

Changing it to public will not work. You may be able to compile it, but simply storing something else there isn't going to update the screen. Besides, you need to keep your hands off of this code. It's not only not pretty, you may have reinstall your C++ now, because messing up the standard code will mess up ALL apps created with it.

To alter it, you must use methods. I think set_text may work, but I can't be sure, so look in the help. In any case, this will alter not only the stored "text" value, but also the text on your screen.

Changing it to double cannot and will not work. The edit box on your screen is a text edit box, not a double edit box. As such it stores text. To turn this into a double, you muist convert it. You also must validate the input, as people can enter "Hello" if they feel like it.

The fact that you're required to call a method, which is just a function operating on the object, is called encapsulation. This means that you are to keep your hands out of the gory details so as not to mess them up. Your benefit is that you are granted usage of this edit box without having to worry about being able to screw it up. But if you mess with the source, you're screwing it up, and quite purposely so.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users