Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default Working with an array

Excel 2002, WinXP
The MsgBox in this simple macro produces Two, Three in turn. It skips the
One.
But if I change the "1" in the For statement to a "0", I get One, Two,
Three.
Why does this happen?
Thanks for your help. Otto

Public TheArray() As Variant
Dim c As Long

Sub MacroOne()
ReDim TheArray(1 To 3)
TheArray = Array("One", "Two", "Three")
For c = 1 To UBound(TheArray)
MsgBox TheArray(c)
Next
End Sub


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

Put a watch on TheArray and step through your code.

When I did it, assigning the array redimmed TheArray(0 to 2).

If I added "option base 1", it redimmed it again, but started at 1 (much like
not redimming it at all):

Option Base 1
Sub MacroOne()
Dim c as long
ReDim TheArray(1 To 3)
TheArray = Array("One", "Two", "Three")
For c = 1 To UBound(TheArray)
MsgBox TheArray(c)
Next
End Sub

But I think I'd just use:

Sub MacroOneA()
Dim c as long
Dim TheArray as Variant
TheArray = Array("One", "Two", "Three")
For c = lbound(TheArray) To UBound(TheArray)
MsgBox TheArray(c)
Next
End Sub

And never have to worry about it again.

Otto Moehrbach wrote:

Excel 2002, WinXP
The MsgBox in this simple macro produces Two, Three in turn. It skips the
One.
But if I change the "1" in the For statement to a "0", I get One, Two,
Three.
Why does this happen?
Thanks for your help. Otto

Public TheArray() As Variant
Dim c As Long

Sub MacroOne()
ReDim TheArray(1 To 3)
TheArray = Array("One", "Two", "Three")
For c = 1 To UBound(TheArray)
MsgBox TheArray(c)
Next
End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,090
Default Working with an array

Thanks Dave. You've come through again. Otto
"Dave Peterson" wrote in message
...
Put a watch on TheArray and step through your code.

When I did it, assigning the array redimmed TheArray(0 to 2).

If I added "option base 1", it redimmed it again, but started at 1 (much
like
not redimming it at all):

Option Base 1
Sub MacroOne()
Dim c as long
ReDim TheArray(1 To 3)
TheArray = Array("One", "Two", "Three")
For c = 1 To UBound(TheArray)
MsgBox TheArray(c)
Next
End Sub

But I think I'd just use:

Sub MacroOneA()
Dim c as long
Dim TheArray as Variant
TheArray = Array("One", "Two", "Three")
For c = lbound(TheArray) To UBound(TheArray)
MsgBox TheArray(c)
Next
End Sub

And never have to worry about it again.

Otto Moehrbach wrote:

Excel 2002, WinXP
The MsgBox in this simple macro produces Two, Three in turn. It skips
the
One.
But if I change the "1" in the For statement to a "0", I get One, Two,
Three.
Why does this happen?
Thanks for your help. Otto

Public TheArray() As Variant
Dim c As Long

Sub MacroOne()
ReDim TheArray(1 To 3)
TheArray = Array("One", "Two", "Three")
For c = 1 To UBound(TheArray)
MsgBox TheArray(c)
Next
End Sub


--

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
array not working James Excel Discussion (Misc queries) 1 October 16th 09 05:45 PM
3d array not working D Excel Worksheet Functions 3 November 2nd 07 03:36 PM
CountIf Array not working NWO Excel Discussion (Misc queries) 1 March 1st 07 07:48 PM
Sum not working on Array ExcelMonkey[_190_] Excel Programming 1 February 25th 05 06:46 PM
Working with array equations OkieViking Excel Discussion (Misc queries) 2 January 23rd 05 07:43 AM


All times are GMT +1. The time now is 05:59 AM.

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

About Us

"It's about Microsoft Excel"