You will need a kind of dialog box to input the numbers. A dialog box will wait for the user to press enter of click on OK button.
iMax := 0; iMin := 1e8; sum := 0; dlg := TIntegerInputDialog.Create(); for i := 1 to 5 do begin num := dlg.GetInput; iMax := Max(iMax, num); iMin := Min(iMIn, num); sum := sum + num; end; dlg.Free; before that... define a dialog box, just a form with a edit box TIntegerInputDialog = class(TForm) published Edit1: TEdit; ... ... public function GetInput: Integer; end; ... .. function TIntegerInputDialog.GetInput: Integer begin // open the dialog ShowModal; // return the integer from TEdit result := StrToIntDef(Edit1.Text, 0); end; Hope this will help! On Tue, Feb 26, 2008 at 5:44 AM, Rob Kennedy <[EMAIL PROTECTED]> wrote: > Wilna Smith wrote: > > Is there a way in which can use a for-loop to read numerical values > > from a edit box? I know a Inputbox will work better, but is there a > > way to make this code work? > > It would help if you described what you wanted it to do, and in what way > it fails to accomplish that. > > > sum := 0; > > iMax := 0; > > iMin := 1000000000; > > You sort of have the right idea. Set the minimum to a big number so that > any smaller number forces the minimum down. But what if I enter > 1000000001? If that's the only number I've entered, it's clearly the > minimum. > > Set the minimum to the largest possible value, and set the maximum to > the smallest possible value. Those are MaxInt and -MaxInt-1, > respectively. You can also call them High(iMin) and Low(iMax). > > > for j := 1 to 5 do > > begin > > sNumber := edtNum.text; > > iNumber := StrToInt(sNumber); > > if iNumber > iMax then iMax := iNumber; > > if iNumber < iMin then iMin := iNumber; > > sum := sum + iNumber; > > edtNum.text := '0'; > > edtNum.SetFocus; > > aPPLICATION.ProcessMessages; > > end; > > btnGo.Enabled := false; > > rAvg := sum / j; > > The value of a loop-control variable is _undefined_ once the loop > terminates. > > But don't worry about that; a loop is inappropriate here. > > > lblMax.Caption := 'Maximum value: ' + IntToStr(iMax); > > lblMin.caption := 'Minimum value: ' + IntToStr(iMin); > > lblAvg.Caption := 'Average value: ' + FloatToStrF(rAvg, ffFixed, > > 2,2); > > > > The loop is only enters one value - due to the .ProcessMessages, else > > no values gets read. > > I think what you want is to read five values from the user, and you want > to do it with just one edit box instead of five. Each time the user > presses "Go," you want to add the next number to your collection to get > statistics. > > Phrased that way, the solution using event-based methods practically > writes itself. If your assignment requires you to use a "for" loop, then > please provide more details. > > "Each time the user presses 'Go'": Make an OnClick event handler for the > "Go" button. Do one number's worth of processing in that method. Keep > track of how many numbers you've gotten, and when you've read the right > number of them, make sure the user can't submit any more. > > -- > Rob > > -- http://www.blitzfoto.nl http://www.fdevblog.net Linked in: http://www.linkedin.com/in/heruutomo [Non-text portions of this message have been removed]

