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. Other Discussions
  3. Article Writing
  4. Simple but very confusing to me

Simple but very confusing to me

Scheduled Pinned Locked Moved Article Writing
helplearning
5 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.
  • K Offline
    K Offline
    Kron of LS
    wrote on last edited by
    #1

    I need to create a dialog based app that does basically one thing, calculate the total pay from 2 fields -i have 3 edit box's, 1 for hours worked, 1 for pay rate and the third for the total pay. -what it has to do is take whatever numbers i put into the first 2 fields, then by clicking a button multiplay them together and put the answer into the third field. i've seen calculation code for console based but it looks completely different then what i use for dialog. i know it must be simple but to me as a beginner, it's rather confusing. please help:confused:

    L S F 3 Replies Last reply
    0
    • K Kron of LS

      I need to create a dialog based app that does basically one thing, calculate the total pay from 2 fields -i have 3 edit box's, 1 for hours worked, 1 for pay rate and the third for the total pay. -what it has to do is take whatever numbers i put into the first 2 fields, then by clicking a button multiplay them together and put the answer into the third field. i've seen calculation code for console based but it looks completely different then what i use for dialog. i know it must be simple but to me as a beginner, it's rather confusing. please help:confused:

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

      Since you have a console app that performs the desired function your problem then seems to be how to get the numbers from the edit boxes and put the result into the third edit box. Look at the documentation for Dialog Data Exchange (DDX) and UpdateData.

      1 Reply Last reply
      0
      • K Kron of LS

        I need to create a dialog based app that does basically one thing, calculate the total pay from 2 fields -i have 3 edit box's, 1 for hours worked, 1 for pay rate and the third for the total pay. -what it has to do is take whatever numbers i put into the first 2 fields, then by clicking a button multiplay them together and put the answer into the third field. i've seen calculation code for console based but it looks completely different then what i use for dialog. i know it must be simple but to me as a beginner, it's rather confusing. please help:confused:

        S Offline
        S Offline
        Steve T
        wrote on last edited by
        #3

        Kron, I'm not sure what parts you are finding confusing but the app you want is so simlple here's a quick walkthrough of how to make it in Visual C++; (No I/O control or formating/error checking etc) You should be able to spot where you went wrong. Create a new Project - MFC AppWizard (exe) Add the 4 controls you need ... 3 edit boxes and a button Right click each one in turn and in their properties/general change the IDs to : IDC_HOURS IDC_RATE IDC_PAY IDC_CALC (for the button) Now again right click one o fthe controls again and this time go to the ClassWizard. For the 3 edit controls you want to add a variable and associate it with the edit box: In ClassWizard select the "Member Variables" tab then - ( example for "Hours" box... ) Highlight "IDC_HOURS" in Control IDs column. Click "Add Variable" Complete Member variable name as "m_Hours" Make sure "Value" is selected in Category drop-down list. Select "float" in "Variable Type" drop-down list. Click "OK" ...do the same for IDC_RATE and IDC_PAY Controls IDs. Now select the Message Maps tab on the AppWizard. Highlight IDC_CALC in the Object IDs list Highlight BN_CLICKED in the "Messages" list Click "Add Function" Click "Edit Code" This will take you to the code at the newly created ::OnCalc()function. Here insert the 3 lines: UpdateData(TRUE); // the above line transfers the input typed in the IDC_HOURS // box and IDC_RATE box into the variables m_Hours and m_Rate m_Pay = m_Rate * m_Hours; // This does the work UpdateData(FALSE); // This causes newly calculated contents of m_Pay to be // displayed in the IDC_PAY edit box. Compile and run! Hope that helps. Steve T.

        K 1 Reply Last reply
        0
        • S Steve T

          Kron, I'm not sure what parts you are finding confusing but the app you want is so simlple here's a quick walkthrough of how to make it in Visual C++; (No I/O control or formating/error checking etc) You should be able to spot where you went wrong. Create a new Project - MFC AppWizard (exe) Add the 4 controls you need ... 3 edit boxes and a button Right click each one in turn and in their properties/general change the IDs to : IDC_HOURS IDC_RATE IDC_PAY IDC_CALC (for the button) Now again right click one o fthe controls again and this time go to the ClassWizard. For the 3 edit controls you want to add a variable and associate it with the edit box: In ClassWizard select the "Member Variables" tab then - ( example for "Hours" box... ) Highlight "IDC_HOURS" in Control IDs column. Click "Add Variable" Complete Member variable name as "m_Hours" Make sure "Value" is selected in Category drop-down list. Select "float" in "Variable Type" drop-down list. Click "OK" ...do the same for IDC_RATE and IDC_PAY Controls IDs. Now select the Message Maps tab on the AppWizard. Highlight IDC_CALC in the Object IDs list Highlight BN_CLICKED in the "Messages" list Click "Add Function" Click "Edit Code" This will take you to the code at the newly created ::OnCalc()function. Here insert the 3 lines: UpdateData(TRUE); // the above line transfers the input typed in the IDC_HOURS // box and IDC_RATE box into the variables m_Hours and m_Rate m_Pay = m_Rate * m_Hours; // This does the work UpdateData(FALSE); // This causes newly calculated contents of m_Pay to be // displayed in the IDC_PAY edit box. Compile and run! Hope that helps. Steve T.

          K Offline
          K Offline
          Kron of LS
          wrote on last edited by
          #4

          i dont know why but my teacher seems to think i should know this stuff already when he hasn't even explained floating point yet for decimals. i had to buy a book and find it there. another problem i'm having with this is, i have to now put in 2 more edit fields for name and lastname and make a button that clears ALL fields. i thought i had it but i get an error telling me it can't convert str to float and vice versa. is there a universal clear command that clears all fields in the program regardless of the contents?

          1 Reply Last reply
          0
          • K Kron of LS

            I need to create a dialog based app that does basically one thing, calculate the total pay from 2 fields -i have 3 edit box's, 1 for hours worked, 1 for pay rate and the third for the total pay. -what it has to do is take whatever numbers i put into the first 2 fields, then by clicking a button multiplay them together and put the answer into the third field. i've seen calculation code for console based but it looks completely different then what i use for dialog. i know it must be simple but to me as a beginner, it's rather confusing. please help:confused:

            F Offline
            F Offline
            fantastic_mr_fox
            wrote on last edited by
            #5

            1. Create a new project under VC++ using the project wizard and make it a dialog based application. 2. Go into the resource and add the edit controls you need and a button to multiply. Use names such as IDC_EDIT_RATE, IDC_EDIT_HOURS and IDC_EDIT_RESULT for your edit boxes. 3. Go into classwizard and to the 'member variables' add a new variables to the controls. This gives you an easy way to get to the data in the edit controls. So you should create some variables such as m_editRate, m_editHours and m_editResult. 4. Goto the 'message maps' tab again in classwizard. Select the button control from the list onthe left. Select the BN_CLICKED message, and create a function called OnButtonClick(); 5. Goto this function in the code and add the following: ---------------------- CString sRate; m_editRate.GetWindowText( sRate ); CString sHours; m_editHours.GetWindowText( sHours ); CString sResult; m_editResult.GetWindowText( sResult ); float fRate = atof( sRate ); float fHours = atof( sHours ); float fResuls = fRate*fHours; CString sResult; sResult.Format( "%f", fResult ); m_editResult.SetWindowText( sResult ); ---------------------- You'll have to include the right header to use atof() (see the help file).. I can't remember it offhand. Well I hope that will get you started. Philip =)

            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