|
// hey but adding a // at the end of the comment line says that the comment is over. We use in our VC++ //
/* you get me or not */ ?? ;P
<marquee scrollamount="1" scrolldelay="1" direction="up" height="10" step="1">--[ ]--
[My Current Status]
Link2006 wrote:Let's take it outside of CP
Jeremy : Please don't.I would love to see this.I'm making the popcorn already.
|
|
|
|
|
in my header file i wrote this code:
class CMyDlg : public CDialog
{
public:
int varCount;
vector<<int> intVec;
}
and in the cpp file wrote this code :
void CQMDlg::OnGetvarCountButton()
{
for(int i=0;i!=varCount;i++)
{
intVec.push_back(i);
}
}
there is no error in compilation but when i press that specific button, program hangs.
can somebody help me?
thanks
|
|
|
|
|
Have stepped in to the code ? what varCount is expected to initialize with? Probably its not initializing properly and going into loop.
|
|
|
|
|
How exactly have you initialized varCount ?
Your loop has a problem:
for(int i=0;i!=varCount;i++)
while i is not equal to varCount, thats just asking for trouble. Try changing it to
for(int i=0;i<varCount;i++)
|
|
|
|
|
thank you guys.
yes, my problem was in varCount initialization.
and i have another problem. when i write
intVec.
the property container menu of intVec doesn't appears.
|
|
|
|
|
Intellisense doesn't work ? That doesn't really matter, does it ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Many times, deleting .ncb file in project folder and rebuilding application do work.
|
|
|
|
|
thanks
i deleted the .ncb file and now it's working.
|
|
|
|
|
waldermort wrote: while i is not equal to varCount, thats just asking for trouble
How?
|
|
|
|
|
Because, it can easily happen, that you skip that specific value, for whatever reason. You could accidently increase the counter twice, initialize it with a value larger than varCount and stuff like that. It's just a matter of clean and readable code. If you want a loop to run as long as i is less or equal some other value, then you should write your condition that way. Lots of problems and timewasting during debugging happen due to such dirty practices.
Then again, STL-Iterators work just that way ( it = YourVector.begin(); it != YourVector.end(); it++ ), but that don't mean it's good =).
|
|
|
|
|
Actually, I dont follow coding style, by OP,too. All points mentioned by you are valid.
But in given code , that doesn't matter.
As revealed later, it was initializatin problem.
|
|
|
|
|
prasad_som wrote: But in given code , that doesn't matter.
As revealed later, it was initializatin problem.
Actually, he probably would have caught it sooner because I'm guessing it was something like this:
void CQMDlg::OnGetvarCountButton()
{
varCount = -1;
for(int i=0; i!=varCount; ++i)
{
intVec.push_back(i);
}
}
Which will run forever, whereas if the code was written as:
void CQMDlg::OnGetvarCountButton()
{
varCount = -1;
for(int i=0; i<varCount; ++i)
{
intVec.push_back(i);
}
}
It would have been caught immediately since the vector would have been empty.
As a side note, STL's iterators use != for a reason. For most of the containers, there is no guarantee that the memory locations are sequential, so you can't do a < comparison to find the end of the loop.
-- modified at 10:18 Thursday 21st September, 2006
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
Zac Howland wrote: for(int i=0; i!=varCount; ++i
True, I never come across such code,too.
|
|
|
|
|
Hello everyone,
I m trying to populate my Combobox but i m not successfull as yet.
as usuall I have enetred the data in properties DATA tab of ComboBox
I tryed with insertstring and additem method also but nothing is working.At runtime my ComboBox expands blankly it does not show any data
Thanx,
namy.
namy
|
|
|
|
|
|
Hello prasad,
Yes if u can please give the code
I m same namy i have just changed my name to namy1
thanx
|
|
|
|
|
Can you show snippet code
|
|
|
|
|
I have used this as well as the other one bellow not at same time definitely
char *names[3];
names[0] = "Joe";
names[1] = "Billy";
names[2] = "Bob";
for(int i=0;i<=2;i++)
m_ctrldestcombobox.AddString((LPCTSTR)names[i]);
*****************************************************************
m_ctrldestcombobox.InsertString(1, "SAP R/3");
m_ctrldestcombobox.InsertString(2, "PLM SERVER");
thanx pls reply even if i m acting foolishly
|
|
|
|
|
namy1 wrote: char *names[3];
names[0] = "Joe";
names[1] = "Billy";
names[2] = "Bob";
for(int i=0;i<=2;i++)
m_ctrldestcombobox.AddString((LPCTSTR)names[i]);
As seems, you are using VS2005. This code works fine with small modification
CString names[3];
names[0] = "Joe";
names[1] = "Billy";
names[2] = "Bob";
for(int i=0;i<=2;i++)
m_combo.AddString(names[i]);
|
|
|
|
|
I tested your code it was working,did you check return value of AddString what return value?
|
|
|
|
|
namy31 wrote: as usuall I have enetred the data in properties DATA tab of ComboBox
If you have entered string there, it should be semicolon(; ) separated.
|
|
|
|
|
No semicolon is required.
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
DavidCrow wrote: No semicolon is required.
In original post, he mentioned setting data using DATA field in properties window. There you have to insert data (; ) separated.
Let's say I want to display three items added initialy viz. "tom","dick" and "harry", you can add it in DATA field with (; ) as separator; as "tom;dick;harry "
|
|
|
|
|
prasad_som wrote: There you have to insert data (;) separated.
No you don't. Each item goes on a separate line. No semicolon is required. This is in the context of VC++ v6.
"Talent without discipline is like an octopus on roller skates. There's plenty of movement, but you never know if it's going to be forward, backwards, or sideways." - H. Jackson Brown, Jr.
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
Ohh ! I was talking in VS 2005 context.
|
|
|
|