Subject: RE: Collection Handling - Need Help with Logic
OK, did I mention I’m a novice? I took a different approach and attempted to obtain all possible combinations to create 3 sets from the initial collection in the view, and create a separete “set” document for each good combination. The script runs, and sets are created and listed in a new view with descending lengths of “wasted footage” based on a field formula in the “set” form.
Next thing I have to do is figure out how to prevent creating a “set” record if an item was previously included in a “set” document. I figure for each value written to the “set” document, I can maintain a list array or variable in the script and check against the list as the loops are navigated. If the item is in the list, skip the “set” creation and resume loop.
Does anyone know how to do this? I guess appendarray would be one function, but how to you check a value against the array list?
Here’s what I have so far…I had to change weight to flow, but same logic. Don’t laugh…this stuff is not easy for me =)
Sub Initialize
Dim session As New notessession
Dim collection As NotesDocumentCollection
Dim db As notesdatabase
Dim doc As NotesDocument
Dim first_doc As NotesDocument, second_doc As NotesDocument, third_doc As NotesDocument
Dim countdoc As NotesDocument
Dim i As Long, x As Long, y As Long, num As Long, counter As Long
Dim countertext As String, partnum As String
Dim sernum_1 As String, sernum_2 As String, sernum_3 As String
Dim flow_1 As Double, flow_2 As Double, flow_3 As Double, flow_sum As Double
Dim length_1 As Integer, length_2 As Integer, length_3 As Integer
'set ID counter lookup - access counter document and get value
Set db = session.CurrentDatabase
Set view=db.getview("(counter)")
Set countdoc=view.getfirstdocument
num=countdoc.label_count(0)
counter = num
Set collection = db.UnprocessedDocuments
For i = 1 To collection.Count
For x = 2 To collection.Count
For y = 3 To collection.Count
countertext = Right$("0000" + Cstr(counter),5) 'pad counter with leading zeroes to 4 places
Set first_doc = collection.GetNthDocument(i) 'obtain a record in the view
partnum = first_doc.part_num(0)
sernum_1 = first_doc.ser_num(0)
flow_1 = first_doc.inv_water_flow(0)
length_1 = first_doc.length(0)
Set second_doc = collection.GetNthDocument(x) 'obtain another record
sernum_2 = second_doc.ser_num(0)
flow_2 = second_doc.inv_water_flow(0)
length_2 = second_doc.length(0)
Set third_doc = collection.GetNthDocument(y) 'obtain another record
sernum_3 = third_doc.ser_num(0)
flow_3 = third_doc.inv_water_flow(0)
length_3 = third_doc.length(0)
flow_sum = Format((flow_1+flow_2+flow_3),"0.00") 'add the three values
If flow_sum > 9.1 And flow_sum < 12.2 And _ 'verify sum of values is within range
sernum_1 <> sernum_2 And _ 'make sure items are distinct
sernum_1 <> sernum_3 And _
sernum_2 <> sernum_3 Then
Set doc = New notesdocument(db) ' create a document for each acceptable set
doc.form="Set Data" ' set the form name
doc.part_num=first_doc.part_num(0) 'populate fields
doc.ser_num_1=sernum_1
doc.ser_num_2=sernum_2
doc.ser_num_3=sernum_3
doc.inv_water_flow_1=flow_1
doc.inv_water_flow_2=flow_2
doc.inv_water_flow_3=flow_3
doc.length_1=length_1
doc.length_2=length_2
doc.length_3=length_3
doc.set_id=countertext
Call doc.ComputeWithForm( False, False ) 'compute sum of flows and length wasted
Call doc.Save( False, False )
counter = counter+1 'increase unique id counter for sets
countdoc.label_count=counter
Call countdoc.save(True,False)
Else
'do nothing
End If
Next y
Next x
Next i
End Sub