New topic: 

For loop exceeds its bounds

<http://forums.realsoftware.com/viewtopic.php?t=47902>

         Page 1 of 1
   [ 5 posts ]                 Previous topic | Next topic          Author  
Message        torrid          Post subject: For loop exceeds its boundsPosted: 
Thu May 16, 2013 9:42 pm                                 
Joined: Sat Jun 04, 2011 8:29 am
Posts: 384                This is really bizarre.  It is happening on Windows.

Dim i As Integer

  For i = 1 To (sGrid1.Rows)

  If (sVal(i, sCol.Value("expenses2")) > 0) And (sVal(i, sCol.Value("age0")) >= 
gClient.RetAge) Then
    tmpMax = sVal(i, sCol.Value("expenses2")) + sVal(i, sCol.Value("rigoal"))  
  Else
    tmpMax = sVal(i, sCol.Value("rigoal"))  
  End If
  if i > 57 then
  MsgBox("i=<" + Str(i) + "> sGrid1 has this many rows:<" + Str(sGrid1.Rows) + 
">")
  End if
  End if
  
  Next
  
sGrid1.Rows = 57 
but i is zooming past it to higher values.
Usually this type of error occurs because the code inside the loop accidentally 
manipulates the i loop variable... but in this case the code does not...this 
code has worked for awhile but now it does not seem to work and is causing the 
program to crash when it then goes into the arrays because i is too bug and 
exceeds the number of values available.

Is this a bug in the grid control?
How would I debug this?

I added code like this inside at the top of the loop:
  // BUG On windows... see i = 58 but sGRid1.Rows = 57 .... MAKES NO SENSE
  if i > sGrid1.Rows Then
  Exit
  End if

But the build still crashes. Any ideas or suggestions appreciated.      
_________________
Currently using:
Windows XP Pro SP3
Real Studio 2011 Release 4.3 Enterprise
and
Mac OS 10.7.4
Real Studio 2011 Release 4.3 Enterprise
(finally also compiled on Mac)  
                             Top                kermit          Post subject: 
Re: For loop exceeds its boundsPosted: Fri May 17, 2013 1:21 am                 
        
Joined: Mon May 30, 2011 12:56 am
Posts: 692                sVal(i, sCol.Value("rigoal")) 

is the sVal (integer, string)  method declared  with byRef or byVal?

.or in other words, check happens to i in the sVal function??

if sVal is like this:

function sVal(byRef n as integer, s as string) as integer
  dim x as integer
  for x = 1 to 99
  if x = something then
  n = x  <-----
  end if
  next x
end function



This is a silly example, but what I mean is assigning a value to the variable n 
INSIDE this method, actually changes the value of the variable i OUTSIDE of it. 
  
                             Top                charonn0          Post subject: 
Re: For loop exceeds its boundsPosted: Fri May 17, 2013 2:52 am                 
                
Joined: Mon Apr 02, 2007 2:08 am
Posts: 1210
Location: San Francisco, CA, USA                Debug the application and 
single-step through the loop while keeping an eye on the i variable. It should 
only change at a loop boundary; if it changes within the loop, then the problem 
line is the line that just executed.      
_________________
Boredom Software  
                             Top                torrid          Post subject: 
Re: For loop exceeds its boundsPosted: Fri May 17, 2013 9:17 am                 
                
Joined: Sat Jun 04, 2011 8:29 am
Posts: 384                It's just an array not a function:

sVal(-1,-1) As Double   
                             Top                wbgookin          Post subject: 
Re: For loop exceeds its boundsPosted: Fri May 17, 2013 9:59 am                 
        
Joined: Sat Aug 22, 2009 9:44 am
Posts: 314                Is there an extra "end if" in your loop that's 
referring to something outside of it, or is that a typo?   
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 5 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to