Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Templates and passing functions


Hi,

I'm not all that familiar with vba, and was wondering if there is
something similiar to:

1) C++ Templates
2) C/C++ Passing functions as parameters

I would like to have the equivalent of the qsort function from C/C++
(and I'd prefer not to have to specify Variant as the type, as I've
heard that is slower).

Thanks,
Scott


--
Maistrye
------------------------------------------------------------------------
Maistrye's Profile: http://www.excelforum.com/member.php...o&userid=36078
View this thread: http://www.excelforum.com/showthread...hreadid=573264

  #2   Report Post  
Posted to microsoft.public.excel.programming
Les Les is offline
external usenet poster
 
Posts: 240
Default Templates and passing functions

I recently had to write a qsort for an array of 100000 numbers.
Perhaps this will point you in the right direction:

Public Sub mySort()

Dim x As Long
Dim y As Long
Dim idx As Long
Dim Nums(0 To 99999) As Long

'load array
For y = 1 To 4
For x = 1 To 25000
idx = (((y - 1) * 25000) + x)
Nums(idx - 1) = CLng(Sheets("RECS2").Cells(x, y))
Next
Next

'sort array
Call quick(Nums(), 100000)

End Sub

Public Sub quick(myNums() As Long, count As Long)
Call qs(myNums(), 0, (count - 1))
End Sub

Public Sub qs(myNums() As Long, leftNum As Long, rightNum As Long)
Dim i As Long
Dim j As Long
Dim x As Long
Dim y As Long

i = leftNum
j = rightNum
x = myNums((leftNum + rightNum) / 2)

Do
Do While myNums(i) < x And i < rightNum
i = i + 1
Loop
Do While x < myNums(j) And j leftNum
j = j - 1
Loop
If i <= j Then
y = myNums(i)
myNums(i) = myNums(j)
myNums(j) = y
i = i + 1
j = j - 1
End If
Loop While i <= j

If leftNum < j Then
Call qs(myNums(), leftNum, j)
End If
If i < rightNum Then
Call qs(myNums(), i, rightNum)
End If

End Sub

--
Les Torchia-Wells


"Maistrye" wrote:


Hi,

I'm not all that familiar with vba, and was wondering if there is
something similiar to:

1) C++ Templates
2) C/C++ Passing functions as parameters

I would like to have the equivalent of the qsort function from C/C++
(and I'd prefer not to have to specify Variant as the type, as I've
heard that is slower).

Thanks,
Scott


--
Maistrye
------------------------------------------------------------------------
Maistrye's Profile: http://www.excelforum.com/member.php...o&userid=36078
View this thread: http://www.excelforum.com/showthread...hreadid=573264


Reply
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 add functions in excel templates (XLT) [email protected] Excel Worksheet Functions 0 September 18th 06 07:46 PM
Passing strings as arguments to xll functions. JacksonRJones Excel Programming 0 March 24th 06 03:37 PM
passing targets between functions ph8[_44_] Excel Programming 6 March 8th 06 03:16 PM
passing arrays between functions in VBA Tom Ogilvy Excel Programming 3 March 1st 04 05:54 PM
Passing parameters between functions Gaston[_7_] Excel Programming 4 February 9th 04 04:08 AM


All times are GMT +1. The time now is 02:19 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"