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. Button to List

Button to List

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorial
4 Posts 2 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

    Well, I am a newbie programmer. I need help with a lil project I am making. Lets say I have this button called increase, when I press this button I want it to add 1 to the variable x, and display the changes. So under the button "OnIncrease", I chose and put the command x++; Which lets me add 1 to the variable x which is an unsigned long. Once this button is clicked, I want to also make it display in the box called "OnList" which is a list box. Can anyone explain simply how to make it say, "You have "x" dollars in your account." Thanks, make sure it is simple for me to understand. Arun

    V 1 Reply Last reply
    0
    • A arunforce

      Well, I am a newbie programmer. I need help with a lil project I am making. Lets say I have this button called increase, when I press this button I want it to add 1 to the variable x, and display the changes. So under the button "OnIncrease", I chose and put the command x++; Which lets me add 1 to the variable x which is an unsigned long. Once this button is clicked, I want to also make it display in the box called "OnList" which is a list box. Can anyone explain simply how to make it say, "You have "x" dollars in your account." Thanks, make sure it is simple for me to understand. Arun

      V Offline
      V Offline
      V 0
      wrote on last edited by
      #2

      CString str; CString output; str.Format("%i", x);//make a string from your number output = "You have \"" + str + "\"dollars in your account.";//make nice ans fluffy string. (\" is a " character in your string) listbox.Add(output);//add to listbox (could be AddString or something don't know by heart) hope this helps. "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix

      A 1 Reply Last reply
      0
      • V V 0

        CString str; CString output; str.Format("%i", x);//make a string from your number output = "You have \"" + str + "\"dollars in your account.";//make nice ans fluffy string. (\" is a " character in your string) listbox.Add(output);//add to listbox (could be AddString or something don't know by heart) hope this helps. "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix

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

        I tried implementing your code and I got errors. Do you think you can manually explain it? What did you mean make nice ans fluffy string? I get these errors -_- F:\Documents and Settings\Administrator\My Documents\Arun\Code\Tycoon\TycoonDlg.cpp(107) : error C2065: 'listbox' : undeclared identifier F:\Documents and Settings\Administrator\My Documents\Arun\Code\Tycoon\TycoonDlg.cpp(107) : error C2228: left of '.Add' must have class/struct/union type F:\Documents and Settings\Administrator\My Documents\Arun\Code\Tycoon\TycoonDlg.cpp(107) : error C2065: 'output' : undeclared identifier This is the code from my file. void CTycoonDlg::OnIncrease() { cash++; //On Click, Display in ListBox "You currently have $(cash) with you." CString str; CString output; str.Format("%i", cash);//make a string from your number output = "You have \"" + str + "\"dollars in your account.";//make nice ans fluffy string. (\" is a " character in your string) } void CTycoonDlg::OnList() { listbox.Add(output);//add to listbox (could be AddString or something don't know by heart) } I know I said "x" would be the variable, but I decided it was too confusing and changed it to "cash".

        V 1 Reply Last reply
        0
        • A arunforce

          I tried implementing your code and I got errors. Do you think you can manually explain it? What did you mean make nice ans fluffy string? I get these errors -_- F:\Documents and Settings\Administrator\My Documents\Arun\Code\Tycoon\TycoonDlg.cpp(107) : error C2065: 'listbox' : undeclared identifier F:\Documents and Settings\Administrator\My Documents\Arun\Code\Tycoon\TycoonDlg.cpp(107) : error C2228: left of '.Add' must have class/struct/union type F:\Documents and Settings\Administrator\My Documents\Arun\Code\Tycoon\TycoonDlg.cpp(107) : error C2065: 'output' : undeclared identifier This is the code from my file. void CTycoonDlg::OnIncrease() { cash++; //On Click, Display in ListBox "You currently have $(cash) with you." CString str; CString output; str.Format("%i", cash);//make a string from your number output = "You have \"" + str + "\"dollars in your account.";//make nice ans fluffy string. (\" is a " character in your string) } void CTycoonDlg::OnList() { listbox.Add(output);//add to listbox (could be AddString or something don't know by heart) } I know I said "x" would be the variable, but I decided it was too confusing and changed it to "cash".

          V Offline
          V Offline
          V 0
          wrote on last edited by
          #4

          arunforce wrote: What did you mean make nice ans fluffy string? Nothing actually, crazy developers like myself often set crazy comment to try and be funny. ok, CString output is declared LOCAL in your case. Put it in your .h file or somewhere on top of your .cpp file. (but under the include part) "listbox" is an unknown Object (or variable) in your case. go to the resources, right click your list box and choose "add member variable". Name it and use this name instead of "listbox" output = "You have \"" + str + "\"dollars in your account." make it: output = "You have " + str + " dollars in your account."; then you don't have the " in your text. try this and you'll get less errors. btw: I explained it taken in account you have Visual Studio. If you don't, you have to create your listbox manually. =>( http://msdn.microsoft.com[^] search on CListBox) "If I don't see you in this world, I'll see you in the next one... and don't be late." ~ Jimi Hendrix

          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