|
Calator (Programmer) |
21 Jan 08 1:57 |
below is an example of code that loops in order to get all records beyong the first 20. Note that '20' is coded as a constant and could be changed in theory to anything else, but you may find that if changed, the retrival no longer works as expected, just because Mincom classes could only handle 20 (I am not certain, it could be put to the test, but to be safe just use 20). The other constants presents in the code can be safely varied as they have nothing to do with Mincom classes.
The key to the process is the test on "IsRestart", which tells if restart information is present, ie if there are more records available.
Hope that helps.
'global definitions 'max number of records to be returned by one call to object RETRIEVE method Const maxInstRet As Integer = 20 'max number of records to be returned in TOTAL (ie from iterating calls), 'before asking user if they wish to continue 'set to a low value during testing, eg 25, then to a higher value eg 500 Const maxRecords As Integer = 100
sub ... 'this example calls the EQUIPMENT.Retrieve service 'in order to obtain all Current Equipment for the Productive Unit in the first argument 'Equipment returned is filtered by Status in second argument
Dim Block As MIMSBlock Dim Reply As MIMSReply Dim Request As MIMSRequest Dim Inst As MIMSInstance Dim intNoOfRecords As Integer ' For training purposes, a max limit of total items ' is set as a constant, so that thousands are not retrieved; ' following variable keeps count of the number of items returned intNoOfRecords = 0 ' Create a new block (network message) to send to the server Set Block = oMimsx.Blocks.New("MainBlock") ' Create a request for information within the network message Block.Requests.New ("InstEquip") ' Specify the back end class and method Block.Requests("InstEquip").AddFieldNameValue "_Service", _ "EQUIPMENT.Retrieve" ' Specify number of records per reply Block.Requests("InstEquip").AddFieldNameValue "_MaxInst", _ Format$(maxInstRet)
' Specify the fields required Block.Requests("InstEquip").AddFieldNameValue "_ReplyList", _ "EquipNo,ParentEquip,EquipGrpId" '======================================================================= ' Create an instance of the request Block.Requests("InstEquip").Instances.New ("Instance") 'Specify the INPUT FILTERS: Block.Requests("InstEquip").Instances("Instance").AddFieldNameValue _ "ParentEquip", argParent Block.Requests("InstEquip").Instances("Instance").AddFieldNameValue _ "EquipStatus", argStatus
' loop to get every block Do 'Send the block to the server for processing Set Reply = Block.Send 'Process the reply If Not (Reply Is Nothing) Then 'If someting was returned 'Note: the number of records returned is available in: Reply.Requests(1).Instances.Count ' Loop through the requests and instances, representing a list of ' Install Position Equipment, and for each item in the list, ' do some processing not shown in this example: For Each Request In Reply.Requests For Each Inst In Request.Instances 'some non-relevant processing here intNoOfRecords = intNoOfRecords + 1 Next Next End If ' if no restart information then exit the loop If Not Reply.Requests(1).IsRestart Then Exit Do End If
' there are more records; test how many we already have got, 'and ask permission to continue, if we already have more than the maximum constant If intNoOfRecords >= maxRecords Then If MsgBox("More Equipment exists! Do you want to continue?", vbOKCancel) = vbCancel Then Exit Do Else 'reset counter and continue; this will allow to return another block of ' maxRecords, before asking again to continue intNoOfRecords = 0 End If End If
' add restart field, or set its value if already added If Block.Requests(1).IsRestart Then Block.Requests(1).Fields.Item("_Restart").Value = _ Reply.Requests(1).Fields.Item("_Restart").Value Else Block.Requests(1).AddFieldNameValue "_Restart", _ Reply.Requests(1).Fields.Item("_Restart").Value End If Loop ' go back for the next lot ' free the memory for the request list oMimsx.Blocks.Remove ("MainBlock") Exit Sub |
|