473,323 Members | 1,551 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,323 software developers and data experts.

assistance with moving through loops

Hi

I have some code that will prepare a text file that can be read by another
application. The code is supposed to collect information on the starting
point of a range, then end point of the range and the interval to create
categories. For example if the start is 5 and the end is 25 and the
interval is 5, then the application should return a text file with the body
as follows:

<name>
5 - 10 ='5 to 10'
10-15='10 to 15
15-20='15 to 20'
20-25='20 to 25'
......

I am having trouble getting the interval to work as i dont fully understand
the complexity(or simplicity) of the loop. I appear to be putting bandaids
on errors and getting my code to complex. Could someone help me to simplify
this and I will hopefully learn a bit more about the program logic.
My form has 4 fields in test boxes - tbName, tbStart, tbEnd, tbInterval
private void btnOK_Click(object sender, System.EventArgs e)

{

if (int.Parse(tbStart.Text)>int.Parse(tbEnd.Text))

MessageBox.Show("The value in the End box is less than the Start");
double Vend =System.Convert.ToDouble(tbEnd.Text);

double Interval=System.Convert.ToDouble(tbInterval.Text);

double Start=System.Convert.ToDouble(tbStart.Text);

double Ends=System.Convert.ToDouble(tbEnd.Text);

double counter=(Vend/Start)-Interval;

if ((Vend-Start) %Interval>0 )

MessageBox.Show("The interval is not a readily divisible into the End
value");

string fmtname=tbName.Text.ToString();

string fmtstart=tbStart.Text.ToString();

string fmtend=tbEnd.Text.ToString();

double starts=Convert.ToDouble(fmtstart);

double ends=Convert.ToDouble(fmtend);

double first =starts+Interval;

using (StreamWriter sw = new StreamWriter(string.Format(@"c:\{0}.txt",
fmtname)))

{

sw.WriteLine("Proc format; ");

sw.WriteLine("value {0}",fmtname) ;
sw.WriteLine("{0} - {1} = '{0} to {1}'",starts, first);

for (int i = 1; i <= counter; i++)

{

starts=starts+Interval;

ends=starts+Interval;

sw.WriteLine("{0} - {1} = '{0} to {1}'",starts, ends);

}

sw.WriteLine("; ");

sw.WriteLine("run;");

MessageBox.Show(string.Format("File written to {0}.txt", fmtname));

}

}

when i run this i only get one element output in the file.

Any help appreciated - especially pointing out which bits i can do better.

thanks

Doug
Feb 25 '06 #1
1 1120
Hi Gordon
you can use the following code :

int end = 30;
int start = 10;
int interval = 5;
int count = end / start;
for (int i = start; i < end; i += interval)
MessageBox.Show (string.Format("{0} - {1} = '{0} to
{1}'", i , i + interval ));

Feb 25 '06 #2

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

Similar topics

4
by: Dalan | last post by:
I presume that using an open recordset method is the preferred method of accomplishing what I'm trying to do. Of course, if there are other options that would work, feel free to share them. I...
0
by: Randall Skelton | last post by:
Hi all, I have begun the slow process of shuffling data from about 125 narrow tables into a single wide table and I am seeking some insight on the 'fastest way.' The narrow tables are all of...
4
by: HMS Surprise | last post by:
Just wondered if there was some python idiom for moving a few items from one list to another. I often need to delete 2 or 3 items from one list and put them in another. Delete doesn't seem to have...
15
by: mcjason | last post by:
I saw something interesting about a grid pair puzzle problem that it looks like a machine when you find each that work out the way it does and say with all the others that work out the way they...
0
by: UWALAKA | last post by:
> FROM THE DESK OF DIRECTOR GENERAL F.M.A LAGOS EMAIL, dranthfiles1@indiatimes.com Good Day, I Dr.ANTHONY UWALAKA presently I am the director general of finance in the federal ministry of...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.