如何为结尾的循环和开始循环。

编程入门 行业动态 更新时间:2024-10-28 04:19:06
本文介绍了如何为结尾的循环和开始循环。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好, 有人可以帮助或指导我学习一个例子。 我试图在列表控件中总列数为30列。 我的问题取决于每个用户列数可以从5更改为7或9个或更多。 我使用5作为例子: 如果我在第0列:我想总计第0,1,2,2,2,2栏。 如果我在第29栏:我想总共有第29,0,1,27,28栏。 目前我在for循环中有上述内容,if语句硬编码,总共5列。有没有办法,如果我允许用​​户从5改为7,我可以动态获得总数而不是硬编码。 任何帮助或指向正确的方向可能会有所帮助。 我有一些关于我目前正在做的事情的代码。

Hello all, Can someone please help or direct me to an example i can study. I am trying to total columns in a list control which has 30 columns. My problem is depending on each user the column count can change from 5 to 7 or 9 or more. I am using 5 as an example: if i am at column 0: I would like to have totals of column 0,1,2,28,29. if I am at column 29: I would like to have total of column 29,0,1,27,28. Currently I have the above in a for loop with an if statement hard coded with 5 column total. Is there a way, if i allow user to change from 5 to 7, I could dynamically get the total instead of it being hard coded. Any help or pointing in right direction might help. I have part of the code as to what I am currently doing.

for (int a=0; a<12;a++) { CString Temp; if (a==0) { Temp = m_Test.GetItemText(0,0); Temp = m_Test.GetItemText(0,11); Temp = m_Test.GetItemText(0,10); Temp = m_Test.GetItemText(0,1); Temp = m_Test.GetItemText(0,2); return; } if (a==1) { Temp = m_Test.GetItemText(0,1); Temp = m_Test.GetItemText(0,11); Temp = m_Test.GetItemText(0,0); Temp = m_Test.GetItemText(0,3); Temp = m_Test.GetItemText(0,2); return; } if (a==10) { Temp = m_Test.GetItemText(0,10); Temp = m_Test.GetItemText(0,11); Temp = m_Test.GetItemText(0,0); Temp = m_Test.GetItemText(0,9); Temp = m_Test.GetItemText(0,8); return; } if (a==11) { Temp = m_Test.GetItemText(0,11); Temp = m_Test.GetItemText(0,0); Temp = m_Test.GetItemText(0,1); Temp = m_Test.GetItemText(0,9); Temp = m_Test.GetItemText(0,10); return; } Temp = m_Test.GetItemText(0,a-1); Temp = m_Test.GetItemText(0,a-2); Temp = m_Test.GetItemText(0,a); Temp = m_Test.GetItemText(0,a+1); Temp = m_Test.GetItemText(0,a+2); }

推荐答案

你似乎缺少的是一种最后包装索引的方法柱。然后'%'(余数)运算符将为您提供一个工具。例如: What you appear to be missing is a method to wrap the index around at the last column. Then '%' (remainder) operator will give you a tool for that. For example: const int numOfColumns = 30; int idx = 28; int total = 0; for (int k = 0; k < 5; ++k) total += columns[(idx + k) % numOfColumns];

您似乎需要的另一种方法是将您从单元格中读取的字符串转换为数字:

The other thing you seem to need is a way of converting the string you read from a cell into a number:

CString s; s = m_Test.GetItemText(0,11); int x = atoi (s);

将为您做到这一点。结合这两件事你就完成了。

will do that for you. Combine these two things and you are done.

更多推荐

如何为结尾的循环和开始循环。

本文发布于:2023-11-29 19:11:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647361.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:何为   结尾

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!