|
From OP: Is there a way to retreive the data entered in a Edit Control Box while using a numerical Type variable?
Ok, it is the MFC who converts to numeric, but the OP is using MFC and having problems to associate the edit to a numeric variable... so the fact is, that he actually can do it.
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Your code should work. Did you call UpdateData(TRUE) to retrieve the data from the control?
Edit: Actually, your for loop is incomplete.
|
|
|
|
|
Have you tried CWnd::GetDlgItemInt()[^]?
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
Although my answer[^] has been downvoted, you may want to check it. The other answers about get the data in string format and then convert it are totally correct, but you can make what you were asking as well.
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
GetWindowText() would not work with a type of int or cstring. Debug always showed the value was 0 though I'd entered 123456. So I've changed the category to Control and the type is CEdit. This is what I'd been doing earlier in the code and used the following code to get and convert the entry.
m_entered_number.GetWindowText( temp_CString );
entered_number = atoi( temp_CString );
Was looking for a way to eliminate the string and conversion but VS does not want to cooperate.
Everyone, thank you for you help.
|
|
|
|
|
hilop wrote:
m_entered_number.GetWindowText( temp_CString );
entered_number = atoi( temp_CString );
You are using it wrongly. If you declare the member variable as numeric then you can not use it. (see my downvoted answer)
If you want to use that functions you have to declare the member variable as CEdit.
Or do it programmatically:
CEdit* pEdit = GetDialogItem (IDC_MYEDIT);
pEdit->GetWindowText (strTemp);
number = atoi (strTemp);
PS: I don't have VC++ in this laptop and I don't remember if the function is GetDialogItem or GetDlgItem. Check you local help, it anyways is a member function of CDialog
Regards.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
you forget to give call to UpdateDate(false) function which retrieve values from dialog box back to variable
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow Never mind - my own stupidity is the source of every "problem" - Mixture
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Hello dear friends,
I've created a .docx file programatically but opening this file says that
the file has been currupted.
Here is the code.
unsigned long nSize = 0;
char szBuffer[100];
CFile o;
CFileException e;
strcpy(szBuffer,"hi");
nSize=strlen(szBuffer);
if(!o.Open("C:\\Documents and Settings\\Rigel\\Desktop\\Exl.docx", CFile::modeCreate | CFile::modeWrite,&e))
{
MessageBox("Can't open the file for writing.",_T("File"),MB_OK);
}
else
{
o.Write(szBuffer,nSize);
o.Close();
}
ShellExecute(NULL,"open","C:\\Documents and Settings\\Rigel\\Desktop\\Exl.docx",NULL,NULL,SW_NORMAL);
Help me please.
ritz1234
|
|
|
|
|
Well, of course, if you just put a string in the file without respecting the file format. A doc (and docx) file is a binary file, so you have to respect the format of that file. I know that you can use automation to create doc file but I don't know if the format is the same as a docx file.
|
|
|
|
|
Cedric Moonen wrote: I know that you can use automation to create doc file but I don't know if the format is the same as a docx file.
Of course not, docx file is an XML file.
led mike
|
|
|
|
|
|
All you've done is create a file with a .docx extension, not a true Word 2007 document.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I am creating an application in VC++4 on Win CE5. The application is for a smart device with ARMV4I CPU. The code is compiled under the device SDK.
In the below code, I try to write all objects passed in an CArray object. The error that I get is also mentioned below.
void DbOperations::WriteDepartments(CArray<DeptDetails, DeptDetails&> dptArr)
{
HANDLE hFile = CreateFile(DEPT_FILE,
GENERIC_WRITE, FILE_SHARE_WRITE,
NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
AfxMessageBox(_T("Error OPeniong File"));
else {
CFile myfile((int)hFile);
CArchive ar(&myfile, CArchive::store);
if (dptArr.GetSize() == 0)
return;
for (int pos=0; pos < dptArr.GetSize(); pos++) {
DeptDetails& ddt = dptArr.ElementAt(pos);
ddt.Serialize(ar);
ddt.~DeptDetails();
}
myfile.Close();
}
return;
}
ERROR: c:\program files\windows ce tools\wce500\mc1000c50\mfc\include\afxtempl.h(855) : error C2582: 'DeptDetails' : 'operator =' function is unavailable
c:\program files\windows ce tools\wce500\mc1000c50\mfc\include\afxtempl.h(1578) : while compiling class-template member function 'struct __POSITION *__cdecl CList<class DeptDetails,class DeptDetails &>::AddTail(class DeptDetails &)'
Error executing clarm.exe.
I also tried the above with CMapStringToPtr
void DbOperations::WriteDepartments(CMapStringToPtr dptMap)
{
HANDLE hFile = CreateFile(DEPT_FILE,
GENERIC_WRITE, FILE_SHARE_WRITE,
NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
AfxMessageBox(_T("Error OPeniong File"));
else {
CFile myfile((int)hFile);
CString key;
DeptDetails* dd;
CArchive ar(&myfile, CArchive::store);
for (POSITION pos = dptMap.GetStartPosition(); pos != NULL;) {
dptMap.GetNextAssoc(pos, key, (DeptDetails*&)dd );
dd->Serialize(ar);
}
key.Empty();
dd->~DeptDetails();
myfile.Close();
}
return;
}
ERROR : : error C2664: 'GetNextAssoc' : cannot convert parameter 3 from 'class DeptDetails *' to 'void *& '
A reference that is not to 'const' cannot be bound to a non-lvalue
Error executing clarm.exe.
Also, if I don't comment the code of CMap, I don't get any errot of CArray; only error of CMap else of CArray.
Does anyone has any idea where I am going wrong. Please help me out.
Thanks
Terry
|
|
|
|
|
What does the declaration of DeptDetails look like?
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Trupti Mehta wrote: ERROR: c:\program files\windows ce tools\wce500\mc1000c50\mfc\include\afxtempl.h(855) : error C2582: 'DeptDetails' : 'operator =' function is unavailable
c:\program files\windows ce tools\wce500\mc1000c50\mfc\include\afxtempl.h(1578) : while compiling class-template member function 'struct __POSITION *__cdecl CList<class deptdetails,class="" deptdetails="" &="">::AddTail(class DeptDetails & [Wink] '
Error executing clarm.exe.
I think DeptDetails is derived from CObject , because you are serializing it. If your class is derived from CObject, the compiler won't generate default copy constructor and assignment operator for your derived class. So you should provide it. For more info - http://msdn.microsoft.com/en-us/library/ccb3dh5c.aspx[^]
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Yes you are absolutely correct, DeptDetails is derived from CObject & IMPLEMENT_SERIAL(DeptDetails, CObject, 1);
is added as expected.
Thanks for your help.
Based on your link, I added both constructor/method :
public:
DeptDetails(const DeptDetails &d);
DeptDetails& operator=(const DeptDetails &d);
And implemented as :
DeptDetails::DeptDetails(const DeptDetails &d) {
deptNo = d.deptNo;
deptName = d.deptName;
vat = d.vat;
}
DeptDetails& operator=(const DeptDetails &d) {
deptNo = d.GetDeptNo();
deptName = d.GetDeptName();
vat = d.GetVat();
return *this;
}
Copy constructor is perfect, but operator assignment gives 8 error :
eptDetails.cpp
D:\TRUPTI\HANDHELD\MC_App\DeptDetails.cpp(28) : error C2801: 'operator =' must be a <Unknown> member
D:\TRUPTI\HANDHELD\MC_App\DeptDetails.cpp(29) : error C2065: 'deptNo' : undeclared identifier
D:\TRUPTI\HANDHELD\MC_App\DeptDetails.cpp(29) : error C2662: 'GetDeptNo' : cannot convert 'this' pointer from 'const class DeptDetails' to 'class DeptDetails &'
Conversion loses qualifiers
D:\TRUPTI\HANDHELD\MC_App\DeptDetails.cpp(30) : error C2065: 'deptName' : undeclared identifier
D:\TRUPTI\HANDHELD\MC_App\DeptDetails.cpp(30) : error C2662: 'GetDeptName' : cannot convert 'this' pointer from 'const class DeptDetails' to 'class DeptDetails &'
Conversion loses qualifiers
D:\TRUPTI\HANDHELD\MC_App\DeptDetails.cpp(31) : error C2065: 'vat' : undeclared identifier
D:\TRUPTI\HANDHELD\MC_App\DeptDetails.cpp(31) : error C2662: 'GetVat' : cannot convert 'this' pointer from 'const class DeptDetails' to 'class DeptDetails &'
Conversion loses qualifiers
D:\TRUPTI\HANDHELD\MC_App\DeptDetails.cpp(33) : error C2673: '=' : global functions do not have 'this' pointers
Error executing clarm.exe.
DeptDetails.obj - 8 error(s), 0 warning(s)
I tried a lot, and understand that their is a simple minute mistake which is causing so many errors, but couldn't trap the mistake.
Can please help me know the mistake and resolve the errors.
I appreciate your help.
Thanks
Terry
|
|
|
|
|
Trupti Mehta wrote: // Assignment operator
DeptDetails& operator=(const DeptDetails &d) {
deptNo = d.GetDeptNo();
deptName = d.GetDeptName();
vat = d.GetVat();
return *this;
}
Did you forget to add DeptDetails:: while copy pasting the function signature from header to cpp?
DeptDetails& DeptDetails::operator=(const DeptDetails &d)
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Thanks Jijo,
But this didn't solve the Map error of the followng function:
void DbOperations::WriteDepartments(CMapStringToPtr dptMap)
{
HANDLE hFile = CreateFile(DEPT_FILE,
GENERIC_WRITE, FILE_SHARE_WRITE,
NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
AfxMessageBox(_T("Error OPeniong File"));
else {
CFile myfile((int)hFile);
CString key;
DeptDetails* dd;
CArchive ar(&myfile, CArchive::store);
for (POSITION pos = dptMap.GetStartPosition(); pos != NULL;) {
dptMap.GetNextAssoc(pos, key, (DeptDetails&)dd );
dd->Serialize(ar);
}
key.Empty();
dd->~DeptDetails();
myfile.Close();
}
return;
}
On GetNextAssoc method, I still get :
error C2664: 'GetNextAssoc' : cannot convert parameter 3 from 'class DeptDetails *' to 'void *& '
A reference that is not to 'const' cannot be bound to a non-lvalue
Error executing clarm.exe.
How to resolve this error yet? Do i have to write another operator= for DeptDetails*. Can you let me know the code so I don't make mistake again.
I highly appreciate for your quick and helpful responses.
One more query I have:
I wanted to store deptNo (int) as key & DeptDetails as value in a Map. I looked at CMap but couldn't find any method to iterate the map contents, hence selected CMapStringToPtr seemed to be best suited to store deptNo in the form of CString. Is this decision correct or should I approach some other class of CMap.
Thanks
Terry
|
|
|
|
|
Buddy, sorry for the late reply. I went to city with my friend to buy a brand new helmet. So back to your problem,
Trupti Mehta wrote: dptMap.GetNextAssoc(pos, key, (DeptDetails& [Wink] dd ); //.GetNextAssoc(pos, key, (DeptDetails*& [Wink] dd);
The reason for your last error is - 3ed parameter of GetNextAssoc() expects CObject*& . Rewrite the code snippet as follows,
DeptDetails* dd;
...
dptMap.GetNextAssoc(pos, key, ((CObject*&)dd);
Trupti Mehta wrote: How to resolve this error yet? Do i have to write another operator= for DeptDetails*. Can you let me know the code so I don't make mistake again.
I hope everything will be solved by this fix. Yep, I've posted the code snippet!
Trupti Mehta wrote: One more query I have:
I wanted to store deptNo (int) as key & DeptDetails as value in a Map. I looked at CMap but couldn't find any method to iterate the map contents, hence selected CMapStringToPtr seemed to be best suited to store deptNo in the form of CString. Is this decision correct or should I approach some other class of CMap.
1) You can iterate CMap by using GetStartPosition() and GetNextAssoc() .
2) Since your intention is to keep int as key, instead of CMapStringToPtr , CMapWordToPtr will be more suitable, because it have mapkey as word by default and you can avoid that DepartNo to CString conversion.
Feel free to ask more doubts, if you have.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
No Jijo,
This is what I had tried earlier and tried again on your code snppet. But still no change.
DeptDetails implements Serialization, so IMPLEMENT_SERIAL & DYNAMIC_SErial are added in .h & .cpp files. CMapStrToPtr & CMapWordToPtr both needs DYNAMIC.
I commented DYNAMIC SERIAL in both files & tried again but still same error
ERROR :
Cannot convert (CObject*) to void*&
I am implementing in Win CE 5, just if this info bes any help to u. Help says CMAP & respective sub types supports Win Ce 1 & further.
Thanks
Terry
|
|
|
|
|
Terry,
If that still throws and error, then the reason might be something different. Could you post the full code snippet of DeptDetails class? the header and cpp. I'll try to isolate the issue.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
class DeptDetails : public CObject
{
DECLARE_SERIAL(DeptDetails);
public:
DeptDetails(void);
DeptDetails(int dno, CString name, float vat);
DeptDetails(const DeptDetails &d);
DeptDetails& operator=(const DeptDetails &d);
IMPLEMENT_SERIAL(DeptDetails, CObject, 1);
DeptDetails::DeptDetails(void)
: deptNo(0)
, deptName(_T(""))
, vat(0)
{
}
DeptDetails::DeptDetails(int dno, CString name, float vat) {
deptNo = dno;
deptName = name;
this->vat = vat;
}
DeptDetails::DeptDetails(const DeptDetails &d) {
deptNo = d.deptNo;
deptName = d.deptName;
vat = d.vat;
}
DeptDetails& DeptDetails::operator=(const DeptDetails &d) {
deptNo = d.deptNo;
deptName = d.deptName;
vat = d.vat;
return *this;
}
class DbOperations
{
public:
CMap<int, int, DeptDetails, DeptDetails> deptMap;
void WriteOperators(CMap<int, int, OperatorDetails, OperatorDetails> opdtMap);
void DbOperations::WriteDepartments(CMap<int, int, DeptDetails, DeptDetails> dptMap)
{
HANDLE hFile = CreateFile(DEPT_FILE,
GENERIC_WRITE, FILE_SHARE_WRITE,
NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
AfxMessageBox(_T("Error OPeniong File"));
else {
CFile myfile((int)hFile);
int key;
DeptDetails dd;
CArchive ar(&myfile, CArchive::store);
for (POSITION pos = dptMap.GetStartPosition(); pos != NULL;) {
dptMap.GetNextAssoc(pos, key, dd );
ar.WriteObject(&dd);
}
dd.~DeptDetails();
ar.Close();
myfile.Close();
}
return;
}
CMap<int, int, DeptDetails, DeptDetails> DbOperations::ReadDepartments()
{
if(deptMap.IsEmpty() == false)
deptMap.RemoveAll();
HANDLE hFile = CreateFile(DEPT_FILE,
GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFile == INVALID_HANDLE_VALUE)
AfxMessageBox(_T("Error OPeniong File"));
else {
CFile myfile((int)hFile);
int key;
DeptDetails* dd;
int i;
myfile.SeekToBegin();
CArchive ar(&myfile, CArchive::load);
dd = (DeptDetails*) ar.ReadObject( RUNTIME_CLASS(DeptDetails) );
delete dd;
dd->~DeptDetails();
myfile.Close();
}
return deptMap;
}
Regardingly, for all CMap... DYNAMIC_SERIAL objectS ARE NOT supported, its only CMap where the object can be of DYNAMIC_SERIAL/IMPLEMENT_SERIAL. CMap was my first inital preference but by looking at other CMap classes, I opted them, but not on returning to CMap things are fine. I mean 0 errors 0 warnings. I only get error at SetAt in ReadDepartments(). Have I implemented the CArchive correctly in Write & Read Departments. Please check out that.
I have come back in VC++ after long time, so many things are new and many out of the mind also. Hope to get this woring correctly at the earliest.
Thanks
Terry
|
|
|
|
|
Terry your map is CMap < int, int, DeptDetails, DeptDetails > where you are supposed to insert an object of DeptDetails .
Trupti Mehta wrote: // deptMap.SetAt(i, dd);
But dd, which you're inserting is a pointer where object is expected. So you should use it like as follows,
deptMap.SetAt(i, *dd);
Trupti Mehta wrote: Have I implemented the CArchive correctly in Write & Read Departments. Please check out that.
Seems Fine by looking with my eyes.
Trupti Mehta wrote: I have come back in VC++ after long time, so many things are new and many out of the mind also. Hope to get this woring correctly at the earliest.
No probs buddy. Feel free to shoot any doubts.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Thanks Jijo for all your help and efforts.
I am able to write data to the file from map, but couldn't check the dat file.
As I am working on CE, couldn't even read the data as after closing the Enumarator, the files are deleted. But the file is writing correctly so I hope reading will also perform correctly only.
Now, I have problem of communicating between parent & child dialogs & on child dialog's message parent should hide that child and show another child dialog. As this question is out of this topic so am creating a new one. Hope will get help from you in that topic too.
Once again thanks.
Thanks
Terry
|
|
|
|
|
Trupti Mehta wrote: But the file is writing correctly so I hope reading will also perform correctly only.
So happy to hear the good news!
Trupti Mehta wrote: Hope will get help from you in that topic too.
Sure. I'll have a look at it.
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|