Documentation>Application Documentation>XMIM Documentation>XMIM Examples>XMIMShowWhen Example

XMIMShowWhen Example
 

XMIM “Show-When” queries can be created using the XMIMShowWhen class. This class also provides for file-based execution of any XMIM query.

Consider the simple query:

SHOW
  IBMCLOSE: Close of GII.IBM.NYSE
WHEN
  Date is after 10/01/2000
And

  2 day percent move of  GII.IBM.NYSE is more than 5
 

Sub showwhen()  

/*Create variables for your VBXMIM objects. */

   Dim svr As XmimServer

   Dim showwhen As XmimShowWhen

   Dim timeUnits As XmimUtils

 

   Dim ClosePrice As Double

   Dim d As Date

   Dim t As String

   Dim n, i As Integer

 

/*Use the New property to create instances of each of your VBXMIM objects*/

    Set svr = New XmimServer

   Set showwhen = New XmimShowWhen

   Set timeUnits = New XmimUtils

 

 /*Connect to the XMIM server*/

   svr.host = "cbot.lim.com"

   svr.ServerNum = 1

   svr.Connect

 

  /*Before using any properties or methods, invoke the Init method*/

   showwhen.Init svr

  

 

 /* To construct a query, first set the number of attributes, using the NAttrs property, and set the number of conditions using NConds.  In our example, we have 1 attribute and 2 conditions */

   showwhen.NAttrs = 1

   showwhen.NConds = 2

  

  

 /*Use the Attr and Cond properties to fill in the attributes and conditions. */

  showwhen.Attr(0) = "Close of GII.IBM.NYSE"

  showwhen.Cond(0) = "Date is after 1995"

  showwhen.Cond(1) = "2 day percent move of GII.IBM.NYSE is more than 10"

   

/*You can also select an execution granularity for the query via Units (type of Units, seconds, minutes, etc) and NUnits, intervals. Units must be member of the Units family of XMIMUtils constants, Seconds, Minutes, Hours, etc.  In this case, the results will be shown in 15 minute intervals. */

 

  showwhen.Units = timeUnits.Minutes

  showwhen.Nunits = 15

 

 /* To run the query, call the Execute method. This will send the query to XMIM, allocate space for the results and load the results into the XMIMShowWhen object. */

 showwhen.Execute

 

/* Use the Nrecords property to determine the number of records that resulted after executing the query*/

   n = showwhen.NRecords

   i = 0

 

 

/*Iterate through each returned record*/

   While n > 0

 

 /* Use the DateTime property to fetch a particular date and the Val property to access individual fields of a record*/    

     ClosePrice = showwhen.Val(0, i)

     d = showwhen.DateTime(i)

   

/*Send the date and the individual field, in this case the Close of GII.IBM.NYSE, to individual cells of an Excel worksheet*/

    Worksheets("Sheet1").Cells(i + 1, 1).Value = d

    Worksheets("Sheet1").Cells(i + 1, 2).Value = ClosePrice

     n = n - 1

     i = i + 1

   Wend

 

 /*Disconnect from the Server and dispose of your instances using Nothing*./

   svr.Disconnect

   Set showwhen = Nothing

   Set svr = Nothing

 

End Sub