#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default Arrays

I cannot get an array to populate. There are a number of txtboxes on a form
filled with data.

Each time the txtboxes are filled a cmdbutton is clicked and the results are
saved to an array, the txtboxes are cleared ready for new data entry.
It works first time round but on the second round of txtbox renewal it fails
with Subscript out of Range.
Elsewhere in my code this structure works but there is only 1 dimension.

This is the code I am using:

Public enterArray() as Variant

In the initialise event:
enterCount=1 '''for reasons elsewhere in code

In the cmdbutton click event:
Sub Test()
ReDim Preserve enterArray(1 To enterCount, 0 to 4) ''''Fails
here
enterArray(enterCount, 0) = txtName.Text
enterArray(enterCount, 1) = txtNarrative.Text
enterArray(enterCount, 2) = txtDate.Text
enterArray(enterCount, 3) = txtInits.Text
enterCount = enterCount + 1
End Sub

Could someone please show me where I have gone wrong.

Thanks

Geoff

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Arrays

When you ReDim an array, you can only change the last dimension.

Maybe you can swap them:

ReDim Preserve enterArray(0 to 4, 1 To enterCount)

Geoff wrote:

I cannot get an array to populate. There are a number of txtboxes on a form
filled with data.

Each time the txtboxes are filled a cmdbutton is clicked and the results are
saved to an array, the txtboxes are cleared ready for new data entry.
It works first time round but on the second round of txtbox renewal it fails
with Subscript out of Range.
Elsewhere in my code this structure works but there is only 1 dimension.

This is the code I am using:

Public enterArray() as Variant

In the initialise event:
enterCount=1 '''for reasons elsewhere in code

In the cmdbutton click event:
Sub Test()
ReDim Preserve enterArray(1 To enterCount, 0 to 4) ''''Fails
here
enterArray(enterCount, 0) = txtName.Text
enterArray(enterCount, 1) = txtNarrative.Text
enterArray(enterCount, 2) = txtDate.Text
enterArray(enterCount, 3) = txtInits.Text
enterCount = enterCount + 1
End Sub

Could someone please show me where I have gone wrong.

Thanks

Geoff


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default Arrays

That's got me past that hurdle.

Now i just have to figure how to read them back.

Thank you. I had tried every variation.

Geoff

"Dave Peterson" wrote:

When you ReDim an array, you can only change the last dimension.

Maybe you can swap them:

ReDim Preserve enterArray(0 to 4, 1 To enterCount)

Geoff wrote:

I cannot get an array to populate. There are a number of txtboxes on a form
filled with data.

Each time the txtboxes are filled a cmdbutton is clicked and the results are
saved to an array, the txtboxes are cleared ready for new data entry.
It works first time round but on the second round of txtbox renewal it fails
with Subscript out of Range.
Elsewhere in my code this structure works but there is only 1 dimension.

This is the code I am using:

Public enterArray() as Variant

In the initialise event:
enterCount=1 '''for reasons elsewhere in code

In the cmdbutton click event:
Sub Test()
ReDim Preserve enterArray(1 To enterCount, 0 to 4) ''''Fails
here
enterArray(enterCount, 0) = txtName.Text
enterArray(enterCount, 1) = txtNarrative.Text
enterArray(enterCount, 2) = txtDate.Text
enterArray(enterCount, 3) = txtInits.Text
enterCount = enterCount + 1
End Sub

Could someone please show me where I have gone wrong.

Thanks

Geoff


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 371
Default Arrays

.......which I have just worked out. That was the easy after the advice!

<vbg

Many thanks.

Geoff

"Geoff" wrote:

That's got me past that hurdle.

Now i just have to figure how to read them back.

Thank you. I had tried every variation.

Geoff

"Dave Peterson" wrote:

When you ReDim an array, you can only change the last dimension.

Maybe you can swap them:

ReDim Preserve enterArray(0 to 4, 1 To enterCount)

Geoff wrote:

I cannot get an array to populate. There are a number of txtboxes on a form
filled with data.

Each time the txtboxes are filled a cmdbutton is clicked and the results are
saved to an array, the txtboxes are cleared ready for new data entry.
It works first time round but on the second round of txtbox renewal it fails
with Subscript out of Range.
Elsewhere in my code this structure works but there is only 1 dimension.

This is the code I am using:

Public enterArray() as Variant

In the initialise event:
enterCount=1 '''for reasons elsewhere in code

In the cmdbutton click event:
Sub Test()
ReDim Preserve enterArray(1 To enterCount, 0 to 4) ''''Fails
here
enterArray(enterCount, 0) = txtName.Text
enterArray(enterCount, 1) = txtNarrative.Text
enterArray(enterCount, 2) = txtDate.Text
enterArray(enterCount, 3) = txtInits.Text
enterCount = enterCount + 1
End Sub

Could someone please show me where I have gone wrong.

Thanks

Geoff


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Working with ranges in arrays... or an introduction to arrays Glen Excel Programming 5 September 10th 06 08:32 AM
Arrays - declaration, adding values to arrays and calculation Maxi[_2_] Excel Programming 1 August 17th 06 04:13 PM
arrays in arrays jacob Excel Programming 4 August 29th 04 08:40 PM
Arrays Kenny Excel Programming 5 August 26th 04 09:47 AM
ARRAYS Gary B[_3_] Excel Programming 8 July 14th 03 03:59 AM


All times are GMT +1. The time now is 06:36 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"