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