|
He, he, he...it's the magic touch of stupidity. You'd be surprized how many ridiculous programming stunts I pull . It's been a long time since I've programmed in anything that wasn't for the web...I'm very rusty....
~Cam Desautels (BinaryUprising.com)
|
|
|
|
|
I'm very new to C++ and need to build a program that performs simple multiplication in edit boxes, there are three allowing the user to enter numerals in 2 and the result being displayed in the third. My problem is, I cannot for the life of me figure out how to correct a mistake I must have made. I keep getting the errors:"error C2440: '=' : cannot convert from 'char [1]' to 'float'". I assume I am supposed to convert somehow the inputs from char to float. Any assistance would be appreciated. I was told by someone something about atoi atof, and have searched for these things in my MSDN to no avail. Am I maybe declaring my variables wrong?
|
|
|
|
|
First of all, if you defined your edit boxes as variables rather than controls, you were then able to define them as numbers instead of strings. You can delete them and recreate them as such, if you like. If you created them as controls, then you'd need to get their text with GetWindowText, and you will need to convert a string to a number.
Every MSDN ever will cover atoi and atof, I dunno what the problem is there - even if I tick 'search titles only' I get 5 matches. atoi converts Ascii TO Integer, and atof converts Ascii TO Floating point (float or double ).
Finally, if you're using variables directly for your values, you need to remember to call UpdateData() to update those values before using them, and UpdateData(false) to pass the value back in for the result. If you were using a string, or using SetWindowText in a control, CString has a method called format that takes the same arguements as sprintf, namely you can get a string representation of an integer, i and a float, f like this:
CString s;
s.Format("My int = %d, my float = %f, my float with 2 decimal points = %.2f", i, f, f);
I hope that helps.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
If you didn't follow what the last guy said, I'll try to make it a little simpler. I'm a newbie myself, but I could write the program you're writing . First off, about atoi atof, these are C/C++ library functions. Basically that means they are prewritten functions that you can call from your program if you so please. They, respectively, convert an ASCII char(acter) to int(eger), or an ASCII char(acter) to a float(ing point number). But screw those for now
When you wrote your program, odds are you made a dialog in the resource editor, then you threw some edit boxes onto it. Next you ran ClassWizard to assign member variables to them. But the problem is that you assigned the wrong type of variables to them. So, to fix all this, open Visual Studio, and hit Ctrl+W. Click the "member variables" tab. Now there should be a list. On the left you will see them names of your edit boxes. Select one of your edit boxes, and click "Delete Variable". Then click "Add Variable" choose the name you would like for the variable (would be best to use the same name you used before so you don't have to recode), make sure "Value" is selected in the next box down, and then make sure "int" is selected in the bottom box. Now press 'Ok'. Repeat this process for all three of your edit boxes, and you should be all set.
----
I need to append something to this. When I first started programming in VC++ I made a program like that, and annoyed the hell out of myself because all of the code seemed right, and I got no errors, but it would never display! In case this is happening to you, here's the explanation. The data typed in to an edit box isn't actually stored directly into the member variable we supply for that purpose. We have to call the UpdateData() function to get what's in the window and put it into the variable. UpdateData takes one parameter, either TRUE or FALSE; UpdateData(TRUE) takes the data that is in the window, and puts it into the variables. UpdateData(FALSE) does the exact opposite, it updates the window. So, when your user clicks the multiply button, we need to do something like this:
void CMyProgDlg::OnMultiply()
{
// TODO: Add your control notification handler code
UpdateData(TRUE); //Puts data in member variables
m_Sum = m_NumOne * m_NumTwo; //multiplies
UpdateData(FALSE); //Puts data to screen
}
Anyway, just hoping to say you a headache. I just spent two minutes or so throwing together a program that doe exactly what you want yours to do. If you find yourself needing more help, download it from this link.
~Cam Desautels (www.BinaryUprising.com), always welcome to help out the new ones
|
|
|
|
|
I am taking a little course in C++ and my instructor tols me that my problem has to do with the way I am declaring my variables. I used the class wizard and made the variables as catagory Value, and Variable type float. I made sure my Updatedata(); commands were right, and I still get these errors. Since we haven't covered the atoi/atof topics yet I assume the problem is how the variables or functions are declared. This is pretty stressful, considering I'd like to get this right so I can be where you are and help someone later on. Is there anything else I might be overlooking? I really appreciate your assistance. Thanks.
|
|
|
|
|
Ok, please re-read my reply if you haven't seen what I appended to it. Another thing I would recommend doing is in the resource editor (where you can edit your dialog box), right click your edit boxes, click the 'Styles' tab, and check 'Number'. Then only numbers can be typed into the box. That's no explanation for your compiling errors, but it will save you time later, so you won't have to write error-checking routines to make sure your user typed in a number. If all else fails, make sure to check out the sample prog I linked to in my last post.
~Cam Desautels
|
|
|
|
|
Cam, I really appreciate all your assistance. I hoipe to repay you someday somehow. I downloaded the file you attatched and after it downloaded I tried unzipping it and received the error message "file is multipart or corrupt. Thank you for the attempt.
|
|
|
|
|
drat...sorry about that. I'm uploading the corrected version of the file right now. It ought to be at the same exact location by the time you recieve this, so just follow the original link if you'd like to download it.
~Cam Desautels (BinaryUprising.com)
|
|
|
|
|
If you made the variables of type float, then you need to make sure that only numbers are being entered into the edit boxes. Sadly, if you click the option in the edit box properties to make the value a number, you will only get int's, the decimal point will also be supressed.
You really should consider posting some code when asking for help. I suspect if I saw the code I'd probably know what you were doing wrong.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
Christian, Thanks an aweful lot for helping me. I REALLY appreciate it.
|
|
|
|
|
If you made the variables of type float, then you need to make sure that only numbers are being entered into the edit boxes. Sadly, if you click the option in the edit box properties to make the value a number, you will only get int's, the decimal point will also be supressed. However, if the values are ALL set to be floats, there is no char to float conversion happening at ALL, so I doubt you've got that bit right, or if you have, the problem is elsewhere and you should be posting the code where it crashes.
You really should consider posting some code when asking for help. I suspect if I saw the code I'd probably know what you were doing wrong.
Christian
After all, there's nothing wrong with an elite as long as I'm allowed to be part of it!! - Mike Burston Oct 23, 2001
Sonork ID 100.10002:MeanManOzI live in Bob's HungOut now
|
|
|
|
|
True, true, sorry about that...int math was simpler...
~Cam Desautels (BinaryUprising.com)
|
|
|
|
|
You might want to have a look at this little article. It is a set of classes built to take numeric input from edit boxes and it handles a lot of those messy details for you. There are facilities to use sliders also but you don't have to.
I hope this helps.
|
|
|
|
|
But it's so simple, really. And the point is to learn. Once he gets it down he'll be pumping these things out in no time, and wondering what was slowin' him down before.
~Cam Desautels (BinaryUprising.com)
|
|
|
|
|
You guys are awesome, Thanks for your help!!
|
|
|
|
|
|
Cam, I'm sorry I didn't say. Yes, I got it owkring. Thanks a lot for your help! It's impressive to see that there are people out there that seem to REALLY care. Your code and that srticle that Rich sent me to set me right. THANKS! By the way, GREAT web site!
|
|
|
|
|
Sorry about the typos, I'm pretty tired now.
|
|
|
|
|
Sorry about the typos, I'm really tired now. Good night
|
|
|
|
|
Ok, very cool, very cool...no problem about the help, I'm a struggling C++ programmer myself (yeah, but what the heck, I'm 17, it'll come...), and if I help others with what I can, maybe someone can help me when the time comes. Thanks a lot about my site, I have a lot of fun with webdev. Did you see there's a little text box on the right-hand side of the homepage where you can post comments (hint, hint). LOL, anyway, the best of luck to you, I'm glad I could help.
~Cam Desautels (BinaryUprising.com)
|
|
|
|
|
i have created a new project with a recordset.
with the toolbar that the wizard supplied i can navigate throught the records but i can not figure out where i can update controls on my dialog when navigating.
thank you for any help
|
|
|
|
|
Hi,
U have to use the Recordset to bind the dilaog controls to the
recordset fields.
U can do this by the RFX_ macros and attaching by using the DDX macros
by hand, that's a little tediuos, but
u can do automatically in the following manner.
1. When the Dialog is open in the Resource Window.
2. Select a control and open class Wizard(Ctrl+W)
3. Then depending on the control u selected and to the
field u want to display in the control
4. Select the control and go to the 'Members Variables' tab
5. Select the control and press 'Add Variable'
6. In the Member vaiable name --> Select the Recordset field u want
to associate.
Phew,
Thats all.
|
|
|
|
|
thank you could not be easier
|
|
|
|
|
can i cast a member func ptr to global func ptr
(without a compilation error...)?
typedef void (*Func)();
class Moo{
void Do();
void Cast_A_Func(){ m_fn = (Func)(void*)Do; } //Or something like that...
Func m_fn;
};
--BlackSmith--
"With the help of all mighty", 2001, Me.
|
|
|
|
|
No, because member functions have 'this' as their first argument (although you don't write it that way). Your code will work only if Do() is static, since static methods have no this pointer.
--Mike--
http://home.inreach.com/mdunn/
"Not our fault we are intellectually superior to the rest of the office." -- Paul Watson in the Lounge, 12/12/2001
Sonork - 100.10414 AcidHelm
|
|
|
|
|