Current location: Hot Scripts Forums » Programming Languages » Visual Basic » Dynamic Arrays and Objects


Dynamic Arrays and Objects

Reply
  #1 (permalink)  
Old 11-03-08, 06:34 AM
ProBowlUK ProBowlUK is offline
New Member
 
Join Date: Oct 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Question Dynamic Arrays and Objects

Hi

Not sure if this belongs here or in ASP.
Read several textbooks and tutorials, but can't seem to get complete understanding.

Problem is with ARRAYS and ReDim Preserve

Supposing you have an array of 4 houses with their details ...
PRICE, Desc, Location .... arrHouses(4,3)
To add another detail (eg: Type) is straight forward.
To add another house with Redim, you have to turn the array around -
(3,4) to become (3,5). How is that done ?


Can anyone give a really clear explanation of Dynamic Arrays, also for creating and using Objects for the same kind of webpage.


Cheers
Reply With Quote
  #2 (permalink)  
Old 11-11-08, 09:46 AM
Yeroon's Avatar
Yeroon Yeroon is offline
Code Master
 
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
Maybe this an idea?:

Code:
<% 
Dim arrAttributes(3) '3 = attributes
Dim arrHouses(2) ' 2= houses

'attributes house 1
arrAttributes(0) = "1A"
arrAttributes(1) = "1B"
arrAttributes(2) = "1C"

'set house attributes
arrHouses(0) = arrAttributes

'attributes house 2
ReDim arrAttributes(3) ' ReDim no preserve, so we get new array
arrAttributes(0) = "2A"
arrAttributes(1) = "2B"
arrAttributes(2) = "2C"
'set house attributes
arrHouses(1) = arrAttributes


'redim house array to hold 3 houses. use preserve, to preserve data
ReDim Preserve arrHouses(3)
ReDim arrAttributes(3) ' ReDim no preserve, so we get new array
arrAttributes(0) = "3A"
arrAttributes(1) = "3B"
arrAttributes(2) = "3C"
'set house attributes
arrHouses(2) = arrAttributes

Response.Write(arrHouses(0)(0))
Response.Write(arrHouses(1)(0))
Response.Write(arrHouses(2)(0))


%>
Output: 1A2A3A
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
Reply With Quote
  #3 (permalink)  
Old 11-11-08, 09:48 AM
Yeroon's Avatar
Yeroon Yeroon is offline
Code Master
 
Join Date: Aug 2007
Location: Netherlands, Nijmegen
Posts: 850
Thanks: 2
Thanked 20 Times in 20 Posts
PS. you cant ReDim the first dimension

Taken from MSDN:

Quote:
'ReDim' can only change the right-most dimension

A ReDim statement attempted to use the Preserve keyword to change a dimension of an array that is not the last dimension. When using Preserve, you can resize only the last dimension of an array. For all other dimensions, you must specify the same size as for the existing array.
Reversing wont help you, since this will only resort the data within the array. It wont change the array structure in any way.
__________________
Feel free to thank people if they help you by clicking thanks at a post.
=================================
Make it idiot proof and someone will make a better idiot.
=================================
Realise the impotence of proof reading everything you publish
Reply With Quote
Reply

Bookmarks


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
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating a browser RPG in javascript SolidSamurai JavaScript 26 10-20-08 03:27 PM
Quick question dealing with object arrays dmiranda Everything Java 2 01-09-05 04:15 AM


All times are GMT -5. The time now is 01:18 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.