close
美元日經與星日經價差
使用元大點金靈串接DDE報價,以下將用VB.NET說明
首先新增一個 Excel 檔案,並且將該檔案取名為DDE,將檔案開啟後,將儲存格設定接收行情參數
然後再用VB.NET串接,程式碼如下
Imports NDde
Imports NDde.Client
Imports System.Text
Public Class Form1
Private WithEvents dde As DdeClient
Dim i, j, k As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
dde = New DdeClient("Excel.exe", "DDE.xlsx", Me)
dde.Connect()
Dim temp1, temp2 As Byte()
Try
temp1 = dde.Request("R1C1", 1, 60000)
temp2 = dde.Request("R1C2", 1, 60000)
Catch ex As Exception
End Try
Try
dde.StartAdvise("R1C1", 1, True, 60000)
dde.StartAdvise("R1C2", 1, True, 60000)
Catch ex As Exception
End Try
End Sub
Public Sub DDE_Advise(ByVal sender As Object, ByVal e As NDde.Client.DdeAdviseEventArgs) Handles dde.Advise
If e.Item.ToString = "R1C1" Then
i = e.Text
i = CInt(i)
Label3.Text = i
End If
If e.Item.ToString = "R1C2" Then
j = e.Text
j = CInt(j)
Label4.Text = j
End If
k = i - j
If k > 50 Then
ListBox1.Items.Add("如果價差>50,現在價格" & k & "點")
End If
End Sub
End Class
以上純屬個人興趣研究
全站熱搜
留言列表