LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Passing indexed array value to VBA function

Thanks Nick, that was it. I changed temp to a variant and all is well.

NickHK wrote:
It not the input arguments that are the problem, it the function's return
value.
Or rather it's the variables you are attempting to assign to the return
value.

Will you function return an array of integers or (an array in) a variant or
an array of variant ?
Dim temp() As Integer
Public Function RandomNumbers(<arguments) As Variant
Dim randomNums(), unsortedRandoms(), unsortedExtras()

NickHK

wrote in message
oups.com...
Hehe, I didnt think you would want to look at that mess.

The problem is just that I get a runtime error 13 type mismatch on the
RandomNumbers function call. It doesnt seem to like the firstNumber(q)
argument for the function. The function is defined to accept integers,
so I am thinking that its not recognizing this number in the array as
an integer.

Is the application.inputbox statement correct to put an integer in the
array? Can I not call the function with the array like it is?

Thanks again.

Alan Beban wrote:
Now that I asked for it I don't know that I want it. Is the problem
simply that the function you posted doesn't perform any function? In
the form in which you posted it it doesn't.

Alan Beban

wrote:
Thanks for the reply. Here is the whole subroutine.

Sub randomgen()
'Declare temporary arrays
Dim randomNums(), unsortedRandoms(), unsortedExtras()
Dim randomWeights() As Integer
Dim extraWeights() As Integer
Dim temp() As Integer
Dim lastNumber() As Integer
Dim firstNumber() As Integer
'randoms will hold the sorted random sample numbers
'extras will hold the sorted substitutes
Dim extras(), randoms()
'declare counters
Dim a, b, i, j, k, m, p, q, currentRandom, totalRange, counterR,
counterE As Integer

----------- SNIP ------------------------

counterR = 0
counterE = 0
For q = 0 To Cells(4, 2) - 1
'get random numbers for current range
Cells(5, 2) = extraWeights(q)
temp = RandomNumbers(lastNumber(q), firstNumber(q),
(randomWeights(q) + extraWeights(q)))
'put randoms in unsorted randoms

---------- SNIP ------------------------

'Only one range
Else
'Call random number function and put result in randomNums
randomNums = RandomNumbers(Worksheets("temp data").Cells(1,

2),
Worksheets("temp data").Cells(1, 1), (Cells(2, 2) + Cells(3, 2)) * 5)

------------- SNIP -------------

Public Function RandomNumbers(Upper As Integer, _
Optional Lower As Integer = 1, _
Optional HowMany As Integer = 1, _
Optional Unique As Boolean = True) As Variant

end function


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I use and indexed value as the name of an array for vlooku JimR Excel Worksheet Functions 2 October 1st 07 08:20 AM
Passing array from Access to Excel function Dale[_15_] Excel Programming 5 September 29th 05 07:30 PM
Sum from an indexed array/table [email protected] Excel Discussion (Misc queries) 1 May 17th 05 07:41 PM
Passing array of strings from DLL function to VBA Jag Man Excel Programming 0 January 12th 04 10:09 PM
Passing array to a function GB[_3_] Excel Programming 3 October 21st 03 09:59 AM


All times are GMT +1. The time now is 06:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"