Basic Agent : pb type mismatch and array

Hello,

I’m testing a very basic agent to sort element and I having always the same error type mismatch when calling the function to sort

here is my code :

Dim testTab() As String 

Redim Preserve testTab(3) As String

testTab(0) = "Marc"

testTab(1) = "Anthony"

testTab(3) = "Gilles"

SortArray2    testTab   <== type mismatch

thanks for your help

for information


where SortArry2 is the code from notes.net below :

Function SortArray2 (Array$())

’ this code taken from Notes.net, and slightly modified to sort by numeric value

Dim MaxElement%, MidPoint%, I%, J%, Done% 

MaxElement% = Ubound(Array$)



Select Case MaxElement%

Case 0

	Exit Function

Case 1 

	If Cint (Array$(0)) > Cint (Array$(1)) Then 

		Swap Array$(0), Array$(1) 

	End If

Case Else 

	MidPoint% = MaxElement% 

	While MidPoint% > 0

		MidPoint% = MidPoint% \ 2 

		Do

			Done% = True

			For J% = 0 To MaxElement% - MidPoint%

				I% = J% + MidPoint% 

				If Cint (Array$(J%)) > Cint (Array$(I%)) Then 

					Swap Array$(J%), Array$(I%) 

					Done% = False 

				End If 

			Next 

		Loop Until Done%

	Wend

End Select

End Function

Function Swap (A$, B$)

’ goes w/ SortArray which was taken from notes.net

Dim Temp$ 

Temp$ = A$

A$ = B$

B$ = Temp$

End Function

Subject: basic Agent : pb type mismatch and array

Nicholas, looks like the reason that this is failing is that the sort routine, as modified, is trying to sort as numeric. (Note the CInt around the array elements.) Remove all CInt references and retry it. If that doesn’t work, reply back here.

I originally posted this sort routine back in 2004. If you want the original, search the forum for MaxElement% and you can get the original unmodified code that was for a string array. If it is needed for sorting a numeric array, it should be properly modified to do that.

Subject: thanks, works fine

Thanks you very much Jerry

the problem was cint function to remove

Subject: basic Agent : pb type mismatch and array

Hi,

if you need to sort the array in Script, i would do this with the evaluate Statement and the @ function @sort.

dim sortedarray as variant

dim unsortedarray as variant

sortedarray = Evaluate(“@sort(unsortedarray;[DESCENDING])”)

the native @sort function , is much more efficient than any sort routine in Script

regards bernhard

Subject: RE: basic Agent : pb type mismatch and array

I tried your code like this :

Dim entryList() As String 

Redim Preserve entryList(3) As String

Dim sortedarray As Variant

Dim unsortedarray As Variant

entryList(0) = "Marc"

entryList(1) = "Anthony"

entryList(3) = "Gilles"

unsortedarray = entryList

Print "unsortedarray = " & Ubound (unsortedarray)

sortedarray = Evaluate("@sort(unsortedarray;[DESCENDING])") 

Print "sortedarray = " & Ubound (sortedarray)

For i = 0 To Ubound (sortedarray)

	Print "res = " & sortedarray(i)

Next 

I have in print unsortedarray = 3

but I have in print sortedarray = 0 !!!

do you know why ?

Subject: RE: basic Agent : pb type mismatch and array

Hi,

the reason is that evaluate cannot access your script’s variable unsortedarray.

sortedarray = Evaluate(|@sort(“Marc”:“Anthony”:Gilles";[DESCENDING])|)

would work.

if you are working with a notesdocument you could

let evaluate work with your notesdocument’s field contents:

doc.mylist = unsortedarray

sortedarray = Evaluate(“@sort(mylist;[DESCENDING])”,doc)

Regards, Natalie