Can someone see my error with this line

Hello all.

This bit of code is making me frustrated 100 times over.

var i as integer

// ok. Let’s do this again…and SAVE IT, moron.
// so we will need to see the row index selected.

app.whatWAStheSelectedIndex = window1.ListBox1.SelectedRowIndex

//for testing only
MessageBox "The selected Row index is : " + app.whatWAStheSelectedIndex.ToString
MessageBox "The number of rows in the run is: "+ window1.ListBox1.RowCount.ToString

//so now let’s remove the rows from the selected Row Index to the end of the available rows.
for i = (window1.ListBox1.RowCount - 1) to (app.whatWAStheSelectedIndex) step -1
Window1.ListBox1.RemoveRowAt(i)
next i

//now let’s take the value that is in the listbox column 4 and make it our new currentdateandtime
app.theCurrentDateAndTime = DateTime.FromString (window1.ListBox1.CellTextAt(window1.ListBox1.SelectedRowIndex, 4))

//for testing only
MessageBox "The new value of current date time is : "+app.theCurrentDateAndTime.ToString

This bit:

app.theCurrentDateAndTime = DateTime.FromString (window1.ListBox1.CellTextAt(window1.ListBox1.SelectedRowIndex-1, 4))

works if I enter static text, but when I try to grab the cell from the column 4 of the row before, it gives me an OutOfBoundsException. I have verified that the row is indeed existing, but nothing I try will make it work.

I’m out of ideas. Does anyone out there see what I have done wrong?

Regards

I think the problem is when you call the CellTextAt() method, the row and column parameters are using a zero-based index, so the value should be 3 instead of 4, if you’re looking for column 4.

I hope that helps.

Hi there. Thanks for the response Scott.

I have it working now.
First error… the DUMB one, was that I was missing a closing bracket. Yeah I’m blind. :smiley:

Two when I entered the code, for some reason, I actually found a funny looking character in the code. looked like a piece of exploded lawn furniture. I think I might have accidentally held down option, or control or something.

This is the working code.

var i as integer
var j as integer
var localTheCurrentDateAndTime as DateTime

// ok. Let’s do this again…and SAVE IT, moron.
// so we will need to see the row index selected.

app.whatWAStheSelectedIndex = window1.ListBox1.SelectedRowIndex

//for testing only
MessageBox "The selected Row index is : " + app.whatWAStheSelectedIndex.ToString
MessageBox "The number of rows in the run is: "+ window1.ListBox1.RowCount.ToString

//so now let’s remove the rows from the selected Row Index to the end of the available rows.
for i = (window1.ListBox1.RowCount - 1) to (app.whatWAStheSelectedIndex) step -1
Window1.ListBox1.RemoveRowAt(i)
next i

//now let’s take the value that is in the listbox column 4 and make it our new currentdateandtime
app.theCurrentDateAndTime = DateTime.FromString (window1.ListBox1.CellTextAt(i, 4))

//for testing only
MessageBox "The new value of current date time is : "+app.theCurrentDateAndTime.ToString

When entering code into a post, please:

  1. Enter it
  2. Select it all
  3. Click the </> button

It makes it much more readable and avoids my slight tendency to ignore code not posted that way.

2 Likes

Sounds good.
I always choose the wrong one…