Moving from 3.3 to 4.1

When I moved a project from 3.3 to 4.1 I get a nil object exception when my sheet dialog box is shown that contains a weblistbox. I add the rows and set the column values and then show the listbox. It seems that my rows are being added at the wrong index. I updated a column to show the lastindex property. The 0’th row seems to be blank and the first row displays the last index = “0” and the second row displays the last index = “1”. The dialog displays ok…but when I try to do anything that iterates over the listbox rows…the 0th row is nil. I tried to reproduce the problem by adding another sheet with a listbox and can’t re-produce the problem. Seems to only affect my code that was carried over from 3.3 I’ll just rebuild the dialog under 4.1…but I wondered if anyone else had this happen and if there is a simple solution. I tried several things like removing the dialog reference from the webpage and re-adding it. No luck.

I guess this is “normal”? Step1) Open a new Web Project. Put a single button on the web page called called “open” Step 2) Add a dialog Sheet to the project. Place two controls on the sheet a) button called “close” b) a weblistbox. In the close button action…code “self.close”. 3) Add the dialog sheet to the web page. in the Open button action event, code the following.
Sheet11.ListBox1.AddRow("one "+str(Sheet11.ListBox1.LastIndex))
Sheet11.ListBox1.AddRow("two "+str(Sheet11.ListBox1.LastIndex))
Sheet11.ListBox1.AddRow("three "+str(Sheet11.ListBox1.LastIndex))
Sheet11.ListBox1.AddRow("four "+str(Sheet11.ListBox1.LastIndex))
Sheet11.ListBox1.AddRow("five "+str(Sheet11.ListBox1.LastIndex))
Sheet11.Show

Run the project and click on “open”.
What I see is:
one 0
two 0
three 1
four 2
five 3

Why does last index = 0 show up on both row zero and row 1?
Instead of updating the columns on the add row line I was doing this:

Sheet11.ListBox1.AddRow
Sheet11.ListBox1.Cell(Sheet11.ListBox1.LastIndex,0) = "one "+str(Sheet11.ListBox1.LastIndex)
Sheet11.ListBox1.AddRow
Sheet11.ListBox1.Cell(Sheet11.ListBox1.LastIndex,0) = "two "+str(Sheet11.ListBox1.LastIndex)
Sheet11.ListBox1.AddRow
Sheet11.ListBox1.Cell(Sheet11.ListBox1.LastIndex,0) = "three "+str(Sheet11.ListBox1.LastIndex)
Sheet11.ListBox1.AddRow
Sheet11.ListBox1.Cell(Sheet11.ListBox1.LastIndex,0) = "four "+str(Sheet11.ListBox1.LastIndex)
Sheet11.ListBox1.AddRow
Sheet11.ListBox1.Cell(Sheet11.ListBox1.LastIndex,0) = "five "+str(Sheet11.ListBox1.LastIndex)
Sheet11.Show

and this provides
one 0
two 1
three 2
four 3
five 4

I’m guessing the seeming discrepancy has to do with when AddRow updates the LastIndex property.

Right. You are doing two different things. In your first example you are getting LastIndex before AddRow has completed, so LastIndex refers to the prior row. It likely defaults to 0, which is why you get 0 on the first row.

In your second example, you call AddRow separately and then set the row text. So the LastIndex values are current.