Fast view column reader


	Private searchKeys As String
	Private cache As Variant 
	Private vw As NotesView

	' initialisation
		If IsEmpty(cache) Then 
			Call fillCache
		End If
	' cache is now filled with data, as an Array
	
	%REM
		Function fillCache
		Description: Load all selectable values 
	%END REM
	Private Sub fillCache 
		If IsEmpty(searchValues) Then 
			Call fillCacheR(0, CInt(vw.Entrycount))
		Else
			Call fillCacheR(0, CInt(vw.Getallentriesbykey(searchValues, True).Count))
		End If 
	End Sub 
	
	%REM
		Sub fillCacheR
		Description: Load a subset of selectable values, takes care of >32K problems; DbColumn and DbLookup are a lot faster than NotesViewEntries 
	%END REM
	Private Sub fillCacheR(offset As Long, count As Long)
		Dim v As Variant
		Dim n As Long 
		Dim s As String 
		If count=0 Then
			Exit Sub 
		End If
		If count<=1000 Then 
			If searchKeys="" Then 
				s= |@Subset(@Subset(@DbColumn(""; | + dbinfo +|; "| + vwname + |"; | + searchCol + |); | + CStr(offset+count) + |); | + CStr(-count) + |)|
			Else
				s= |@Subset(@Subset(@DbLookup(""; | + dbinfo +|; "| + vwname + |"; "| + searchKeys + |"; | + searchCol + | ); | + CStr(offset+count) + |); | + CStr(-count) + |)|
			End If 
			' Print "fillCacheR" offset count s		
			v= Evaluate(s)
			If IsArray(v) Then
				If IsEmpty(cache) Then
					cache= v
				Else
					cache= ArrayAppend(cache, v)
				End If
				Exit Sub 
			End If 
		End If 
		n= count\2
		If n<64 Then ' arbitrary value
			Error 1001, "Caching problem on " + vwname
		End If
		Call fillCacheR(offset, n)
		Call fillcacheR(offset+n, count-n) 
	End Sub

	%REM
		Function setSearch
		Description: If the picklist data isn't in the first column, setSearch is used to search a sorted view and pick a column  
	%END REM
	Function setSearch(keys As Variant, column As Variant)
		searchValues= keys 
		If IsArray(keys) then
			searchKeys= Join(keys, |":"|)
		Else
			searchKeys= CStr(keys)
		End If
		If IsNumeric(column) Then 
			searchCol= CStr(column)
		Else
			searchCol=|"|+ column + |"|
		End If 
	End Function
	
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
No comments yetLogin first to comment...