|
hi. im new to vc++ and i need some help. im tryin to break a string into tokens, but the problem is that this loops runs one time more then it is supposed to .e.g. for a string with 4 tokens it runs 5 times on the 5th run it displays an empty message box and then i get "debug assertion failed" and something about Expression iStart>=0.
if i remove the while it runs once but without the error.
//m_LineList is a CStringList
POSITION pos = m_LineList.GetHeadPosition() ;
int strpos = 0;
CString str;
str = m_LineList.GetNext( pos );
CString temp="";
while ( str != '\0')
{
temp = str.Tokenize( "," , strpos );
MessageBox(temp);
};
|
|
|
|
|
Deviantizh wrote: while ( str != '\0')
What's this? I seriously doubt you'll be able to successfully make this comparison. Use the IsEmpty() method instead.
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
|
|
|
|
|
I don't think the original string is modified by Tokenize, thus checking it will not work. You could check the return for an empty string, but you could have empty tokens. Off the top of my head, I'd suggest testing strpos (this solution was not tested; it's just a quick guess):
CString temp;<br />
while (strpos < str.GetLength())<br />
{<br />
temp = str.Tokenize(",", strpos);<br />
MessageBox(temp);<br />
}
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
-- modified at 11:49 Tuesday 21st February, 2006
|
|
|
|
|
thanx ill try that out
|
|
|
|
|
the problem is that
pos is set to -1 if no more separators can be found.
the solution u proposed works for that simple loop but in the following code it after displaying the entire row(all the tokens) the application hangs. can you please figure out why that is ?
while(pos != NULL)//while thr is data present
{
//MessageBox(m_LineList.GetNext( pos ));
str = m_LineList.GetNext( pos );
while( str != '\0' )//while not end of string
{
for(int i=1;i
|
|
|
|
|
str will never be modified, you have an endless loop.
the atoi line is converting str, not temp.
atoi is converting string to intenger, not float
you aren't checking strpos.
The code doesn't make much sense since the outer loop implies you have multiple matrices, which you clearly don't. Are you tring to read a row at a time, or all the rows as one string? If the latter, you need to change the scope of your loops. I'll leave that as an excercise for you.
while(pos != NULL)<br />
{<br />
CString str = m_LineList.GetNext(pos);<br />
int strpos = 0;<br />
<br />
for(int i = 1; i < 3 && strpos >= 0; i++)<br />
{<br />
for (int j = 1; j < 3 && strpos >= 0; j++)<br />
{<br />
CString temp = str.Tokenize( ", " , strpos );<br />
if (strpos >= 0)<br />
{<br />
simmatrix[i][j]= temp.IsEmpty() ? 0.0f : (float) atof(temp);<br />
MessageBox(temp);<br />
}<br />
}<br />
}<br />
}
If you put this in a function, you could simplify the strpos tests.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
thanks, got the stuff workin
|
|
|
|
|
I was wondering if I can modify the colors of the scrollbars of some text boxes...something similar to what CSS does in HTML. Because this would make my application more interesting.
in css the code would be
scrollbar-face-color:005585;<br />
scrollbar-highlight-color:005585;<br />
scrollbar-3dlight-color:005585;<br />
scrollbar-shadow-color:005585;<br />
scrollbar-darkshadow-color:FFFFFF;<br />
scrollbar-arrow-color:FFFFFF;<br />
scrollbar-track-color:FFFFFF;
This code modifies the color of the scrollbars of internet explorer, but also of the textareas.
|
|
|
|
|
Ummm, the user sets his colors, and probably doesn't want applications mucking around with them. Bad idea.
------- sig starts
"I've heard some drivers saying, 'We're going too fast here...'. If you're not here to race, go the hell home - don't come here and grumble about going too fast. Why don't you tie a kerosene rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hello,
I am using a 3rd party SDK to display inventory of a machine; anyway after using the following code I close my application in debug mode and it throws an ASSERT error (listed below). This looks to me like the object either isn't being destroyed properly or the refrence count is incorrect for what ever reason...
Any ideas?
<code>
IDatabasePtr ptr = NULL;
IInventoryPtr inventory = NULL;
int result = 0;
CWaitCursor wait;
try
{
ptr.CreateInstance(__uuidof(Database), NULL, CLSCTX_INPROC_SERVER);
result = ptr->SetConnectionString(_bstr_t(strConnectionString));
if (result == 0)
AfxMessageBox("Database connect failed.");
else
{
try
{
inventory.CreateInstance(__uuidof(Inventory), NULL, CLSCTX_INPROC_SERVER);
inventory->ShowInventoryTree(lComputerIDN);
}
catch (_com_error&)
{
AfxMessageBox("COM Error: Failed");
}
}
}
catch(_com_error&)
{
AfxMessageBox("COM Error: Failed");
}</code>
Here's the error in debug.
<code>CCmdTarget::~CCmdTarget()
{
#ifndef _AFX_NO_OLE_SUPPORT
if (m_xDispatch.m_vtbl != 0)
((COleDispatchImpl*)&m_xDispatch)->Disconnect();
ASSERT(m_dwRef <= 1);
Whoever said nothing's impossible never tried slamming a revolving door!
-- modified at 11:06 Tuesday 21st February, 2006
|
|
|
|
|
Hi all,
While working with print templates I got into a situation where my JavaScript loaded ActiveX control was not filling my m_spClientSite with a value other than NULL.
After wrestling with it for a while I decided to take a back door. It was necessary for me to access the COM interfaces in my instance of IE so I went to the Running Object Table. I enumerated its contents and was relaxed when I saw 3 IE entries as that was the number of IE windows I had open. Each one had been opened from the other. My problem is that all the IE objects in the ROT have the values of the first IE window opened (unfortunately not the one I wanted).
So my question is: is there a way of access the other IE COM interfaces?
Or even more helpful: what's the procedure when you control hasn't got a useful value in its m_spClientSite.
Thanks loads for any help
Tom
|
|
|
|
|
As I understand it you want to access IE interfaces from an ActiveX control hosted by it but IOleObject::SetClientSite hasn't been called on your control yet. This is a situation that should never happen, something is going wrong - perhaps your code is trying to access IE's interfaces before the control is hosted properly. My advise would be to try to find the source of the problem and not "hack around" it - You'll just make more trouble for yourself.
Steve
|
|
|
|
|
Thanks Steve.
That which should never happen seem to be a common occurance using print templates though.
Tom
|
|
|
|
|
i not want use
void a()
{
}
void b()
{
}
a_funlen = b - a
|
|
|
|
|
What is your question?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
|
|
|
|
|
a function compile and link, in exe's length
int fun()
{
__asm mov eax, 1
__asm ret 0
}
mov eax, 1 == b8 01 00 00 00
ret 0 == c3
so the fun length is 6
|
|
|
|
|
The best way is to have the compiler produce assembly code. Go to project properties | C/C++ | Output Files | Assemler Output. Select "Assembly, Machine-Source and Code." The output will be ".cod" files in your object directory.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
How can I tell MessageBox() to switch to next row?
I tried "\n" and it seems not working.
|
|
|
|
|
Sometime you have to use \r\n
(or \n\r... I don't remember)
Bye
Have a nice code day
|
|
|
|
|
what about in an editbox? how can I tell it to switch the line?
|
|
|
|
|
well, if you found a solution on the messagebox, then use the same solution there.
I suppose that is needed \r\n .
Have you already tryed, and it doesn't work?
Have a nice code day
|
|
|
|
|
I will try it after work, no C++ in my office.
Thanks
|
|
|
|
|
Make sure you have multiline selected for the edit box too...
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
I just tried, it works like a charm, big help!
|
|
|
|
|
\n is normally only for consoles in win32.
The win32 user interface is working with \r\n.
Don't try it, just do it!
|
|
|
|