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


.



Relevant Pages

  • Re: Like this tremolo - Recuerdes
    ... The proposed hypothetical involved voicing the contour of a chord ... below a tonic on the sixth string, and you want not to be able support ... It's no overstatement to speak of instruments' limitations, ... I agree with you about gain, loss, and simplicity. ...
    (rec.music.classical.guitar)
  • Generic Web Service Support
    ... I would like to write a simple web service (for simplicity, ... stateless, returns a string given a couple of strings as arguments, ... say) as a Java class and then "plug it in" to a server that provides a ... posts them as URL parameters to the ...
    (comp.lang.java.programmer)
  • Re: bug reading /proc/sys/kernel/*: only first byte read.
    ... Eric W. Biederman wrote: ... deliberately for simplicity. ... Getting the string side of this fixed even by itself is ... worthwhile, although it might be worth teach people ...
    (Linux-Kernel)
  • Re: Identifying an exact binary representation
    ... Bernhard Enders wrote: ... simplicity, it is not necessary to represent it as a string, maybe it ...
    (comp.lang.fortran)
  • extension_pack
    ... It is used to set upper loop -- limits for non-deterministic values thus avoiding the use of access -- types and enabling the functions to be used for synthesizeable code. ... DivisorVal: integer) return std_logic_vector; function "/"(DividendVal: string; DivisorVal: integer) return std_logic_vector; ... for loopVar in 0 to slvVal'length/4-1 loop ... end loop; if then return not resultVar; -- "width mismatch" errors here are due to improper sizing of the vector that this function is assigned to else return resultVar; -- "width mismatch" errors here are due to improper sizing of the vector that this function is assigned to end if; ...
    (comp.lang.vhdl)