473,397 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

How can I increment an integer one-at-a-time?

for (int i = 0; i < listBox2.Items.Count; i+=1)<<something like this?
{
thisString[i] = (string)listBox10.Items[i];
}
Any help is appreciated.
Thanks,
Trint

Nov 16 '05 #1
7 19761
+=1 will work just fine; although, the ++ operator provides the same
functionality.

Nov 16 '05 #2
Hi Trint,

use:

increment:
i++;
decrement
i--;

for (int i = 0; i < listBox2.Items.Count; i++)

sample one:

int i = 0;
Console.WriteLine(i++); <- value = 0
Console.WriteLine(i); <- value = 1

sample two: (value is incremented and then applied)
int i = 0;
Console.WriteLine(++i); <- value = 1 when printed

Hope this helps.

- Alex


- Alexander Rauser

http://www.flashshop.info

trint wrote:
for (int i = 0; i < listBox2.Items.Count; i+=1)<<something like this?
{
thisString[i] = (string)listBox10.Items[i];
}
Any help is appreciated.
Thanks,
Trint

Nov 16 '05 #3
Sorry, not what I meant...I want it to go through the incrementation
just once until it comes back to the beginning from another call.
Can I just put a break; at the bottom "}" and store where I was at?
Trint

..Net programmer
tr***********@gmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #4
I think you mean something like this

string getNext() {

if(currentIndex < listBox2.Items.Count)
listBox2[currentIndex]

}

"Alex" wrote:
Hi Trint,

use:

increment:
i++;
decrement
i--;

for (int i = 0; i < listBox2.Items.Count; i++)

sample one:

int i = 0;
Console.WriteLine(i++); <- value = 0
Console.WriteLine(i); <- value = 1

sample two: (value is incremented and then applied)
int i = 0;
Console.WriteLine(++i); <- value = 1 when printed

Hope this helps.

- Alex


- Alexander Rauser

http://www.flashshop.info

trint wrote:
for (int i = 0; i < listBox2.Items.Count; i+=1)<<something like this?
{
thisString[i] = (string)listBox10.Items[i];
}
Any help is appreciated.
Thanks,
Trint

Nov 16 '05 #5
I think you mean something like that:

public class {

private int currentIndex = 0;

void method() {

...

string str = getNext();
...

}

string getNext() {

if(currentIndex < listBox2.Items.Count) {
return listBox2[currentIndex++];
else {
currentIndex = 0;
return "";
}

}

}

So the answer is to declare a variable with a broader scope than a method
scope, an instance variabe for example and use it as index. In C there was a
static keyword you could use inside a function but it is not possible in C#.

"trint" wrote:
for (int i = 0; i < listBox2.Items.Count; i+=1)<<something like this?
{
thisString[i] = (string)listBox10.Items[i];
}
Any help is appreciated.
Thanks,
Trint

Nov 16 '05 #6
Hi Trint,

Could you explain in some more detail?
You can provide the index as a parameter in the method, if that is what
you mean
Just once sounds a bit like you don't need a loop at all, much like robkit
mentions.
You can combine the two and to

void GetItem(int i)
{
if(i < listBox2.Items.Count);
thisString[i] = (string)listBox10.Items[i];
}

On Mon, 07 Feb 2005 05:19:56 -0800, Trint Smith <tr***********@gmail.com>
wrote:
Sorry, not what I meant...I want it to go through the incrementation
just once until it comes back to the beginning from another call.
Can I just put a break; at the bottom "}" and store where I was at?
Trint

.Net programmer
tr***********@gmail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


--
Happy Coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #7
There is obviously more to GetItem and GetNextItem...I have tried both
suggestions and don't quiet get how to write it...here is what I did:

string getNext()
{

if(currentIndex < listBox2.Items.Count)
{
return listBox2[currentIndex++];
}
else
{
currentIndex = 0;
return "";
}
Thanks for the answers though,
Trint

Nov 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Gena | last post by:
Hi, Can anyone help me to increment the primary key's value on duplication without using mysql v 4.1 "on duplicate key" function? I can't upgrade to use the "on duplicate key" feature so am now...
3
by: Joseph Hill | last post by:
Hi My queries need to search for 1600 higher, and 1600 lower than a given integer. One integer is a 'northing' and another an 'easting' - map grid references. I would like the results...
7
by: mhk | last post by:
hi, is there any function in Javascript to check/validate integer value. there is parseInt(val) but it only checks first digit. example : to find error in 123k44
8
by: Mantorok Redgormor | last post by:
The only adder I was able to come up with for incrementing by one, uses a for loop. I was trying to do this without using a for loop while emulating i++(it's for obfuscated code) Anyone know...
38
by: Keith | last post by:
I've been reading and looking on the internet - but I just can't fin this. Perhaps I'm approaching this the wrong way - code-wise I'm attempting to learn how "things" work in VBNET by creating...
18
by: Bruno Baguette | last post by:
Hello, I have to design a table wich will store some action reports. Each report have an ID like this 1/2004, 2/2004, ... and each years, they restart to 1 (1/2004, 1/2005, 1/2006,...). So, I...
17
by: henrytcy | last post by:
Hi, How can I get a digit from integer for example, 12311, one by one for comparision? Thanks!
0
by: Michele 'xjp' | last post by:
Hi, I need a data structure (better if in STL) what give me: - an auto generated auto-increment integer field ('id') - various string fields This structure data must be searchable: I must be...
6
by: truezplaya | last post by:
Hey all I currently have an application in vb that reads and writes to a oracle table. My problem is getting it to write to the table as i wish to have the PK column as auto increment by one. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.