View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
moi moi is offline
external usenet poster
 
Posts: 27
Default Custom Array Functions

Watch your code step by step...

Let's say a_number (the cell) = 5

- Dim aAd(1 To 12) As Integer
This should create an array with 12 elements, although I would choose for

Dim aAd As Variant
aAd = Array(12)

or

Dim aAd(12) As Variant

- Dim n As Integer
Loop counter, seems correct

Now here we go and fill the array...

For n = 1 To 12 Step 1
aAd(n) = n * a_number
Next n

- So far so good, the result is:
aAd(1) = 5
aAd(2) = 10
...
aAd(12) = 60


Finally you say
- DispArray = aAd

and there it goes wrong. You have an array with 12 elements, so now you
should specify the element to return
DispArray = aAd(a_number)

Because you can't return an Array with 12 values into one single cell,
DispArray = aAd will return 0.




"Syed Zeeshan Haider" schreef in
bericht ...
Hello Everybody,
I have Excel 2003 Pro on WinXP Pro.

I have been searching on internet but could not find any useful
information about creating custom array functions.
Can somebody tell me any links to the reference about creating custom
array functions?

Well, actually I saw a rather complex code on a site. This code returned
array but I couldn't spend next 2 to 3 hours in understanding what was it
supposed to calculate. No description was provided.
I tried to experiment with my own following code:

Public Function DispArray(a_number As Integer) As Variant
' yes, varaibles are not logical
Dim aAd(1 To 12) As Integer
Dim n As Integer
For n = 1 To 12 Step 1
aAd(n) = n * a_number
Next n
DispArray = aAd
End Function

It is supposed to display multiplication table's result of a given integer
(a_number). But it returns same result in all select cells.

Thank you,
--
Syed Zeeshan Haider


-----------------------------------------------------------------------------------------------------------------------------
Download a free game to play with Internet Explorer from
http://szh.20m.com/entertainment/olwg.html