(Q) Casting arrays 
Author Message
 (Q) Casting arrays

I have recently written an application with events that pass arrays by  
reference to functions within modules.  These functions then redimension  
and populate the arrays.

Question:  I have had difficulty casting arrays to specific types.  For  
example, consider the following:

Form Level:
SUB Button1_Click(..)
        Static theArray$()
        DoWhatever theArray$
END SUB

Module Level:
SUB DoWhatever (anArray())
        ReDim Preserve anArray(2,2)
        anArray(1,1) = "Charlie"
        ....(etc)
END SUB

When I try to pass the STRING array to the DoWhatever subroutine, I get  
what amounts to a "wrong type" message.  I tried wrapping the theArray$  
array with CVar(), but that didn't work.

Any ideas?

TIA.   --- Dave



Tue, 26 Aug 1997 22:01:32 GMT  
 (Q) Casting arrays

Quote:

> I have recently written an application with events that pass arrays by  
> reference to functions within modules.  These functions then redimension  
> and populate the arrays.

> Question:  I have had difficulty casting arrays to specific types.  For  
> example, consider the following:

> Form Level:
> SUB Button1_Click(..)
>    Static theArray$()
>    DoWhatever theArray$
> END SUB

> Module Level:
> SUB DoWhatever (anArray())
>    ReDim Preserve anArray(2,2)
>    anArray(1,1) = "Charlie"
>    ....(etc)
> END SUB

> When I try to pass the STRING array to the DoWhatever subroutine, I get  
> what amounts to a "wrong type" message.  I tried wrapping the theArray$  
> array with CVar(), but that didn't work.

> Any ideas?

> TIA.   --- Dave

DoWhatEver should look like

Sub DoWhatever(AnArray() as String)
    ReDim Preserve AnArray(2,2) as String
    ....

Also note that only the last dimension can be changed with Preserve.
Specifically lets say you have 100 Addresses, each address consisting
of say Street,City,PostCode. Then you would set up the array as follows:

Redim Address(3,100) as String

where Address(1,N) = Street
      Address(2,N) = City
      Address(3,N) = Postcode

Now when you want to add a entry you do:

Redim Preserve Address(3,101) As String

--
[ Name : Daniel Grealy              ]



Sat, 30 Aug 1997 04:08:05 GMT  
 (Q) Casting arrays
Quote:

> > Question:  I have had difficulty casting arrays to specific types.  For  
> > example, consider the following:

> > Form Level:
> > SUB Button1_Click(..)
> >      Static theArray$()
> >      DoWhatever theArray$
> > END SUB

> > Module Level:
> > SUB DoWhatever (anArray())
> >      ReDim Preserve anArray(2,2)
> >      anArray(1,1) = "Charlie"
> >      ....(etc)
> > END SUB

> > When I try to pass the STRING array to the DoWhatever subroutine, I get  
> > what amounts to a "wrong type" message.  I tried wrapping the theArray$  
> > array with CVar(), but that didn't work.

Dave,

I think your problem is here

Quote:
> >      DoWhatever theArray$

It should be
      DoWhatever theArray$()

Regards,
Charly



Sun, 31 Aug 1997 23:37:21 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Casting string into the byte array!

2. Casting an array's type?

3. How to cast an array

4. Casting from a Byte Array to a User Defined type

5. A97 Wizard Qs

6. Newbie Qs: Optimizing Stylesheet with Fields

7. Qs on applying style

8. Qs on applying style (word2000)

9. connect to robohelp qs

10. VERBATUM EXAM Qs 91947

11. handling event from control qs

12. 2 fairly simple database Qs

 

 
Powered by phpBB® Forum Software