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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Please help in c++

Please help in c++

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialc++helpquestion
11 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.
  • N Offline
    N Offline
    Neil Jigger
    wrote on last edited by
    #1

    How to link a radio button to a command button to get an answer in the edit box? example: a 3 radio buttons (10% discount, 5% penalty and 10% penalty) if supposing i will chose the first radio button (10% penalty) how to write the code so that by clicking the command button (compute) a result will be displayed in the edit box and wo with the other radio buttons? Im new in c++ Thank you so much. Neil

    _ 1 Reply Last reply
    0
    • N Neil Jigger

      How to link a radio button to a command button to get an answer in the edit box? example: a 3 radio buttons (10% discount, 5% penalty and 10% penalty) if supposing i will chose the first radio button (10% penalty) how to write the code so that by clicking the command button (compute) a result will be displayed in the edit box and wo with the other radio buttons? Im new in c++ Thank you so much. Neil

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      I'm assuming you're using MFC. Make sure the radio buttons belong to the same group. You can do this by setting the group property of the first radio button to true. And the rest of the radio button must follow the first in order. Now associate an int variable with the first radio button by right clicking on it and selecting "Add Variable". Similarly associate an int variable with the edit box. In the button click handler, first call UpdateData. This will update the UI selection to the variables just added. Check the value of the radio button variable to determine the option selected. It will be 0 for first, 1 for second and so on. Do your calculation and set the result to the variable associated with the edit box. Finally call UpdateData(FALSE) to set the variables back to the UI.

      «_Superman_» I love work. It gives me something to do between weekends.

      N 1 Reply Last reply
      0
      • _ _Superman_

        I'm assuming you're using MFC. Make sure the radio buttons belong to the same group. You can do this by setting the group property of the first radio button to true. And the rest of the radio button must follow the first in order. Now associate an int variable with the first radio button by right clicking on it and selecting "Add Variable". Similarly associate an int variable with the edit box. In the button click handler, first call UpdateData. This will update the UI selection to the variables just added. Check the value of the radio button variable to determine the option selected. It will be 0 for first, 1 for second and so on. Do your calculation and set the result to the variable associated with the edit box. Finally call UpdateData(FALSE) to set the variables back to the UI.

        «_Superman_» I love work. It gives me something to do between weekends.

        N Offline
        N Offline
        Neil Jigger
        wrote on last edited by
        #3

        Superman please show me sample code on how to do it? I can only compute the result under command button but when i select one radio button nothing will happend, i do not know how to connect radio button and command button to get the result. Please... neil

        C 1 Reply Last reply
        0
        • N Neil Jigger

          Superman please show me sample code on how to do it? I can only compute the result under command button but when i select one radio button nothing will happend, i do not know how to connect radio button and command button to get the result. Please... neil

          C Offline
          C Offline
          Chandrasekharan P
          wrote on last edited by
          #4

          Superman has given a very good explanation on how to implement this problem. Go Ahead and do the implementation. i am sure it is not a difficult task to complete. When you are stuck there are people to help you. On selecting the radio button you can pass the value to the function in the command button which does the calculation and display the result in the textbox.

          N 1 Reply Last reply
          0
          • C Chandrasekharan P

            Superman has given a very good explanation on how to implement this problem. Go Ahead and do the implementation. i am sure it is not a difficult task to complete. When you are stuck there are people to help you. On selecting the radio button you can pass the value to the function in the command button which does the calculation and display the result in the textbox.

            N Offline
            N Offline
            Neil Jigger
            wrote on last edited by
            #5

            thanks for the reply... my problem is that i dont have a sample code on how to pass the value of the function to the command button. If i tried to use if else statement the system will say syntax error :( here is my sample code: UpdateData(); if m_button1.Select = true m_edit2 = 0; else m_edit2 = m_edit1 * .9; UpdateData(false); i cant connect to the radio button...please help me... thank you and i will wait for a reply. neil

            C D 2 Replies Last reply
            0
            • N Neil Jigger

              thanks for the reply... my problem is that i dont have a sample code on how to pass the value of the function to the command button. If i tried to use if else statement the system will say syntax error :( here is my sample code: UpdateData(); if m_button1.Select = true m_edit2 = 0; else m_edit2 = m_edit1 * .9; UpdateData(false); i cant connect to the radio button...please help me... thank you and i will wait for a reply. neil

              C Offline
              C Offline
              Chandrasekharan P
              wrote on last edited by
              #6

              C

              Neil Jigger wrote:

              how to pass the value of the function to the command button.

              Create a Global variable. assign the value and then pass the value to the command button. and why are you using an if-else statement for this?

              N 1 Reply Last reply
              0
              • C Chandrasekharan P

                C

                Neil Jigger wrote:

                how to pass the value of the function to the command button.

                Create a Global variable. assign the value and then pass the value to the command button. and why are you using an if-else statement for this?

                N Offline
                N Offline
                Neil Jigger
                wrote on last edited by
                #7

                hehehe...that's the reason why i posted this query because i only have little knowledge on c++. I am still on the process of studying this language. Please sir give me website to where i can look for sample codes on c++. I really need samples very badly... thank you again. neil

                C 1 Reply Last reply
                0
                • N Neil Jigger

                  hehehe...that's the reason why i posted this query because i only have little knowledge on c++. I am still on the process of studying this language. Please sir give me website to where i can look for sample codes on c++. I really need samples very badly... thank you again. neil

                  C Offline
                  C Offline
                  Chandrasekharan P
                  wrote on last edited by
                  #8

                  Search radio button in Code Project. there are lots of examples. Check this link for example on Radio Button [^]

                  1 Reply Last reply
                  0
                  • N Neil Jigger

                    thanks for the reply... my problem is that i dont have a sample code on how to pass the value of the function to the command button. If i tried to use if else statement the system will say syntax error :( here is my sample code: UpdateData(); if m_button1.Select = true m_edit2 = 0; else m_edit2 = m_edit1 * .9; UpdateData(false); i cant connect to the radio button...please help me... thank you and i will wait for a reply. neil

                    D Offline
                    D Offline
                    David Crow
                    wrote on last edited by
                    #9

                    Lose the calls to UpdateData(). They are completely unnecessary and only add to your confusion. You can easily have a CButton member variable associated with each radio button, and can call the button's GetCheck() method to see if it is checked or not. BTW, when pasting code snippets, see #5 here. As it is, your code will not compile.

                    "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                    "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                    N 1 Reply Last reply
                    0
                    • D David Crow

                      Lose the calls to UpdateData(). They are completely unnecessary and only add to your confusion. You can easily have a CButton member variable associated with each radio button, and can call the button's GetCheck() method to see if it is checked or not. BTW, when pasting code snippets, see #5 here. As it is, your code will not compile.

                      "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                      N Offline
                      N Offline
                      Neil Jigger
                      wrote on last edited by
                      #10

                      thanks david for your reply. i cannot continue with my code for the reason that i dont have enough knowledge on it. My code is successful if i will not use radio button in getting the reasult but when i used a radion button to connect to the command button i cannot successfully link to it coz i dont know the code on how to do it. I just need a sample code for my reference...can u send sample code to connect the radio button to a command button please...? Neil

                      D 1 Reply Last reply
                      0
                      • N Neil Jigger

                        thanks david for your reply. i cannot continue with my code for the reason that i dont have enough knowledge on it. My code is successful if i will not use radio button in getting the reasult but when i used a radion button to connect to the command button i cannot successfully link to it coz i dont know the code on how to do it. I just need a sample code for my reference...can u send sample code to connect the radio button to a command button please...? Neil

                        D Offline
                        D Offline
                        David Crow
                        wrote on last edited by
                        #11

                        Neil Jigger wrote:

                        ...used a radion button to connect to the command button...

                        What is this supposed to mean? What is a "command button?"

                        "Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

                        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

                        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