hi all
i've written a class that sorts an string-array using the binary-tree-sort algorithm. when i use the class via webagent i get sometimes an overflow error or sometime errors like this:
--error class baumsort_string/sub toArray():Subscript out of range (9) in zeile 228
--error class baumsort_string/sub toArray():No RESUME (19) in zeile 228
--error class baumsort_string/sub toArray():No RESUME (19) in zeile 228
--error class baumsort_string/sub toArray():No RESUME (19) in zeile 228
--error class baumsort_string/sub toArray():No RESUME (19) in zeile 228
-error sub sort_string():No RESUME (19) in Zeile 12
error:No RESUME (19) in Zeile 60
if i use arrays from 1 to 900 entries i have no problems
but if i use arrays with more than 1000 entries i get often an overflow error (but not allways)
when debugging in notesclient i don't get the error.
im using server version 5.0.12 (same error with 5.0.11) and clien version 5.0.11
here's the class: (put it into the declarations part of the agent)
i got it into a seperate class, but for testing it should also work from your agent
**************************
**********
**********
**********
**********
**********
**********
**********
**********
********
Public Class baumsort_string
Public value As String
Public lChild As baumsort_string
Public rChild As baumsort_string
'create binary tree object
Sub new(par_value As String)
Me.value=par_value
Set Me.lChild=Nothing
Set Me.rChild=Nothing
End Sub
'add new value to binary tree
Sub addValue(par_value As String)
If par_value<=Me.value Then
If Me.lChild Is Nothing Then
Set Me.lChild=New baumsort_string(par_value)
Else
Call Me.lChild.addValue(par_val
ue)
End If
Else
If Me.rChild Is Nothing Then
Set Me.rChild=New baumsort_string(par_value)
Else
Call Me.rChild.addValue(par_val
ue)
End If
End If
End Sub
'return binary-tree to array
Sub toArray(par_array() As String)
On Error Goto err_
If Not Me.lChild Is Nothing Then Call Me.lChild.toArray(par_arra
y)
Redim Preserve par_array(Ubound(par_array
)+1)
par_array(Ubound(par_array
))=Me.valu
e
If Not Me.rChild Is Nothing Then Call Me.rChild.toArray(par_arra
y)
exit_:
Exit Sub
err_:
If Err=200 Then 'Array not initialized
Redim par_array(0)
Resume Next
Else
Print "<br>--error class baumsort_string/sub toArray():" & Error & " (#" & Err & ") in line " & Erl
End If
End Sub
End Class
**************************
**********
**********
**********
**********
**********
**********
**********
**********
********
and here's the function that sorts an array using the class above:
**************************
**********
**********
**********
**********
**********
**********
**********
**********
********
Sub sort_string(par_array() As String)
On Error Goto err_
Dim baum As baumsort_string
Dim i As Integer
Dim vers As Integer
Set baum=New baumsort_string(par_array(
0))
For i=1 To Ubound(par_array)
Call baum.addValue(par_array(i)
)
Next
Erase par_array()
Call baum.toArray(par_array)
exit_:
Exit Sub
err_:
Print "<br>-error sub sort_string():" & Error & " (#" & Err & ") in line " & Erl
End Sub
**************************
**********
**********
**********
**********
**********
**********
**********
**********
********
'here's the rest of the agent: (variable maxanz defines the number of array-entries)
**************************
**********
**********
**********
**********
**********
**********
**********
**********
********
Sub Initialize
On Error Goto err_
Dim maxanz As Integer
Dim offset As Integer
Dim maxwert As Integer
Dim i,j As Integer
Dim gesstartzeit As Single
Dim startzeit As Single
Dim temp As String
Dim temp1() As String
Dim temp2() As String
Dim baum As baumsort_string
offset=Asc("a")
maxwert=Asc("z")-offset
maxanz=1000
'Create Random-Strings
Print "<br><b>Create Random Strings:</b>"
gesstartzeit=Timer()
startzeit=Timer()
Redim temp1(maxanz)
For i=0 To Ubound(temp1)
temp1(i)=Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert)
temp1(i)=temp1(i) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & Chr$(offset + Rnd*maxwert) & "_" & Cstr(i)
Next
Print "<br>time elapsed:" & Format$((Timer()-startzeit
),"0.000")
& "s"
Print "<br>ubound of array:" & Ubound(temp1) & "<br>"
'Sort the Array
Print "<p><b>Sorting Array:</b>"
startzeit=Timer()
Call sort_string(temp1())
Print "<br>time elapsed:" & Format$((Timer()-startzeit
),"0.000")
& "s"
Print "<p><h1>total time elapsed:" & Format$((Timer()-gesstartz
eit),"0.00
0") & "s</h1>"
Exit Sub
err_:
Stop 'for debugging in notes client
Print "<br>Error sub initalize():" & Error & " (#" & Err & ") in line " & Erl
End Sub
**************************
**********
**********
**********
**********
**********
**********
**********
**********
********
Start Free Trial