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. Loading Variable in EditBox

Loading Variable in EditBox

Scheduled Pinned Locked Moved C / C++ / MFC
questionhelp
5 Posts 3 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.
  • A Offline
    A Offline
    arunforce
    wrote on last edited by
    #1

    How do I load a variable inside an edit box? I have an edit box stated below, its called "OnCash", It's ID is "IDC_CASH". Source: ---------------------------------------------- void CTycoonDlg::OnCash() { //$cash(variable) } ---------------------------------------------- I want it to say in the editbox that is read only, $(cashvariable) so it would look like this inside the editbox: $100000 (default value for the cash, unsigned long) Can anyone help me?

    A 1 Reply Last reply
    0
    • A arunforce

      How do I load a variable inside an edit box? I have an edit box stated below, its called "OnCash", It's ID is "IDC_CASH". Source: ---------------------------------------------- void CTycoonDlg::OnCash() { //$cash(variable) } ---------------------------------------------- I want it to say in the editbox that is read only, $(cashvariable) so it would look like this inside the editbox: $100000 (default value for the cash, unsigned long) Can anyone help me?

      A Offline
      A Offline
      Archer282
      wrote on last edited by
      #2

      You need to create a variable for the value of the edit box do this by going to the resource viewer right click on the dialog select "Class Wizard" click on the Member Bariables tab select IDC_CASH and click Add Variable name it something like m_Cash then to set the text in it do this m_Cash = "$1000000"; UpdateData( TRUE ); // sets the edit boxes text to m_Cash's value to get the edit boxes text and store it in m_Cash call UpdateData( FALSE );

      A 1 Reply Last reply
      0
      • A Archer282

        You need to create a variable for the value of the edit box do this by going to the resource viewer right click on the dialog select "Class Wizard" click on the Member Bariables tab select IDC_CASH and click Add Variable name it something like m_Cash then to set the text in it do this m_Cash = "$1000000"; UpdateData( TRUE ); // sets the edit boxes text to m_Cash's value to get the edit boxes text and store it in m_Cash call UpdateData( FALSE );

        A Offline
        A Offline
        arunforce
        wrote on last edited by
        #3

        Problem is: I already made a value, and It's being read all across the program, im just trying to sorta make an active display in the MFC application on how much money I have... It's an edit box, displaying how much cash you have. This is part of the source: #include "stdafx.h" #include "Tycoon.h" #include "TycoonDlg.h" #include "BUY.h" #include "SELL.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif unsigned long cash = 100000; But Class Wizard makes a new variable, and I want to use my old variable.

        J 1 Reply Last reply
        0
        • A arunforce

          Problem is: I already made a value, and It's being read all across the program, im just trying to sorta make an active display in the MFC application on how much money I have... It's an edit box, displaying how much cash you have. This is part of the source: #include "stdafx.h" #include "Tycoon.h" #include "TycoonDlg.h" #include "BUY.h" #include "SELL.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif unsigned long cash = 100000; But Class Wizard makes a new variable, and I want to use my old variable.

          J Offline
          J Offline
          Jaime Stuardo
          wrote on last edited by
          #4

          just delete the wizard-made variable and use your own. You will need to rename the variable in DDX macros section too. Jaime

          A 1 Reply Last reply
          0
          • J Jaime Stuardo

            just delete the wizard-made variable and use your own. You will need to rename the variable in DDX macros section too. Jaime

            A Offline
            A Offline
            arunforce
            wrote on last edited by
            #5

            I did that and this is how it shows up, 100000, I added a command which increases the value by 1, ak,; cash++. I hit the button, and it shows up as it has been changed in the list box, but not the edit box. The List Box's purpose is to show changes, like if you buy a car, it will say you lost $10,000, and the edit box display's how much money you currently have, and updates accordingly... If I delete the preset in the DDX section it turns into -858993460, and so i deleted it being set in the begining of the file where it says unsigned long cash = 100000; to long cash. (I changed the unsigned part also) The two problems are that 1. The edit box doesn't update. 2. The edit box doesnt have a $ before the number, how do i do that? Thanks alot for your help. Here is how the source beginning is: ------------------------------------------------------------------------- #include "stdafx.h" #include "Tycoon.h" #include "TycoonDlg.h" #include "BUY.h" #include "SELL.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif long cash; unsigned int day = 01; unsigned int month = 01; unsigned int year = 04; unsigned int chp; unsigned int mhp; ///////////////////////////////////////////////////////////////////////////// // CTycoonDlg dialog CTycoonDlg::CTycoonDlg(CWnd* pParent /*=NULL*/) : CDialog(CTycoonDlg::IDD, pParent) { //{{AFX_DATA_INIT(CTycoonDlg) cash = 100000; //}}AFX_DATA_INIT m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CTycoonDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CTycoonDlg) DDX_Text(pDX, IDC_CASH, cash); //}}AFX_DATA_MAP } -------------------------------------------------------------------------

            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