Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Edit Box Variables

Edit Box Variables

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++tutorialquestion
19 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    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?:confused:

    C Offline
    C Offline
    Cam
    wrote on last edited by
    #3

    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 :-D 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 need

    L 1 Reply Last reply
    0
    • C Cam

      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 :-D 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 need

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #4

      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.:confused:

      C C 3 Replies Last reply
      0
      • L Lost User

        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.:confused:

        C Offline
        C Offline
        Cam
        wrote on last edited by
        #5

        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

        L 1 Reply Last reply
        0
        • C Cam

          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

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #6

          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.

          C 1 Reply Last reply
          0
          • L Lost User

            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?:confused:

            R Offline
            R Offline
            Rick York
            wrote on last edited by
            #7

            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.

            C 1 Reply Last reply
            0
            • L Lost User

              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.

              C Offline
              C Offline
              Cam
              wrote on last edited by
              #8

              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)

              1 Reply Last reply
              0
              • R Rick York

                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.

                C Offline
                C Offline
                Cam
                wrote on last edited by
                #9

                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)

                L 1 Reply Last reply
                0
                • C Cam

                  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)

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #10

                  You guys are awesome, Thanks for your help!!:-D

                  C 1 Reply Last reply
                  0
                  • L Lost User

                    You guys are awesome, Thanks for your help!!:-D

                    C Offline
                    C Offline
                    Cam
                    wrote on last edited by
                    #11

                    Did you get it working??? ~Cam Desautels (BinaryUprising.com)

                    L 1 Reply Last reply
                    0
                    • L Lost User

                      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.:confused:

                      C Offline
                      C Offline
                      Christian Graus
                      wrote on last edited by
                      #12

                      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:MeanManOz

                      I live in Bob's HungOut now

                      L 1 Reply Last reply
                      0
                      • C Cam

                        Did you get it working??? ~Cam Desautels (BinaryUprising.com)

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #13

                        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!

                        L C 3 Replies Last reply
                        0
                        • L Lost User

                          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.:confused:

                          C Offline
                          C Offline
                          Christian Graus
                          wrote on last edited by
                          #14

                          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:MeanManOz

                          I live in Bob's HungOut now

                          C 1 Reply Last reply
                          0
                          • L Lost User

                            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!

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #15

                            Sorry about the typos, I'm pretty tired now.

                            1 Reply Last reply
                            0
                            • L Lost User

                              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!

                              L Offline
                              L Offline
                              Lost User
                              wrote on last edited by
                              #16

                              Sorry about the typos, I'm really tired now. Good night

                              1 Reply Last reply
                              0
                              • C Christian Graus

                                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:MeanManOz

                                I live in Bob's HungOut now

                                L Offline
                                L Offline
                                Lost User
                                wrote on last edited by
                                #17

                                Christian, Thanks an aweful lot for helping me. I REALLY appreciate it.

                                1 Reply Last reply
                                0
                                • C Christian Graus

                                  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:MeanManOz

                                  I live in Bob's HungOut now

                                  C Offline
                                  C Offline
                                  Cam
                                  wrote on last edited by
                                  #18

                                  True, true, sorry about that...int math was simpler... ~Cam Desautels (BinaryUprising.com)

                                  1 Reply Last reply
                                  0
                                  • L Lost User

                                    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!

                                    C Offline
                                    C Offline
                                    Cam
                                    wrote on last edited by
                                    #19

                                    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)

                                    1 Reply Last reply
                                    0
                                    Reply
                                    • Reply as topic
                                    Log in to reply
                                    • Oldest to Newest
                                    • Newest to Oldest
                                    • Most Votes


                                    • Login

                                    • Don't have an account? Register

                                    • Login or register to search.
                                    • First post
                                      Last post
                                    0
                                    • Categories
                                    • Recent
                                    • Tags
                                    • Popular
                                    • World
                                    • Users
                                    • Groups