6 Replies - 46965 Views - Last Post: 23 July 2008 - 10:45 PM Rate Topic: -----

#1 SupaFreak  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-February 07

Fixed and Dynamic Arrays

Posted 03 February 2007 - 02:05 PM

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.
Is This A Good Question/Topic? 0
  • +

Replies To: Fixed and Dynamic Arrays

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

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?
Was This Post Helpful? 0
  • +
  • -

#3 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 180
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

Re: Fixed and Dynamic Arrays

Posted 03 February 2007 - 10:45 PM

As for VB6, you can create a fixed array like this:
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.
Was This Post Helpful? 1

#4 m2s87  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 21
  • View blog
  • Posts: 390
  • Joined: 28-November 06

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:

	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)))

:blink: Output would be "46/43/42/1" ! :D

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 :D

Hope it helped :D
Was This Post Helpful? 0
  • +
  • -

#5 SupaFreak  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 03-February 07

Re: Fixed and Dynamic Arrays

Posted 04 February 2007 - 10:05 AM

View PostAmadeus, 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?



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

Was This Post Helpful? 0
  • +
  • -

#6 m2s87  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 21
  • View blog
  • Posts: 390
  • Joined: 28-November 06

Re: Fixed and Dynamic Arrays

Posted 04 February 2007 - 10:29 AM

View PostSupaFreak, on 4 Feb, 2007 - 07:05 PM, said:

View PostAmadeus, 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?



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 :D

This post has been edited by m2s87: 04 February 2007 - 10:31 AM

Was This Post Helpful? 0
  • +
  • -

#7 gever  Icon User is offline

  • New D.I.C Head

Reputation: 5
  • View blog
  • Posts: 29
  • Joined: 19-June 08

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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1