This post has been edited by Atli: 08 October 2012 - 04:17 AM
Reason for edit:: The [code] tags are for code, not normal text.
purpose of redim
Page 1 of 12 Replies - 788 Views - Last Post: 17 October 2012 - 05:57 PM
#1
purpose of redim
Posted 08 October 2012 - 03:52 AM
im quite new to vb,i couldnt understand the concept of redim in vb can anybody explain.......
Replies To: purpose of redim
#2
Re: purpose of redim
Posted 08 October 2012 - 04:01 AM
Redim can be used for arrays. Here is an example:
Say I had an array of, patients, and I wanted to add another one to the list. You can simply use this:
Redim Preserve array(<bounds>)
Redim can also be used to clear an array. Just omit the preserve part and it will clear the array out.
It can only be used within a procedure, (sub or function) and not at class or module level. You can not change the dimensions of an array (ie if it is 2-dimensional it cannot be 3 dimensional or 1 dimensional again), it will just reuse those dimensions.
Further reading
Oops, I just gave you VB.Net information. Sorry about that. I'll keep it here though just in case it helps :|
Say I had an array of, patients, and I wanted to add another one to the list. You can simply use this:
Redim Preserve array(<bounds>)
Redim can also be used to clear an array. Just omit the preserve part and it will clear the array out.
It can only be used within a procedure, (sub or function) and not at class or module level. You can not change the dimensions of an array (ie if it is 2-dimensional it cannot be 3 dimensional or 1 dimensional again), it will just reuse those dimensions.
Further reading
Oops, I just gave you VB.Net information. Sorry about that. I'll keep it here though just in case it helps :|
This post has been edited by DimitriV: 08 October 2012 - 04:07 AM
#3
Re: purpose of redim
Posted 17 October 2012 - 05:57 PM
This info also applies to VB6 for the most part. However, in VB6 you can change the number of dimensions as well as the bound.
Also, you can only use ReDim if you haven't specified the array size when you declare it (a "dynamic array"). Like this:
Also, you can only use ReDim if you haven't specified the array size when you declare it (a "dynamic array"). Like this:
dim x(9) as integer 'static array dim y() as integer 'dynamic array ReDim x(12) 'This will cause an error ReDim y(12) 'Works fine ReDim Preserve y(Ubound(y)+1) 'Used very often; adds one to the existing array while keeping existing valuesNote as Dimitri has said that ReDim always clears the existing array of all its values, unless you use the Preserve option.
This post has been edited by BobRodes: 17 October 2012 - 05:58 PM
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote



|