Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2007

Tip: Looking for answers? Try searching our database.

variable-sized arrays?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rick Charnes - 30 Aug 2007 18:41 GMT
I don't seem to be able to assign a variable-sized array in a sub:

Dim strCode() As String
strCode(1) = "hello"

tells me "Subscript out of range".  What am I doing wrong?  Thanks.
Karl E. Peterson - 30 Aug 2007 18:52 GMT
> I don't seem to be able to assign a variable-sized array in a sub:
>
> Dim strCode() As String
> strCode(1) = "hello"
>
> tells me "Subscript out of range".  What am I doing wrong?  Thanks.

The empty parens in the original Dim only set it up as a dynamic array, which *may*
be resized.  You still need to explicitly resize it, as needed, when needed.

 Dim strCode() As String
 ' ...
 ReDim strCode(0 To 9) As String
 strCode(1) = "hello"
 ' ...
 ReDim Preserve(0 To 19) As String
 strCode(11) = "whatever"
 ' ...

Like that.
Signature

.NET: It's About Trust!
http://vfred.mvps.org

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.