Возможно ли скрипт VBA перенести на платформу AutoIT? Приведенный пример работает с Excel'ем, хотелось бы выполнения его функций минуя окно Excel. А главное - посоветуйте пожалуйста что прочитать чтобы хоть немного разобраться в этом куске кода.
Код:
Sub order2(ByRef orderRange As Range, ByVal serverCell As String, _
ByVal extendedAttribColumn As Integer, ByVal fromOrdersPage As Boolean)
Dim server As String, req As String, reqType As String, id As String, _
setSecType As String, primaryexchange As String, setExchange As String, addr As String, _
extended1 As String, extended2 As String
server = util.getServerStr(serverCell)
If server = "" Then Exit Sub
Dim lmtOrderTypes, auxOrderTypes As Variant
lmtOrderTypes = Array("LMT", "STPLMT", "REL", "LIT", "LOC", "PEGMKT", "TRAILLIMIT", "SCALE", "PEGMID", "PEG MID", "PASSV REL")
auxOrderTypes = Array("STP", "STPLMT", "REL", "LIT", "MIT", "PEGMKT", "TRAIL", "TRAILLIMIT", "SCALE", "PEGMID", "PEG MID", "PASSV REL")
' order vars
Dim side As String, quantity As String, orderType As String, _
lmtPrice As String, auxPrice As String, placeType As String
Dim orderRow As Range
Dim orderSheet As Worksheet
Dim rowCtr As Integer, ctr As Integer
Dim doErrorPopup As Boolean
doErrorPopup = (orderRange.Cells.Count = 1)
For Each orderRow In orderRange
rowCtr = orderRow.row
Set orderSheet = orderRow.Worksheet
If orderSheetCheckFails(orderSheet) Then Exit Sub
If util.composeContractReq(orderSheet.Cells(rowCtr, 1), req, reqType, True, , , _
doErrorPopup, setSecType, setExchange) Then
' get order description
side = orderSheet.Cells(rowCtr, DescripColumn)
quantity = orderSheet.Cells(rowCtr, DescripColumn + 1)
orderType = UCase(orderSheet.Cells(rowCtr, DescripColumn + 2))
lmtPrice = orderSheet.Cells(rowCtr, DescripColumn + 3)
auxPrice = orderSheet.Cells(rowCtr, DescripColumn + 4)
' must have side, quantity, orderType
If (side = "" Or quantity = "" Or orderType = "") Then
If doErrorPopup Then
MsgBox ("You must specify the side, quantity, and order type.")
Exit Sub
End If
Else
req = req & side & util.UNDERSCORE & quantity & util.UNDERSCORE & orderType
If (reqType = util.FULL_CONTRACT_REQ) Then
placeType = PLACE_ORDER_BY_FULL_CONTRACT
Else
placeType = PLACE_ORDER_BY_LOCAL_SYMBOL
End If
id = orderSheet.Cells(rowCtr, DescripColumn + 6).value
If id = "" Then ' none exists yet -- is original placement as opposed to modify
id = makeId()
End If
' for relative order with no limit price, set it to 0; TWS will understand
If orderType = "REL" And lmtPrice = "" Then
lmtPrice = "0"
End If
' for SCALE order with no aux price set it to 0
If orderType = "SCALE" And auxPrice = "" Then
auxPrice = "0"
End If
' for PEG MID order with no limit price, set it to 0
If (orderType = "PEGMID" Or orderType = "PEG MID") And lmtPrice = "" Then
lmtPrice = "0"
End If
' for PEG MID order with no aux price, set it to 0
If (orderType = "PEGMID" Or orderType = "PEG MID") And auxPrice = "" Then
auxPrice = "0"
End If
' for PASSV REL order with no lmt price, set it to 0
If (orderType = "PASSV REL") And lmtPrice = "" Then
lmtPrice = "0"
End If
Dim doTheAuxPrice As Boolean, doTheLmtPrice As Boolean
doTheAuxPrice = False
doTheLmtPrice = False
If setSecType = util.BAG And setExchange = util.IBEFP Then
doTheLmtPrice = True
doTheAuxPrice = (lmtPrice = "")
Else
For ctr = LBound(lmtOrderTypes) To UBound(lmtOrderTypes)
If orderType = lmtOrderTypes(ctr) Then
doTheLmtPrice = True
Exit For
End If
Next ctr
For ctr = LBound(auxOrderTypes) To UBound(auxOrderTypes)
If orderType = auxOrderTypes(ctr) Then
doTheAuxPrice = True
Exit For
End If
Next ctr
End If
If doTheLmtPrice Then
req = req & util.UNDERSCORE & util.orEmpty(lmtPrice)
End If
If doTheAuxPrice Then
req = req & util.UNDERSCORE & util.orEmpty(auxPrice)
End If
' add the deprecated share allocation for FA accounts, extended order attributes, and primary exchange
primaryexchange = UCase(orderSheet.Cells(rowCtr, 9))
extended2 = getExtendedOattrib2(orderRow, extendedAttribColumn, True)
extended1 = getExtendedOattrib1(orderRow, extendedAttribColumn, Len(extended2) = 0 And primaryexchange = "")
If extended1 <> "" Then ' if it is empty then no extended attribs are necessary and primaryexchange is empty
req = req & util.UNDERSCORE & sharesAlloc & _
util.UNDERSCORE & extended1
If primaryexchange <> "" Or extended2 <> "" Then
req = req & util.UNDERSCORE & util.orEmpty(primaryexchange)
End If
If extended2 <> "" Then
req = req & util.UNDERSCORE & extended2
End If
End If
' create order
orderSheet.Cells(rowCtr, OrderLinkColumn).value = util.composeControlLink(server, topic, id, placeType, req)
orderSheet.Cells(rowCtr, OrderLinkColumn + 1).value = id
orderSheet.Cells(rowCtr, OrderLinkColumn + 2).value = util.composeLink(server, topic, id, "status")
orderSheet.Cells(rowCtr, OrderLinkColumn + 3).value = util.composeLink(server, topic, id, "filled")
orderSheet.Cells(rowCtr, OrderLinkColumn + 4).value = util.composeLink(server, topic, id, "remaining")
orderSheet.Cells(rowCtr, OrderLinkColumn + 5).value = util.composeLink(server, topic, id, "price")
orderSheet.Cells(rowCtr, OrderLinkColumn + 6).value = util.composeLink(server, topic, id, "lastFillPrice")
orderSheet.Cells(rowCtr, OrderLinkColumn + 7).value = util.composeLink(server, topic, id, "parentId")
End If ' must have side, quantity, orderType
End If ' util.composeContractReq() succeeded
Next orderRow
End Sub