如何插入iFIX动态数据到Excel工作.docx
《如何插入iFIX动态数据到Excel工作.docx》由会员分享,可在线阅读,更多相关《如何插入iFIX动态数据到Excel工作.docx(9页珍藏版)》请在冰豆网上搜索。
如何插入iFIX动态数据到Excel工作
写IFIX实时数据到Excel
2007-02-2811:
22
Description
Inserting FIX Dynamics data into an Excel worksheet.
Resolution
The following procedure will enable you to insert FIX Dynamics data into an Excel worksheet:
// Declare necessary API routines:
Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As Long) As Long
Private Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long
Sub DetectExcel()
// Procedure dectects a running Excel and registers it.
Const WM_USER = 1024
Dim hwnd As Long
// If Excel is running this API call returns its handle.
hwnd = FindWindow("XLMAIN", 0)
If hwnd = 0 Then // 0 means Excel not running.
Exit Sub
Else
// Excel is running so use the SendMessage API
// function to enter it in the Running Object Table.
SendMessage hwnd, WM_USER + 18, 0, 0
End If
End Sub
Private Sub CommandButton2_Click()
Dim msexcel As Excel.Application
Set msexcel = CreateObject("Excel.Application")
With msexcel
.Visible = True
.Workbooks.Open "d:
fix32Test1.xls", , False
End With
End Sub
Private Sub CommandButton3_Click()
Dim MyXL As Object // Variable to hold reference to Microsoft Excel.
Dim ExcelWasNotRunning As Boolean // Flag for final release.
// Test to see if there is a copy of Microsoft Excel already running.
On Error Resume Next // Defer error trapping.
// Getobject function called without the first argument returns a
// reference to an instance of the application. If the application isn//t
// running, an error occurs. Note the comma used as the first argument
// placeholder.
Set MyXL = GetObject(, "Excel.Application")
If Err.Number <> 0 Then ExcelWasNotRunning = True
Err.Clear // Clear Err object in case error occurred.
// Check for Excel. If Excel is running,
// enter it into the Running Object table.
DetectExcel
//Set the object variable to reference the file you want to see.
Set MyXL = GetObject("d:
fix32 est1.XLS")
// Show Microsoft Excel through its Application property. Then
// show the actual window containing the file using the Windows
// collection of the MyXL object reference.
MyXL.Application.Visible = True
MyXL.Parent.Windows
(1).Visible = True
// Do manipulations of your file here.
With MyXL.Application
.ActiveWorkbook.ActiveSheet.Select
.Goto reference:
=.Range("D4")
.Selection = Fix32.Johnski2.AI1.F_CV
End With
// If this copy of Microsoft Excel was not already running when you
// started, close it using the Application property//s Quit method.
// Note that when you try to quit Microsoft Excel, the Microsoft Excel
// title bar blinks and Microsoft Excel displays a message asking if you
// want to save any loaded files.
If ExcelWasNotRunning = True Then
MyXL.Application.Quit
End If
Set MyXL = Nothing // Release reference to the application and spreadsheet.
End Sub
6:
iFIX_如何使用脚本实现驱动(7x)的启动和停止?
Description
The following solution explains how to Start and Stop a 7.x driver through VBA code. This example uses
the ABR driver. To implement this with another 7.x driver, change the ABR to the three letter acronym of
the other driver and switch the reference to that driver.
Resolution
This code will only work with 7.x drivers. If you want to implement this is code in a new picture you
need to set a reference to Intellution ABRDrv OPC Server 7.20 Library. To set a reference, use the following steps:
1) On the Tools menu in the VB Editor choose References.
2) Select the Intellution ABRDrv OPC Server 7.20 Library from the list.
Add two command buttons to your picture and name them cmdStart_Click and cmdStop_Click.
Then paste the following code into the picture:
Private Sub cmdStart_Click()
Dim ABRDriver As New ABRDrv.ABRServer
ABRDriver.Stop
Set ABRDriver = Nothing
End Sub
Private Sub cmdStop_Click()
Dim ABRDriver As New ABRDrv.ABRServer
ABRDriver.Start
Set ABRDriver = Nothing
End Sub
7:
iFIX_如何使用脚本实现驱动(6x)的启动和停止?
Description
This articles describes how to control (start or stop) the 6.x drivers through VBA, Command Script,
or DOS rather than in Mission Control.
Resolution
The attached application DCTRL61.EXE enables you to do this. Below are the usage instructions.
Usage:
DCTRL command driver acronym delay [sleep]
where command is:
START - start the driver
STOP - stop the driver from polling
STOP_EXIT - stop polling and exit
SLEEP - set new sleep time (period)
STATUS - displays current values
DELAY - Wait a Number of milliseconds before executing this command ( 1000 = 1 second).
The the dctrl61.exe must be located in the FIX32 or Dynamics directory. The command and driver
acronym must be in ALL CAPS.
Example from the DOS prompt:
dctrl60 START MBR
Example from a iFIX VBA:
Shell c:
\fix32\dctrl60 "START MBR"
Example from a FIX32 script:
Runtask c:
\fix32\dctrl60 "START MBR"
8:
iFIX_脚本进行调度的启动和关闭方法?
Description
This solution shows how to start and stop a time-based or event-based schedule running in the background.
Resolution
STOP / START a EVENT BASED SCHEDULE
To Start:
Private Sub CommandButton1_Click()
Dim Var1 As Object
Dim Var2 As Object
Set Var1 = GetObject(, "FixBackGroundServer.Application")
Set Var2 = Var1.System.FindObject("SchedTest1.FIXEvent1")
Var2.StartEvent
End Sub
To Stop:
Private Sub CommandButton1_Click()
Dim Var1 As Object
Dim Var2 As Object
Set Var1 = GetObject(, "FixBackGroundServer.Application")
Set Var2 = Var1.System.FindObject("SchedTest1.FIXEvent1")
Var2.StopEvent
End Sub
STOP / START a TIME BASED SCHEDULE
To Stop the TimerObject:
Private Sub CommandButton1_Click()
Dim Var1 As Object
Dim Var2 As Object
Set Var1 = GetObject (,"FixBackGroundServer.Application")
Set Var2 = Var1.System.FindObject("Sched1.Timer1")
Var2.TimerEnabled = False
End Sub
To Start the TimerObject:
Private Sub CommandButton2_Click()
Dim Var1 As Object
Dim Var2 As Object
Set Var1 = GetObject (,"FixBackGroundServer.Application")
Set Var2 = Var1.System.FindObject("sched.Timer1")
Var2.TimerEnabled = True
Var2.StartTimer
End Sub
9:
iFIX_excel报表实现的方法?
Private Sub CommandButton1_Click()
'注释:
1。
该程序需要安装ADO 2.0目标库并在本机注册
' 2。
Microsoft ActiveX Data Objects 2.1 Library 必须被引用 (Office 2000)
' 3。
Microsoft Excel 9.0 object libraries 必须被引用 (Office 2000)
' 4。
划===处可根据具体报表修改
Dim strQueryAvg As String
Dim c As Integer
Dim r As Integer
Dim Intyexcel As Excel.Application
Dim MyDate, MyMonth, MyDay, MyHour, MyMinute, MySecond
Dim StartTime, EndTime, Duration, DisplayDay, DisplayMonth As String
'++===================================================================
'报表中的 TAG
Dim Tag1, Tag2, Tag3, Tag4, Tag5, Tag6, Tag7, Tag8 As String
Dim Items As Integer
Tag1 = "TEST"
Tag2 = "TEST1"
Tag3 = " "
Tag4 = " "
Tag5 = " "
Tag6 = " "
Tag7 = " "
Tag8 = " "
'从历史库中取得域项, 2 - DATATIME, VALUE, TAG 共三项
Items = 2
'--====================================================================
MyDate = Now()
MyMonth = Month(MyDate)
MyDay = Day(MyDate)
MyHour = Hour(MyDate)
MyMinute = Minute(MyDate)
MySecond = Second(MyDate)
StartTime = "2000" & "-" & MyMonth & "-" & MyDay - 1 & " " & "00:
00:
00"
EndTime = "2000" & "-" & MyMonth & "-" & MyDay - 1 & " " & "23:
00:
00"
'++==========================================================================
'查询,根据报表修改
strQueryAvg = "Select DATETIME, VALUE, TAG FROM FIX " & _
"WHERE MODE = 'AVERAGE' and (TAG='" & Tag1 & "' or TAG='" & Tag2 & "'" & _
" or TAG='" & Tag3 & "' or TAG='" & Tag4 & "' or TAG='" & Tag5 & "'" & _
" or TAG='" & Tag6 & "' or TAG='" & Tag7 & "' or TAG='" & Tag8 & "')" & _
"and INTERVAL = '01:
00:
00' and " & _
"(DATETIME >= {ts '" & StartTime & "'} and " & _
"DATETIME <= {ts '" & EndTime & "'})"
'--===========================================================================
Dim cnADO As New ADODB.Connection
Dim rsADO As Recordset
Set cnADO = New ADODB.Connection
cnADO.ConnectionString = "DSN = FIX Dynamics Historical Data; UID = sa; PWD = ;"
cnADO.Open "FIX Dynamics Historical Data", "sa", ""
Set rsADO = New ADODB.Recordset
rsADO.Open strQueryAvg, cnADO, adOpenForwardOnly, adLockBatchOptimistic
'''如果执行上面的语句出错的话,则最大的可能性就是SQL语句有错误!
r = 1
Set Intyexcel = New Excel.Application
Intyexcel.Visible = False
'++============================================================================
'打开的报表文件名
Dim OutReportFile As String
Dim InReportFile As String
InReportFile = "C:
\Dynamics\App\HIST1"
Intyexcel.Workbooks.Open InReportFile & ".XLS"
Intyexcel.Sheets("Sheet2").Select
Intyexcel.Columns("A:
Z").Select
Intyexcel.Selection.ClearContents
Intyexcel.Range("A1").Select
While rsADO.EOF <> True
With Intyexcel.Worksheets
(2)
For c = 0 To Items
If rsADO(c) <> "" Then .Cells(r, c + 1).Value = rsADO(c)
Next c
r = r + 1
rsADO.MoveNext
End With
Wend
Intyexcel.Sheets("Sheet1").Select
' Intyexcel.ActiveSheet.PageSetup.Orientation = xlPortrait 'xlLandscape
' Intyexcel.ActiveSheet.PageSetup.PaperSize = xlPaperA4
Intyexcel.ActiveSheet.PrintOut
Intyexcel.DisplayAlerts = False
Intyexcel.ActiveWorkbook.Save
OutReportFile = InReportFile & "_00" & MyMonth & MyDay
Intyexcel.ActiveWorkbook.SaveAs OutReportFile
Intyexcel.Quit
Intyexcel.DisplayAlerts = True
Set Intyexcel = Nothing
Set cnADO = No