Hi, I'm wanted to find out the difference between a fixed array and a dynamic array.
Any examples creating them would be helpful.
Thanks.
Fixed and Dynamic Arrays
Page 1 of 16 Replies - 38282 Views - Last Post: 23 July 2008 - 10:45 PM
Replies To: Fixed and Dynamic Arrays
#2
Re: Fixed and Dynamic Arrays
Posted 03 February 2007 - 02:38 PM
A fixed array is one that will not change it's size/allocation, while a dynamic array can be reallocated to grow or shrink.
As for code examples, are you using VB6 or VB.NET?
As for code examples, are you using VB6 or VB.NET?
#3
Re: Fixed and Dynamic Arrays
Posted 03 February 2007 - 10:45 PM
As for VB6, you can create a fixed array like this:
This will declare an array of 10 Integers.
To declare a dynamic Array,
If you want to change its dimension to 10 elements, use
To increase it to 15, use the same statement again.
Unlike C/C++ where the first element of the array is accessed by using Index 0, VB allows you to use both 0 or 1.
Use the Option Base 0 or Option Base 1 to specify which number refers to the first element.
By default, Option Base 0 is selected.
Dim arrayname(10) as Integer
This will declare an array of 10 Integers.
To declare a dynamic Array,
Dim arrayname() as Integer
If you want to change its dimension to 10 elements, use
Redim arrayname(10)
To increase it to 15, use the same statement again.
Redim arrayname(15)
Unlike C/C++ where the first element of the array is accessed by using Index 0, VB allows you to use both 0 or 1.
Use the Option Base 0 or Option Base 1 to specify which number refers to the first element.
By default, Option Base 0 is selected.
#4
Re: Fixed and Dynamic Arrays
Posted 04 February 2007 - 09:56 AM
My little example in vb 6 -
how to tell the diffence between static and dynamic arrays:
Output would be "46/43/42/1" !
So i declared a static array, valuated few stacks and gave the array to the dynamic array. By doing that, note, that dynamic recived not only a value or values, but multidimentional lenght also (and it is not a pointer to original values). Then i changed the size of the dynamic array, not that given values, what where in the new bounderies, are still there.
Msgbox was made to show, that you did not make a mistake
Hope it helped
how to tell the diffence between static and dynamic arrays:
rem written by Margus Martsepp aka m2s87
Const NUGIS As Integer = 47 And -2
Dim valuex(2, 32 To 45 Or NUGIS) As Integer
Dim arrayname() As Integer
valuex(0, NUGIS) = IIf(CInt(Val("lol")) = 0, 101, 0)
valuex(0, NUGIS + 1) = IIf(valuex(0, NUGIS) = 101, 1.1, 0)
valuex(0, 34) = 43
arrayname = valuex
valuex(0, 34) = 42
Dim valuey As Integer: valuey = 34
ReDim Preserve arrayname(2, LBound(arrayname, 2) To valuey) _
As Integer
MsgBox (NUGIS & "/" & _
arrayname(LBound(arrayname, 1), UBound(arrayname, 2)) & _
"/" & valuex(LBound(arrayname, 1), UBound(arrayname, 2)) & _
"/" & valuex(LBound(valuex, 1), UBound(valuex, 2)))
So i declared a static array, valuated few stacks and gave the array to the dynamic array. By doing that, note, that dynamic recived not only a value or values, but multidimentional lenght also (and it is not a pointer to original values). Then i changed the size of the dynamic array, not that given values, what where in the new bounderies, are still there.
Msgbox was made to show, that you did not make a mistake
Hope it helped
#5
Re: Fixed and Dynamic Arrays
Posted 04 February 2007 - 10:05 AM
Amadeus, on 3 Feb, 2007 - 02:38 PM, said:
A fixed array is one that will not change it's size/allocation, while a dynamic array can be reallocated to grow or shrink.
As for code examples, are you using VB6 or VB.NET?
As for code examples, are you using VB6 or VB.NET?
Thanks, the code I'm using is VB.NET, shouldn't it be the same as the vb6 code that born2c0de posted?
This post has been edited by SupaFreak: 04 February 2007 - 10:08 AM
#6
Re: Fixed and Dynamic Arrays
Posted 04 February 2007 - 10:29 AM
SupaFreak, on 4 Feb, 2007 - 07:05 PM, said:
Amadeus, on 3 Feb, 2007 - 02:38 PM, said:
A fixed array is one that will not change it's size/allocation, while a dynamic array can be reallocated to grow or shrink.
As for code examples, are you using VB6 or VB.NET?
As for code examples, are you using VB6 or VB.NET?
Thanks, the code I'm using is VB.NET, shouldn't it be the same as the vb6 code that born2c0de posted?
Not exactly. Check out ms-help://MS.VSExpressCC.v80/MS.NETFramework.v20.en/dv_vbvers/html/40fc500b-28f8-4034-b25e-8a320ccd911e.htm page in your help, to see all the changes. (Note: if your using vb 8 and framework 2)
Hope it helped
This post has been edited by m2s87: 04 February 2007 - 10:31 AM
#7
Re: Fixed and Dynamic Arrays
Posted 23 July 2008 - 10:45 PM
fixed array u cant resize it.
Dynamic Arrays can resize the capability of the Array at runtime
for eg;
Initial declaration
Dim scores() As Integer
Resizing
ReDim scores(1)
for fixed array refer
http://vb.net-inform....net_arrays.htm
for dynamic array
http://vb.net-inform...namic_array.htm
Dynamic Arrays can resize the capability of the Array at runtime
for eg;
Initial declaration
Dim scores() As Integer
Resizing
ReDim scores(1)
for fixed array refer
http://vb.net-inform....net_arrays.htm
for dynamic array
http://vb.net-inform...namic_array.htm
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|