Dim and ReDim 
Author Message
 Dim and ReDim

I dimension an array using Dim in the general declarations section of a form
so it can be used throughout the form.  Then I want to ReDim it in a Sub
within the form, but it won't let me.  Any ideas?

***************************************************
* Visit The Otis Page at http://www.*-*-*.com/ *
*Your source for useless information since 6-27-96*
***************************************************



Sat, 12 Dec 1998 03:00:00 GMT  
 Dim and ReDim

I find this post from an ambiguous sender:

Quote:
>  yOU CAN'T REDEFINE A ARRAY DECLARED WITH DIM.
> DECLARE WITH REDIM THEN YOU REDEFINE IT, EVEN YOU CAN
> PRESERVE CONTRNTS
> DIM A(20) AS INTEGER
> REDIM A(40) --- THIS WON'T WORK
> REDIM A(40) AS INTEGER
> REDIM A(100) --- THIS WILL WORK
> YOU CAN PRESERVE CONTENTS ALSO
> REDIM PRESERVE A(100) -- PREVIOUS ITEMS WILL BE PRESERVED
> Newsgroups: comp.lang.basic.visual.misc
> Path:
>newsbf01.news.aol.com!newstf01.news.aol.com!news-e2a.gnn.com!howland.rest

o> n.ans.net!newsjunkie.ans.net!newsfeeds.ans.net!gtp23.bechtel.com!news

Quote:

> Subject: Re: Dim and ReDim
> Content-Type: text/plain; charset=us-ascii



> Nntp-Posting-Host: 147.1.120.245
> Content-Transfer-Encoding: 7bit
> Organization: Bechtel

> Mime-Version: 1.0
> Date: Wed, 26 Jun 1996 00:00:36 GMT
> X-Mailer: Mozilla 1.22 (Windows; I; 16bit)
> Lines: 17

Please, don't shout.

Steve Comstock
Denver, Colorado
USA

telephone: 800-993-8716
or:        303-393-8716
fax:       303-393-8718



Sat, 12 Dec 1998 03:00:00 GMT  
 Dim and ReDim

Quote:

>I dimension an array using Dim in the general declarations section of a form
>so it can be used throughout the form.  Then I want to ReDim it in a Sub
>within the form, but it won't let me.  Any ideas?

Please let us see your DIM and your REDIM command.

Rainer

------------------------------------------------------



Sat, 12 Dec 1998 03:00:00 GMT  
 Dim and ReDim

yOU CAN'T REDEFINE A ARRAY DECLARED WITH DIM.

DECLARE WITH REDIM THEN YOU REDEFINE IT, EVEN YOU CAN PRESERVE CONTRNTS

DIM A(20) AS INTEGER
REDIM A(40) --- THIS WON'T WORK

REDIM A(40) AS INTEGER
REDIM A(100) --- THIS WILL WORK

YOU CAN PRESERVE CONTENTS ALSO

REDIM PRESERVE A(100) -- PREVIOUS ITEMS WILL BE PRESERVED



Sun, 13 Dec 1998 03:00:00 GMT  
 Dim and ReDim


Quote:
Comstock) writes:
> yOU CAN'T REDEFINE A ARRAY DECLARED WITH DIM.

>> DECLARE WITH REDIM THEN YOU REDEFINE IT, EVEN YOU CAN
>> PRESERVE CONTRNTS

>> DIM A(20) AS INTEGER
>> REDIM A(40) --- THIS WON'T WORK

>> REDIM A(40) AS INTEGER
>> REDIM A(100) --- THIS WILL WORK

>> YOU CAN PRESERVE CONTENTS ALSO

>> REDIM PRESERVE A(100) -- PREVIOUS ITEMS WILL BE PRESERVED

I don't know where you got this idea, but you are wrong, you can Redim a
Dim.

M.D.



Sun, 13 Dec 1998 03:00:00 GMT  
 Dim and ReDim

Quote:

>I dimension an array using Dim in the general declarations section of a form
>so it can be used throughout the form.  Then I want to ReDim it in a Sub
>within the form, but it won't let me.  Any ideas?

I had the same problem but with the help of the net i have here the
solution:

in a module i have made a userdefined type:

Type Test
        x as Integer
        y as String
End Type

in the general Declarations section i have initialized the array:
'just according to the help-files and examples

Dim TestArray() As Test

'and a variable i need later

Dim Counter

So now i have an array of zero and i can use ReDim to change the size.

In the Form_load event i set the Counter to zero:

Counter=0

In a procedure i have to change the size, i coded like this:

Sub Command1_click()
        Counter=Counter+1
        ReDim Preserve TestArray(Counter)
        TestArray(Counter).x=1
        TestArray(Counter.y="a"
end Sub

gr. walther

------------------- cut here ---------------
Walther Musch
Tilburg University Holland



Sun, 13 Dec 1998 03:00:00 GMT  
 Dim and ReDim

Quote:

> >I dimension an array using Dim in the general declarations section of a
form
> >so it can be used throughout the form.  Then I want to ReDim it in a Sub
> >within the form, but it won't let me.  Any ideas?

> Please let us see your DIM and your REDIM command.

> Rainer

> ------------------------------------------------------


I think you have declare your array with an statment of this form :

dim myarray(10) as integer

if you do so the array can not be resized. You must declare your array with an
statment of this type :

dim myarray() as integer

tchuss Rainer



Tue, 15 Dec 1998 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Dim and ReDim?

2. Dim and ReDim

3. dim and redim allocate memory?

4. Efficient use of strings (Dim, Redim, and all that)

5. ReDim a 2 dim. array

6. dim string to dim form

7. Newbie Question: Dim A() as String /Dim A as String()

8. Dim obj As New Class crt Dim Obj As Class = New Class

9. dynamically dim a variable ie dim "variable"&n

10. dim myObject as Object versus dim myObject as myProject.class1

11. dim myObject as Object versus dim myObject as myProject.class1

12. clarify understanding on redim statement with dynamic arrays

 

 
Powered by phpBB® Forum Software