5 Replies - 9328 Views - Last Post: 06 August 2012 - 07:30 AM Rate Topic: -----

#1 useletters  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 111
  • Joined: 20-November 08

Datagrid "Subscript out of range" Runtime Error '9'

Posted 02 August 2012 - 12:32 AM

I'm trying to fetch data from datagrid and send it to a textbox on a separate form.
Here's the code I use, it doesn't work.

Private Sub cmdEdit_Click()
frmPIR.txtDate.Text = frmEditReport.DataGrid1.Columns(3).Text
frmPIR.txtTime.Text = frmEditReport.DataGrid1.Columns(4).Text
frmPIR.txtLocation.Text = frmEditReport.DataGrid1.Columns(3).Text
frmPIR.Show
End Sub


It works if I only use one line.

Private Sub cmdEdit_Click()
frmPIR.txtDate.Text = frmEditReport.DataGrid1.Columns(3).Text
frmPIR.Show
End If
End Sub

This post has been edited by useletters: 02 August 2012 - 12:33 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Datagrid "Subscript out of range" Runtime Error '9'

#2 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 328
  • View blog
  • Posts: 1,990
  • Joined: 26-March 09

Re: Datagrid "Subscript out of range" Runtime Error '9'

Posted 02 August 2012 - 05:18 AM

Does your datagrid have the number of columns you're trying to access?

I'm assuming the error occurs on the call to column(4) as you haven't actually said?
Was This Post Helpful? 0
  • +
  • -

#3 BobRodes  Icon User is offline

  • Lovable Curmudgeon
  • member icon

Reputation: 600
  • View blog
  • Posts: 3,069
  • Joined: 19-May 09

Re: Datagrid "Subscript out of range" Runtime Error '9'

Posted 02 August 2012 - 06:07 AM

I'm assuming that you're using the .Net DataGrid control. If so, you probably think that because you have 4 columns, they are numbered 1 to 4. They aren't; as with all arrays and collections in .Net, the first element is 0, so they are numbered 0 to 3.

p. s. If you are in fact using .Net (VS 2005 or higher) and not VB6, (VS 6), please let me know so I can move this thread to the correct forum.

This post has been edited by BobRodes: 02 August 2012 - 06:08 AM

Was This Post Helpful? 0
  • +
  • -

#4 useletters  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 111
  • Joined: 20-November 08

Re: Datagrid "Subscript out of range" Runtime Error '9'

Posted 02 August 2012 - 06:07 PM

View PostBobRodes, on 02 August 2012 - 09:07 PM, said:

I'm assuming that you're using the .Net DataGrid control. If so, you probably think that because you have 4 columns, they are numbered 1 to 4. They aren't; as with all arrays and collections in .Net, the first element is 0, so they are numbered 0 to 3.

p. s. If you are in fact using .Net (VS 2005 or higher) and not VB6, (VS 6), please let me know so I can move this thread to the correct forum.


Hi, I'm using vb6. I think it should be '.value' instead of'.text' but it still doesn't work. And no, I know how columns are numbered. Thanks

View Postmaj3091, on 02 August 2012 - 08:18 PM, said:

Does your datagrid have the number of columns you're trying to access?

I'm assuming the error occurs on the call to column(4) as you haven't actually said?



Yes, actually the datagrid has more than 5 columns.

This post has been edited by useletters: 02 August 2012 - 06:09 PM

Was This Post Helpful? 0
  • +
  • -

#5 useletters  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 111
  • Joined: 20-November 08

Re: Datagrid "Subscript out of range" Runtime Error '9'

Posted 06 August 2012 - 04:54 AM

Bump...
Was This Post Helpful? 0
  • +
  • -

#6 BobRodes  Icon User is offline

  • Lovable Curmudgeon
  • member icon

Reputation: 600
  • View blog
  • Posts: 3,069
  • Joined: 19-May 09

Re: Datagrid "Subscript out of range" Runtime Error '9'

Posted 06 August 2012 - 07:30 AM

Ok, here's the doc on the VB6 DataGrid control. I never really used the DataGrid control; it got replaced with the MSFlexGrid control back in VB5, if I remember correctly. (Sorry that I forgot that it ever existed! Some people prefer to use it since it does what they want.) The doc is pretty sketchy anymore. However, I also found this which is worth a look too. I don't quite remember how the Columns property and the Col property interact, but I suspect that your problem has something to do with that. Anyway, you might go over the explanations in the second link and see if they help.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1