|
|
Okay, Ive got the other part of my problem fixed, and it appears to be working... That is, fetching text values from Edit Boxes and converting them to Long, then adding them for the sum.
Now, I want to convert the sum variable back to text so it can be used in a message box.
Heres what I have, code snippit:
===========================================================
// Fetch the text from Edit Boxes 1 and 2, and assign them
// to variables Number1 and 2.
GetDlgItemText(IDC_EDIT1, Number1);
GetDlgItemText(IDC_EDIT2, Number2);
// Initilize Long variables for number 1 and 2,
// and the resulting sum, Answer.
long N1;
long N2;
long Ans;
// Convert the text Number1 to Long N1,
// and 2 respectivly
N1 = wcstol(Number1, NULL, 10);
N2 = wcstol(Number2, NULL, 10);
// Add for the sum
Ans = N1 + N2;
// * Error compiling here.. *
// Objective: convert the Long Ans to the
// string AnsSum for printing in message box, etc..
CString AnsSum = atol( Ans );
// Build the text string TmpTxt to be used in message box
CString TmpTxt = "The numbers are " + Number1 + " and " + Number2 + " and the sum is " + _T(AnsSum);
// Finally, display the message box
MessageBox(TmpTxt, _T("Your answer"), MB_ICONINFORMATION | MB_OK);
===========================================================
Im getting these errors:
error C2664: 'atol' : cannot convert parameter 1 from 'long' to 'const char *'
error C2065: 'LAnsSum' : undeclared identifier
error C2666: '+' : 5 overloads have similar conversions
As you may recall from my previou post, this is a super newbie project Im working on, fetch two text vals from two edit boxes, convert them to Long, add them for the sum, convert the Long sum to Text and display the answer in a message box.
This project is introducing me to several various 'C++' structures and getting me used to the IDE. I am making progress, but I feel like a total idiot because I cant develop this simple app without having to ask questions.
I come from years of app dev with VB, so this is quite a change for me.
If you reply, please address me as the idiot I am so I understand what I am doing wrong, and what I need to do, and if you feel fancy, the why...
Thanks,
Andrew
New to VC++ programming, working hard to learn.
|
|
|
|
|
atol() converts an ANSI string to long integer. The function you want is _itoa() (ANSI) or _itow() (UNICODE) or _itot (ANSI and UNICODE) which converts a long integer to a string.
From your previous post I am lead to believe you are using a UNICODE enviroment, so you should either use UNICODE functions (have a 'w' in them instead of an 'a') or use the TCHAR macros.
CPUA 0x5041
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
Same problem as before, you're using an ANSI function (atol ) and passing it a Unicode string (CString has a converter to LPCWSTR ). Check out The Complete Guide to C++ Strings, Part I - Win32 Character Encodings[^] -- it explains the different string types and functions. You absolutely need to know this for Win32 programming. Just remember that in WinCE, everything is Unicode.
--Mike--
The Internet is a place where absolutely nothing happens.
-- Strong Bad
1ClickPicGrabber - Grab & organize pictures from your favorite web pages, with 1 click!
My really out-of-date homepage
Sonork-100.19012 Acid_Helm
|
|
|
|
|
The link to strings has some great information in it, i think, Im too stupid at this point to understand most of what Im reading... Give me some time, Ill figure it out. I had little or no help learning VB, so this is like deja-vu.
New to VC++ programming, working hard to learn.
|
|
|
|
|
PocketBlast wrote:
error C2065: 'LAnsSum' : undeclared identifier
Hey kewl , I was wondering where you had an Identifier named 'LAnsSum' until I saw that you wrapped 'AnsSum' in a _T() macro. The _T() macro is used to declare a literal string in your code as either an ANSI or UNICODE string. Basicly what it does is use the preprocessor to prepend a 'L' in front of what ever text you run through it.
#ifdef _UNICODE
#define _T(str) L##str
#else
#define _T(str) str
#endif
CPUA 0x5041
Sonork 100.11743 Chicken Little
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
Within you lies the power for good - Use it!
|
|
|
|
|
Okay, now I have:
Ans = N1 + N2;
CString AnsSum;
_itow (Ans, AnsSum, 10);
And getting compiler error:
'_itow' : cannot convert parameter 2 from 'class CString' to 'unsigned short *'
Im still lost... Any suggestions?
Andrew
New to VC++ programming, working hard to learn.
|
|
|
|
|
This should convert an integer to a CString:
AnsSum.Format("%d", Ans);
Brad Jennings
"if the golden arches shut shop, where else are the VB people going to get work." - Colin Davies
|
|
|
|
|
Tried:
===========================================================
CString AnsSum;
// _itow (Ans, AnsSum, 10);
AnsSum.Format("%d", Ans);
===========================================================
Compiler/Linker gave:
: error C2664: 'void __cdecl CString::Format(const unsigned short *,...)' : cannot convert parameter 1 from 'char [3]' to 'const unsigned short *'
Guys, Im *very* sorry, Im so new to this I dont even understand the error message.
Thanks for working with me, I wouldnt blame you all if I got banned from this forum!
Andrew
=================================
New to VC++ programming, working hard to learn.
Programming platform: eVC++ 3.0 for WinCE/PPC
=================================
|
|
|
|
|
Hmm, CString must be a little different between compilers.
Try:
CString AnsSum;<br />
char temp[33];<br />
ltoa(i, temp, 10);<br />
AnsSum = temp;
This works without any headers in VC++ 6.0 but if it doesn't know what ltoa is try [edit] including stdlib.h [/edit]. Don't feel bad about asking questions, simple or complex, we've all got to start somewhere.
Brad Jennings
"if the golden arches shut shop, where else are the VB people going to get work." - Colin Davies
|
|
|
|
|
PocketBlast wrote:
AnsSum.Format("%d", Ans);
#include <tchar.h><br />
AnsSum.Format(_T("%d"), Ans);
I assume you are using UNICODE the error message is saying that the "%d" is in the wrong format for unicode it must be an unsigned short, the _T deals with it
If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676
|
|
|
|
|
AnsSum.Format(_T("%d"), Ans);
Holy cow Batman! That worked!
Though, I didnt include #include <tchar.h>, may be default part of the IDE for WinCE, dont know..
Yes, I have recently been educated that I am programming for a Unicode environment, the PocketPC IE: WinCE. Though I have not a clue what that means at this point, Ill figure that out later. Now I gotta learn ANSI formats so I can write for the X86 platform! UGGGG!
Now I know why VB is so appealing to newbies! HAHA!
Thanks much for the on target help!
Andrew
=================================
New to VC++ programming, working hard to learn.
Programming platform: eVC++ 3.0 for WinCE/PPC
=================================
|
|
|
|
|
AnsSum.Format(_T("%d"), Ans);
Cool, it looks like I was on the right track when I was trying to help, just haven't dealt with UNICODE before. I'll have to look into the tchar thing.
Brad Jennings
"if the golden arches shut shop, where else are the VB people going to get work." - Colin Davies
|
|
|
|
|
I used the _T macro, the "correct" way would be to use L("%d") but with _T the code will work for UNICODE and char strings, just check out the MSDN for
"Using Generic-Text Mappings"
"Data Type Mappings"
i.e look for _T in the index
If I have seen further it is by standing on the shoulders of Giants. - Isaac Newton 1676
|
|
|
|
|
hey, I was looking at the tutorial to show fonts in a combo box(http://www.codeproject.com/combobox/fontcombo.asp?forumid=3520&app=50#xxxx). I'm trying to implement it into my program but i'm having trouble.
Keep in mind I'm new to MFC.
It says: "Add a member of type CFontPreviewCombo to your dialog and attach it to your control."
How do I do this? I'm not sure what the member part means. Thanks for any help.
|
|
|
|
|
hello experts,
I created a TimerThread class that derive from CWinThread,
class TimerThread: public CWinThread
{
public:
TimerThread();
SYSTEMTIME* start_time;
SYSTEMTIME* end_time;
VOID SetStartTime(SYSTEMTIME*);
VOID CopyTime(SYSTEMTIME*, SYSTEMTIME*);
};
and I have a global TimeThread* timerThread;
timerThread=AfxBeginThread(RUNTIME_CLASS(TimerThread));
I got the following error, i don't really understand it...
thanks for the help.
C:\sampleC++\dlg\dlgDlg.cpp(130) : error C2039: 'classTimerThread' : is not a member of 'TimerThread'
c:\samplec++\dlg\timerthread.h(2) : see declaration of 'TimerThread'
C:\sampleC++\dlg\dlgDlg.cpp(130) : error C2065: 'classTimerThread' : undeclared identifier
|
|
|
|
|
In your code "classTimerThread" is one world. What is it and where is it declared?
Kuphryn
|
|
|
|
|
sorry the error was thrown at this line:
timerThread=AfxBeginThread(RUNTIME_CLASS(TimerThread));
so it seems RUNTIME_CLASS() returned a classTimerThread or something.. I don't understand..
thanks for the help
|
|
|
|
|
From the MSDN: You must derive your class fromCObject and use the DECLARE_DYNAMIC and IMPLEMENT_DYNAMIC, the DECLARE_DYNCREATE and IMPLEMENT_DYNCREATE, or the DECLARE_SERIAL and IMPLEMENT_SERIAL macros.
Software Zen: delete this;
|
|
|
|
|
I was looking at a tutorial here on codeproject and wasn't to sure about how to include the control into my own project. I figured if I post here instead of on the page for the project I may get more responses or someone who has done it. here is the URL
http://www.codeproject.com/richedit/AutocomplectionCtrl.asp
I wanted to put it in a SDI app. Should I just inherit the CRichEditView class? I'm kind of confused on how to incorporate it. Any examples or help would be greatly appreciated! Thank you
paully
|
|
|
|
|
I Tried To Make a 'replacement' for making Dialog Classe Based On Anthor Class instead Of CDialog ,
Actully I didnt Figure Out Howit works .
Can Anyone refer Me A Tutorial Or Explain it To Me ?
Thanks in Advanced
|
|
|
|
|
hi guys, I used appWizard to created a dialog that has a dropdown combobox on it, it's id is DROPDOWNHRSFN, my question is that, inside of its event handler code, how would I be able to obtain a reference of the dropdown combobox? I would like to get the item that the user selects from the combobox. how would I do that? And How would I initialize this combobox with my custom data?
thank you so much
void CDlgDlg::OnDropdownHrsfn()
{
MessageBox("drop down","drop down",MB_OK);
// TODO: Add your control notification handler code here
}
|
|
|
|
|
|
|
As the sig says, Im new to this entire game! Im not only learning VC++, but the IDE to boot! Gosh.. Gimme some Tylenol!!
Ive got a string variable, Number1, I want to convert it Long, but the linker give the message:
error C2664: 'strtol' : cannot convert parameter 1 from 'class CString' to 'const char *'
Heres the code snippit:
===========================================================
GetDlgItemText(IDC_EDIT1, Number1);
GetDlgItemText(IDC_EDIT2, Number2);
CString TmpTxt = "The numbers are " + Number1 + " and " + Number2;
MessageBox( TmpTxt, _T("Error"), MB_ICONINFORMATION | MB_OK);
// Everything above works fine, below is conversion
// which wont work.
long Ans;
Ans = strtol(Number1, NULL, 10);
===========================================================
This is a stupid newbie project, enter two numbers in two Edit Boxes, convert the text var to a long var, add the two, convert it back to text and give a message box with the sum of the two.
I have the Member Variable assigned to IDC_EDIT1 as CString using Number1, and 2 respectively.
I am using eVC++ 3.0 for WinCE.
Any help, thanks much in advance!
This *aint* VB, dats fur sure!
PS
Please reply as if I were a total idiot, becaue I am!
Andrew
New to VC++ programming, working hard to learn.
|
|
|
|
|