Sub GetRSRealRows(RS1 As ResultSet) As Long
Dim lPosition As Long
Try
lPosition = RS1.Position
RS1.Position = -1
RS1.NextRow
Catch
Return -1 'so we can differentiate between closed (or uninitialized) RS and empty one
End Try
RS1.Position = lPosition 'we shouldn't alter the position!
Return RS1.RowCount
End Sub
Sub ClearResultSets
Dim i As Int
Dim iCount As Int
Dim iRSRows As Int
Dim iRSRowsTotal As Int
Dim strResult As String
Dim arrClose(arrResultSets.Length) As Boolean
For i = 0 To arrResultSets.Length - 1
If arrResultSets(i).IsInitialized Then
iRSRows = GetRSRealRows(arrResultSets(i))
If iRSRows > -1 Then
iCount = iCount + 1
iRSRowsTotal = iRSRowsTotal + iRSRows
arrClose(i) = True
If iCount = 1 Then
strResult = arrResultSetNames(i) & " - " & iRSRows
Else
strResult = strResult & CRLF & arrResultSetNames(i) & " - " & iRSRows
End If
End If
End If
Next
If iCount = 0 Then
Dim rs As ResumableSub = Dialog.Show(Activity, Array As Object("OK"), _
"Close ResultSets", "", "No open ResultSets", _
-1, False, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Null, False, arrS)
Wait For (rs) Complete (strResult As String)
Return
End If
'Chr(45) = -
strResult = strResult & CRLF & General.MakeString(45, 56) & CRLF & "Total - " & iRSRowsTotal
Dim rs As ResumableSub = Dialog.Show(Activity, Array As Object("OK", "Close All"), _
"Close ResultSets (" & iCount & ")", "", strResult, _
-1, False, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Null, False, arrS)
Wait For (rs) Complete (strResult As String)
If strResult = "Close All" Then
For i = 0 To arrResultSets.Length - 1
If arrClose(i) Then
arrResultSets(i).Close
End If
Next
End If
End Sub
Sub MakeString(btByte As Byte, lNum As Long) As String
Dim i As Long
Dim arrBytes(lNum) As Byte
For i = 0 To lNum - 1
arrBytes(i) = btByte
Next
Return BC.StringFromBytes(arrBytes, "ASCII")
End Sub