Again CListCtrl
-
no you dont understand i need row1+row2 = s1(or can be more than 2 rows) How?
Bravoone
-
YES !!!!!!
Bravoone
-
YES !!!!!!
Bravoone
-
put it in a for loop
int nsum = 0; for( int nRow = 0; nRow < m_lis.GetItemCount();nRow++) { for( int nColumn = 0; nColumn < 3;nColumn ++) { CString csText = GetItemText(nRow ,nColumn ); nsum += _atoi( csText); } }
nave
This is my problem is not working !why? CString csText = m_list1.GetItemText(nRow ,nColumn ); nsum += atoi( csText); m_sum.SetWindowText(csText);
Bravoone
-
put it in a for loop
int nsum = 0; for( int nRow = 0; nRow < m_lis.GetItemCount();nRow++) { for( int nColumn = 0; nColumn < 3;nColumn ++) { CString csText = GetItemText(nRow ,nColumn ); nsum += _atoi( csText); } }
nave
Why is not working ? int nsum = 0; for( int nRow = 0; nRow < m_list1.GetItemCount();nRow++) { for( int nColumn = 0; nColumn < 2;nColumn++) { CString csText = m_list1.GetItemText(nRow ,nColumn ); nsum += atoi( csText); m_sum.SetWindowText(csText); } }
Bravoone
-
Why is not working ? int nsum = 0; for( int nRow = 0; nRow < m_list1.GetItemCount();nRow++) { for( int nColumn = 0; nColumn < 2;nColumn++) { CString csText = m_list1.GetItemText(nRow ,nColumn ); nsum += atoi( csText); m_sum.SetWindowText(csText); } }
Bravoone
Bravoone_2006 wrote:
int nsum = 0;
Bravoone_2006 wrote:
m_sum.SetWindowText(csText);
Where you want to show csText?
WhiteSky
-
Why is not working ? int nsum = 0; for( int nRow = 0; nRow < m_list1.GetItemCount();nRow++) { for( int nColumn = 0; nColumn < 2;nColumn++) { CString csText = m_list1.GetItemText(nRow ,nColumn ); nsum += atoi( csText); m_sum.SetWindowText(csText); } }
Bravoone
int nsum = 0;
for( int nRow = 0; nRow < m_list1.GetItemCount();nRow++)
{
for( int nColumn = 0; nColumn < 2;nColumn++)
{
CString csText = m_list1.GetItemText(nRow ,nColumn );
nsum += atoi( csText);
m_sum.SetWindowText(csText);
}
}I would do it like this:
int CMyDialogBox::SumColumn(CListCtrl* pList, int nColumn)
{
// the first thing i'd do is make sure the specified column is within the
// range of available columns, but i'm goin g to leave that as an exercise
// for you// declare and initialize some vars int nSum = 0; int nRows = pList->GetItemCount(); CString csText = ""; // if we actually have rows to process if (nRows > 0) { // process each one for (int nRow = 0; nRow < nRows; nRow++) { // retrieve the text from the current row and specified column csText = pList->GetItemText(nRow ,nColumn ); // if the string isn't empty if (!csText.IsEmpty()) { // establish a string a valid characters so we can ensure // that the extracted string is in fact a number CString sNumbers = "0123456789"; // assume we have a valid integer value bool bIsValid = true; // check each character in the exttracted string for (int i = 0; i < csText.GetLength(); i++) { // if we find the character in the validation string, // the number might be valid bIsValid = (sNumbers.Find(csText.GetAt(i) < 0); // if the exttracted string wasn't valid if (!bIsValid) { // get out of the loop break; } } // if the exttracted string WAS valid, add the value to nSum if (bIsValid) { nSum += atoi( csText); } } } }
}
void CMyDialog::SomeFunction()
{
// by the way, if you want to sum the second column, you need to
// specify 1 as the second paramter
int nResult = SumColumn(&m_list1, 1);
CString csText;// turn nSum into a string - we can use the csText string we've // already been using csText.Format("%d", nSum); // put the csText string
-
int nsum = 0;
for( int nRow = 0; nRow < m_list1.GetItemCount();nRow++)
{
for( int nColumn = 0; nColumn < 2;nColumn++)
{
CString csText = m_list1.GetItemText(nRow ,nColumn );
nsum += atoi( csText);
m_sum.SetWindowText(csText);
}
}I would do it like this:
int CMyDialogBox::SumColumn(CListCtrl* pList, int nColumn)
{
// the first thing i'd do is make sure the specified column is within the
// range of available columns, but i'm goin g to leave that as an exercise
// for you// declare and initialize some vars int nSum = 0; int nRows = pList->GetItemCount(); CString csText = ""; // if we actually have rows to process if (nRows > 0) { // process each one for (int nRow = 0; nRow < nRows; nRow++) { // retrieve the text from the current row and specified column csText = pList->GetItemText(nRow ,nColumn ); // if the string isn't empty if (!csText.IsEmpty()) { // establish a string a valid characters so we can ensure // that the extracted string is in fact a number CString sNumbers = "0123456789"; // assume we have a valid integer value bool bIsValid = true; // check each character in the exttracted string for (int i = 0; i < csText.GetLength(); i++) { // if we find the character in the validation string, // the number might be valid bIsValid = (sNumbers.Find(csText.GetAt(i) < 0); // if the exttracted string wasn't valid if (!bIsValid) { // get out of the loop break; } } // if the exttracted string WAS valid, add the value to nSum if (bIsValid) { nSum += atoi( csText); } } } }
}
void CMyDialog::SomeFunction()
{
// by the way, if you want to sum the second column, you need to
// specify 1 as the second paramter
int nResult = SumColumn(&m_list1, 1);
CString csText;// turn nSum into a string - we can use the csText string we've // already been using csText.Format("%d", nSum); // put the csText string
John Simmons / outlaw programmer wrote:
NOTE: I didn't want to use the atoi function to determine the validity of the converted string because if it's not a number, it returns 0, which IS a number. It's also a VALID number, so you can't just assume that the return value is what you expect it to be. That's why I included code to check each character one at a time before trying to convert it to a numeric value.
So why not just use
strtol()
?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
John Simmons / outlaw programmer wrote:
NOTE: I didn't want to use the atoi function to determine the validity of the converted string because if it's not a number, it returns 0, which IS a number. It's also a VALID number, so you can't just assume that the return value is what you expect it to be. That's why I included code to check each character one at a time before trying to convert it to a numeric value.
So why not just use
strtol()
?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
DavidCrow wrote:
So why not just use strtol()?
Because like
atoi
, it returns ZERO if the string cannot be converted."Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
DavidCrow wrote:
So why not just use strtol()?
Because like
atoi
, it returns ZERO if the string cannot be converted."Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001True, but unlike
atoi()
, it has an argument that tells if the entire string was looked at or not.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
True, but unlike
atoi()
, it has an argument that tells if the entire string was looked at or not.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
There's a bunch of different ways to get to the same point. He used
atoi
, so I did to. The point really isn't worth arguing, IMHO, but y'all go right ahead and talk amongst yourselves."Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
int nsum = 0;
for( int nRow = 0; nRow < m_list1.GetItemCount();nRow++)
{
for( int nColumn = 0; nColumn < 2;nColumn++)
{
CString csText = m_list1.GetItemText(nRow ,nColumn );
nsum += atoi( csText);
m_sum.SetWindowText(csText);
}
}I would do it like this:
int CMyDialogBox::SumColumn(CListCtrl* pList, int nColumn)
{
// the first thing i'd do is make sure the specified column is within the
// range of available columns, but i'm goin g to leave that as an exercise
// for you// declare and initialize some vars int nSum = 0; int nRows = pList->GetItemCount(); CString csText = ""; // if we actually have rows to process if (nRows > 0) { // process each one for (int nRow = 0; nRow < nRows; nRow++) { // retrieve the text from the current row and specified column csText = pList->GetItemText(nRow ,nColumn ); // if the string isn't empty if (!csText.IsEmpty()) { // establish a string a valid characters so we can ensure // that the extracted string is in fact a number CString sNumbers = "0123456789"; // assume we have a valid integer value bool bIsValid = true; // check each character in the exttracted string for (int i = 0; i < csText.GetLength(); i++) { // if we find the character in the validation string, // the number might be valid bIsValid = (sNumbers.Find(csText.GetAt(i) < 0); // if the exttracted string wasn't valid if (!bIsValid) { // get out of the loop break; } } // if the exttracted string WAS valid, add the value to nSum if (bIsValid) { nSum += atoi( csText); } } } }
}
void CMyDialog::SomeFunction()
{
// by the way, if you want to sum the second column, you need to
// specify 1 as the second paramter
int nResult = SumColumn(&m_list1, 1);
CString csText;// turn nSum into a string - we can use the csText string we've // already been using csText.Format("%d", nSum); // put the csText string
Your answer was perfect.:-D
WhiteSky
-
Why is not working ? int nsum = 0; for( int nRow = 0; nRow < m_list1.GetItemCount();nRow++) { for( int nColumn = 0; nColumn < 2;nColumn++) { CString csText = m_list1.GetItemText(nRow ,nColumn ); nsum += atoi( csText); m_sum.SetWindowText(csText); } }
Bravoone
Bravoone_2006 wrote:
m_sum.SetWindowText(csText);
the SetWindowText() must be used after all the loop isn't?
int nsum = 0; for( int nRow = 0; nRow < m_list1.GetItemCount();nRow++) { for( int nColumn = 0; nColumn < 2;nColumn++) { CString csText = m_list1.GetItemText(nRow ,nColumn ); nsum += atoi( csText); } } **TCHAR tcsum[50] _itoa( nsum, tcsum, 10 ); m_sum.SetWindowText(tcsum);**
nave