Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > Resizing an array.


Reply
 
Thread Tools Display Modes
  #1  
Old 07-23-2012, 10:06 AM
MichaelDunne109 MichaelDunne109 is offline
Newcomer
 
Join Date: Feb 2012
Posts: 5
Default Resizing an array.


Hi guys,

Just looking over course work that I completed last semester and have come across a question that I just cant answer. This is just purely out of interest and is just for my own revision so im not cheating or anything by asking on here.

The question is:
Demonstrate how the first and second dimensions of
a 2-dimensional (2-D) array may be resized from a size of 3 by 6 to a size
of 7 by 15, respectively.


Now its been awhile since I looked over this stuff so my mind keeps drawing a blank. I know a Redim statement is used but after that im stumped. Heres my go at it. Im not sure is it right but please guide me in the right direction. Just as a point this is more of a conceptual question more than anything as in its never actually going to be compiled.

My Answer:
Code:
Dim myfirstArray (3,6) As String 'Creates a 3 by 6 array (in question) ReDim myfirstArray (7,15) 'Resizes the above array to 7 by 15
Is this right?

Thanks
Reply With Quote
  #2  
Old 07-23-2012, 10:31 AM
passel's Avatar
passel passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 7,714
Default

Why not compile (and run) it?
That is the best way to test code.

I assume your class did not use VB6, because it would not work there.
(in VB6 the initial array could not be declared Dim'd with bounds, it would either have to be ReDim'd initially with bounds (which is not allowed in VB.net) or Dim'd without any bounds Dim myfirstArray() as String to make it "dynamic".)

In VB.Net it would work, assuming the ReDim was in a procedure (sub or function).

It could be a trick question, since arrays are 0 based, the "size" of array myfirstArray(7, 15) is really 8 x 16, so if you were to take the question literally, then perhaps it should be an array with ubounds of (2,5) going to an array with ubounds of (6,14).
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->