PDA

View Full Version : Delete array element



kunguito
12-11-2008, 08:44 AM
1. Is there any way in VBA to do type casting on a user defined class?

2. Is it possible to code a function that deletes an element of an array regardless of the array type? Some overloading loophole?

3. Most importantly when it's a user defined class?

CreganTur
12-11-2008, 08:59 AM
1. Is there any way in VBA to do type casting on a user defined class?


Are you referring to data type conversion? Example: getting a string value of a variabe that is dimensioned as an integer.

If so, then look at Type Conversion Functions in Access Help. Here's an example that gets a string value of an integer:
Dim i As Integer
i = 150

MsgBox CStr(i)


2. Is it possible to code a function that deletes an element of an array regardless of the array type? Some overloading loophole?

You can remove the value of an array's index by setting it to "" value. But if you mean getting rid of the index and its value, then you would need to figure out how to redim the array so that it contains all of the values you want- excluding the unwanted value.

I'm not sure if I've anwered your questions. If I haven't, then please provide more details.

kunguito
12-11-2008, 11:21 AM
Hi CreganTur,

I didn't mean casting types of VBA. But just forget about it for now.
I wanted to overload the array.
Maybe with pointers? I have never used them in VBA.


Private Sub RemoveFromArray(Arr() As whatever, Pos As Integer)
Dim i As Integer
For i=Pos To UBound(Arr)-1
Arr(i)=Arr(i+1)
Next
ReDim Preserve Arr(UBound(Arr)-1)
End Function

And "whatever" is whatever. String, Long, Integer, userdefined class...

Is there any way to get around it or do I have to code the same function for every type I want to use it with?

Thanks a lot dude!