- 帖子
- 6
- 主題
- 1
- 精華
- 0
- 積分
- 36
- 點名
- 0
- 作業系統
- x64
- 軟體版本
- win7
- 閱讀權限
- 10
- 註冊時間
- 2012-7-11
- 最後登錄
- 2019-12-31
|
[發問] 不太懂為什麼module1跟thisworkbook的關係
從網路上找到的DDE紀錄程式,學習上,不懂為什麼module1跟thisworkbook?都要做相同的變數宣告也都有ExeSelf()的函數?
原本以為在module1上宣告應該就都可以使用才對。
但是實際測試上刪掉其中一個變數宣告或是ExeSelf(),程式就跑不動了發生巨集錯誤。
會想要刪掉其中一個是因為有時候跑一跑原本一分鐘記憶一次卻變成30秒記憶一次。
請指點一下,非常感謝。
Module1
Dim i, j As Single
Dim Min_Bar(1000, 6) As Variant 'Time, O,H,L.C,V
Dim O As Single
Dim H As Single
Dim L As Single
Dim C As Single
Dim V As Single
Dim NP As Single
Sub 關閉DDE自動交易系統()
On Error Resume Next
Application.OnTime Now + TimeValue("00:00:02"), "ThisWorkBook.ExeSelf", , False
End Sub
Sub 啟動DDE自動交易系統()
Dim k As Single
j = 2
Application.OnTime TimeValue("08:45:00"), "ExeSelf"
'Call ExeSelf
End Sub
Private Sub ExeSelf()
On Error Resume Next
i = i + 1
If i = 58 Then
Sheets(2).Cells(j, 1) = Time
Sheets(2).Cells(j, 2) = O
Sheets(2).Cells(j, 3) = H
Sheets(2).Cells(j, 4) = L
Sheets(2).Cells(j, 5) = C
Sheets(2).Cells(j, 6) = V
j = j + 1
i = 0: V = 0
O = Sheets(1).Cells(2, 2)
V = V + Sheets(1).Cells(2, 4)
H = O: L = O: C = O
Else
'以下判斷迴圈讓投資權重與投資標的物名稱設定,僅執行一次
C = Sheets(1).Cells(2, 2)
If C > H Then H = C
If C < L Then L = C
V = V + Sheets(1).Cells(2, 4)
' Sheets(2).Cells(i, 1) = Sheets(1).Cells(2, 2)
End If
Application.OnTime Now + TimeValue("00:00:01"), "ThisWorkBook.ExeSelf"
End Sub
ThisWorkbook
Dim i, j As Single
Dim Min_Bar(1000, 6) As Variant 'Time, O,H,L.C,V
Dim O As Single
Dim H As Single
Dim L As Single
Dim C As Single
Dim V As Single
Dim NP As Single
Private Sub Workbook_Open()
j = 2
'Call ExeSelf
End Sub
Private Sub ExeSelf()
On Error Resume Next
i = i + 1
If i = 60 Then
Sheets(2).Cells(j, 1) = Time
Sheets(2).Cells(j, 2) = O
Sheets(2).Cells(j, 3) = H
Sheets(2).Cells(j, 4) = L
Sheets(2).Cells(j, 5) = C
Sheets(2).Cells(j, 6) = V
j = j + 1
i = 0: V = 0
O = Sheets(1).Cells(2, 2)
V = V + Sheets(1).Cells(2, 4)
H = O: L = O: C = O
Else
'以下判斷迴圈讓投資權重與投資標的物名稱設定,僅執行一次
C = Sheets(1).Cells(2, 2)
If C > H Then H = C
If C < L Then L = C
V = V + Sheets(1).Cells(2, 4)
' Sheets(2).Cells(i, 1) = Sheets(1).Cells(2, 2)
End If
Application.OnTime Now + TimeValue("00:00:01"), "ThisWorkBook.ExeSelf"
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
On Error Resume Next
'Application.OnTime Now + TimeValue("00:00:10"), "ThisWorkBook.ExeSelf", , False
End Sub |
-
-
DDE下單系統.zip
(35.83 KB)
|