|
T.RATHA KRISHNAN wrote: At line 5, the query is executed and the result is assigned to the array. When I print the elements of playerLst array only 11 player names are printed(not what I expect. It has to print 99 names since each country has 11 players and there are 9 cty's).
This is the expected result because you have to use a nested loop in order to print players.
Try something like this after :
for(int i = 0; i<ctyLst.size();i++)
{
queryStr = L"Select Name From Test WHERE Team ='";
queryStr += ctyLst[i].trim();
queryStr += L"'";
queryStr += L"ORDER BY RANDOM() LIMIT 11";
playerLst = SQLdb.Query(queryStr);
for(int j = 0; j<playerLst.size();j++)
{
printf("%s \n",playerLst[j].c_str());
}
}
And about the error: You are trying to add another array into your array (SQLdb.Query returns an array, right?), instead of adding a string and that is the cause of the error.
|
|
|
|
|
If I use nested loop also only 11 names are printed.
|
|
|
|
|
It is a good idea to use your debugger in such situations.
See how many results your first query returns.
After that see how many results return your query that you call each time in loop (note that the loop count depends on the results of first query).
First be sure that queries work as expected!
|
|
|
|
|
This is the query at each iteration of the for loop and contents of the array at each iteration:
Select Name From Test WHERE Team ='Australia' ORDER BY RANDOM() LIMIT 11
SR Watson
SR Watson
SR Watson
SR Watson
SR Watson
SR Watson
SR Watson
SR Watson
SR Watson
SR Watson
SR Watson
Select Name From Test WHERE Team ='England' ORDER BY RANDOM() LIMIT 11
LJ Wright
LJ Wright
LJ Wright
LJ Wright
LJ Wright
LJ Wright
LJ Wright
LJ Wright
LJ Wright
LJ Wright
LJ Wright
Select Name From Test WHERE Team ='India' ORDER BY RANDOM() LIMIT 11
SR Tendulkar
SR Tendulkar
SR Tendulkar
SR Tendulkar
SR Tendulkar
SR Tendulkar
SR Tendulkar
SR Tendulkar
SR Tendulkar
SR Tendulkar
SR Tendulkar
Select Name From Test WHERE Team ='New Zealand' ORDER BY RANDOM() LIMIT 11
BB McCullum
BB McCullum
BB McCullum
BB McCullum
BB McCullum
BB McCullum
BB McCullum
BB McCullum
BB McCullum
BB McCullum
BB McCullum
Select Name From Test WHERE Team ='Pakistan' ORDER BY RANDOM() LIMIT 11
Naved-ul-Hasan
Naved-ul-Hasan
Naved-ul-Hasan
Naved-ul-Hasan
Naved-ul-Hasan
Naved-ul-Hasan
Naved-ul-Hasan
Naved-ul-Hasan
Naved-ul-Hasan
Naved-ul-Hasan
Naved-ul-Hasan
Select Name From Test WHERE Team ='South Africa' ORDER BY RANDOM() LIMIT 11
YA Abdulla
YA Abdulla
YA Abdulla
YA Abdulla
YA Abdulla
YA Abdulla
YA Abdulla
YA Abdulla
YA Abdulla
YA Abdulla
YA Abdulla
Select Name From Test WHERE Team ='Sri Lanka' ORDER BY RANDOM() LIMIT 11
UWMBCA Welegedara
UWMBCA Welegedara
UWMBCA Welegedara
UWMBCA Welegedara
UWMBCA Welegedara
UWMBCA Welegedara
UWMBCA Welegedara
UWMBCA Welegedara
UWMBCA Welegedara
UWMBCA Welegedara
UWMBCA Welegedara
Select Name From Test WHERE Team ='West Indies' ORDER BY RANDOM() LIMIT 11
AB Barath
AB Barath
AB Barath
AB Barath
AB Barath
AB Barath
AB Barath
AB Barath
AB Barath
AB Barath
AB Barath
Select Name From Test WHERE Team ='Zimbabwe' ORDER BY RANDOM() LIMIT 11
KM Dabengwa
KM Dabengwa
KM Dabengwa
KM Dabengwa
KM Dabengwa
KM Dabengwa
KM Dabengwa
KM Dabengwa
KM Dabengwa
KM Dabengwa
KM Dabengwa
No.of Players in the List: 11
Only one player name is assgned for all 11 array locations. If I execute the query using SQLBROWSER,it prints correct results(different 11 names). Why is it so?
I wonder why this printf statement:
printf("No.of Players in the List: %d \n",playerLst.size());
prints 11 even if it outputs 99 unique names. It has to print 99 only?
If I give printf inside the for loop it prints No. Players as 11 at each iteration.
|
|
|
|
|
|
|
You are welcome!
|
|
|
|
|
i define a hot key in my app with RegisterHotKey.
ATOM identiferForTest=GlobalAddAtom(_T("test"));
if (!RegisterHotKey(this->m_hWnd,identiferForTest,0,'T'))
{
AfxMessageBox(_T("hot key conflict!"));
}
and in the event handler~showing a MessageBox respond to the hot key(press 'T' keyboard key)
later at somewhere i call UnRegisterHotKey!
then later i call RegisterHotKey again as mentioned above
now when i press other key~~ a debug assertion failure Window pop up!
what's going on?
can anybody give me some advice?
|
|
|
|
|
What does the ASSERT say? You get a lot of information by examining it. (Press Retry in the assertion dialog.)
|
|
|
|
|
ASSERT say:
Debug Assertion Failure
XXXXXXXXXXXXXX
XXXXXXXXXXXXXX
for more information on how your program can cause an assertion
XXXXXXXXX
(Press Retry to debug he program)
then i press Retry
and VS locate:
_AFXCOLL_INLINE void*& CPtrList::GetNext(POSITION& rPosition)
{ CNode* pNode = (CNode*) rPosition;
ASSERT(AfxIsValidAddress(pNode, sizeof(CNode)));
if( pNode == NULL )
AfxThrowInvalidArgException();
rPosition = (POSITION) pNode->pNext;
return pNode->data; }
|
|
|
|
|
It basically says that the argument rPosition is not part of your container. It might have been at one stage, but has been deleted and is no longer valid.
Examine the call stack and see where it's coming from. That might give you a hint what the problem is.
|
|
|
|
|
seems that i know where problem come from!!
my dialog have no input box! but when i invoke hot key~
it will open a child ActiveX control window which have input box
then i input something
when i invoke hot key again
the Child ActiveX control window will be hidden
and go back to my dialog have no input box
when i press character key! the debug assertion failure window pop up
i think at that moment program still think he have input focus in the child ActiveX control window
but the window has been hidden!!
if so~~~ how can i solve this problem?????????
|
|
|
|
|
When you register the hot key, can't you just verify that the window handle is a valid one and that it is visible before registration? Use ::IsWindow(hwnd) and ::IsWindowVisible(hwnd)
|
|
|
|
|
I can't tell what goes wrong without seeing more of the relevant code, such as the call to UnRegisterHotKey and the next call to RegisterHotKey.
Are you using the same identifierForTest value?
Are you calling RegisterHotKey more than once without unregistering?
Do read the relevant MSDN pages, they contain useful remarks sections.
|
|
|
|
|
LRESULT CtestSDRDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if(message==WM_HOTKEY)
{
if (wParam==identiferForHelp)
{
if(m_bShow)
{
UnregisterHotKey(this->m_hWnd,identiferForTest);
theApp.m_bShorcutAllow=false;
}
else
{
RegisterHotKey(this->m_hWnd,identiferForTest,0,'T');
theApp.m_bShorcutAllow=true;
}
m_bShow=!m_bShow;
}
else if(wParam==identiferForTest)
{
AfxMessageBox(_T("hotkey 'T' invoked"));
}
}
return CDialog::WindowProc(message, wParam, lParam);
}
|
|
|
|
|
|
Hi!
I've to assign a multivalued string to a variable. If I use the following code only the last part is assigned to the variable. ie If I assign "Sri Lanka", only "Lanka" get assigned to the variable. This is the code:
array<stringc> ctyLst = SQLdb.Query("Select DISTINCT Team from Test ORDER BY Team DESC");
array<stringc> playerLst;
char query[512];
for(int i = 0; i<ctyLst.size(); i++)
{
ctyLst[i].trim();
printf("%s \n",ctyLst[i].c_str());
sprintf_s(query,512,"Select Name From Test WHERE Team=(%s) ORDER BY RANDOM() LIMIT 11",ctyLst[i].c_str());
playerLst = SQLdb.Query(query);
}
What to do to assign the full string to the variable Team?
|
|
|
|
|
What is stringc declared as? I would guess that its trim() function is a bit dodgy.
|
|
|
|
|
why do you put string literals in quotes in this message, and not in your SQL query?
what is the purpose of the parentheses in the WHERE clause???
|
|
|
|
|
I created a project with VS2008, dialog-based MFC.
What I want to do with that project is Sending 'User-defined-Message' in APP Class.
So I registered my own message in app class(xxxApp.h) like this:
#define USER_MESSAGE_2 (WM_USER+ 102)
And, in message map, I added ON_MESSAGE code in app class(xxxApp.cpp) like below:
BEGIN_MESSAGE_MAP(CwmUserApp, CWinAppEx)
ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
ON_MESSAGE( USER_MESSAGE_2, OnMyMessage1HandlerApp )
...
END_MESSAGE_MAP()
Also I wrote message handler like this:
LRESULT CwmUserApp::OnMyMessage1HandlerApp(WPARAM wParam, LPARAM lParam)
{
AfxMessageBox(_T("Is it working?"));
return 0;
}
I compiiled. Then one error came up:
error C2440: 'static_cast': 'LRESULT (__thiscall CwmUserApp::* )(WPARAM,LPARAM)'에서 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'(으)로 변환할 수 없습니다.
Sorry, it's korean. If I translate, it says
Can not convert from 'LRESULT (__thiscall CwmUserApp::* )(WPARAM,LPARAM)' to 'LRESULT (__thiscall CWnd::* )(WPARAM,LPARAM)'
I am not that good with programming, but as much as I understand,
Does that say I simply cannot use 'User-defined-Message' in APP class?
'User-defined-Message' in dlg class or view class works fine with me though.
Thanks in advance
chan
|
|
|
|
|
ON_MESSAGE
check the definition of ON_MESSAGE macro in afxmsg_.h
See: The type of the function must be afx_msg LRESULT (CWnd::*)(WPARAM, LPARAM).
|
|
|
|
|
The type of the function must be afx_msg LRESULT (CWnd::*)(WPARAM, LPARAM).
Which means, Some kind of type casting is needed?
I don't follow the details how to fix this problem;
Would you be more specific?
Thanks in advance
Chan
|
|
|
|
|
specifically, you have to write your ON_MESSAGE handler function in a CWnd derived class. If you have a window class CMyWnd which is derived from CWnd, then message map entry will be
ON_MESSAGE( USER_MESSAGE_2, &CMyWnd::OnMyMessage1HandlerApp )
Declare and define OnMyMessage1HandlerApp function in CMyWnd class.
|
|
|
|
|
Are you sure CWinApp derived classes can recieve arbitrary windows messages in MFC? I could be wrong but I thought they could only handle commands.
Cheers,
Ash
|
|
|
|
|
No. CWinApp derived class is never meant to handle windows messages. I forgot to mention him to move the ON_MESSAGE( USER_MESSAGE_2, &CMyWnd::OnMyMessage1HandlerApp ) entry to CMyWnd class's message map. Thanks..
He might have already done it, since he wouldn't find a way to SendMessage to a CWinApp derived class
Cheers..
|
|
|
|