-
Compiled OK, but Macro is Broken.
Option Explicit stays in, variables declared and code compiled OK. Thanks.
Now here is my broken Function autoCreateTicker from Object ExampleUtil, it used to work but I think my new overflow problem is a division by zero error. I make a connection with the server and bring in symbol (stock name), secType (always STK as compared with OPTions or FUTures or FutureOPtions or INDexes or CASH), "SMART" (online application signal to autoselect the least expensive broker, and currencyCode (always USDollars) so I should pass validation.
I should build the server because my user name is still at cell B5 in Object Worksheets("Tickers").Range("B5"). I've commented out the error handler so I think the code fails at the If Not statement.
I thought I was successfully passing Function composeTickerRequest because reqType is always req, Tickersymbol (stock name IBM or whatever) comes from the server ok, secType is always STK, "SMART" is hard coded, and currencyCode is always USD.
May I have a hint how to debug?
[vba]
Option Explicit
Dim lastId As Long
Dim offset As Long
Dim desc As String
Dim order As String
Function autoCreateTicker(symbol, secType, currencyCode, row) As Boolean
Dim server As String
Dim topic As String
Dim id As String
Dim reqType As String
Dim desc As String
Dim logSuccess As Boolean
Dim counter As Integer
' default the user entered fields
Worksheets("Tickers").Range("A" & CStr(row)).value = symbol
Worksheets("Tickers").Range("B" & CStr(row)).value = secType
Worksheets("Tickers").Range("G" & CStr(row)).value = "SMART"
Worksheets("Tickers").Range("I" & CStr(row)).value = currencyCode
' validate
If symbol = "" Or secType = "" Or currencyCode = "" Then
autoCreateTicker = False
Exit Function
End If
' build server
server = Worksheets("Tickers").Range("B5").value
If server = "" Then
autoCreateTicker = False
Exit Function
End If
server = "=" & server
' On Error GoTo tik_ErrorHandler
' set topic
topic = "tik"
' create and set id
id = makeId()
' I think this code blows up on the next line. What to check?
If Not composeTickerRequest(reqType, desc, symbol, secType, "", "", "", "", "SMART", currencyCode) Then
autoCreateTicker = False
Exit Function
End If
Worksheets("Tickers").Range("K" & CStr(row)).value = server & "|" & topic & "!'" & id & "?" & reqType & "?" & desc & "'"
Worksheets("Tickers").Range("N" & CStr(row)).value = server & "|" & topic & "!" & id & "?bidSize"
Worksheets("Tickers").Range("O" & CStr(row)).value = server & "|" & topic & "!" & id & "?bid"
Worksheets("Tickers").Range("P" & CStr(row)).value = server & "|" & topic & "!" & id & "?ask"
Worksheets("Tickers").Range("Q" & CStr(row)).value = server & "|" & topic & "!" & id & "?askSize"
Worksheets("Tickers").Range("T" & CStr(row)).value = server & "|" & topic & "!" & id & "?last"
Worksheets("Tickers").Range("U" & CStr(row)).value = server & "|" & topic & "!" & id & "?lastSize"
Worksheets("Tickers").Range("X" & CStr(row)).value = server & "|" & topic & "!" & id & "?high"
Worksheets("Tickers").Range("Y" & CStr(row)).value = server & "|" & topic & "!" & id & "?low"
Worksheets("Tickers").Range("Z" & CStr(row)).value = server & "|" & topic & "!" & id & "?volume"
Worksheets("Tickers").Range("AA" & CStr(row)).value = server & "|" & topic & "!" & id & "?close"
logSuccess = logMessage("[autoCreateTicker]", "Ticker created for: " & symbol)
autoCreateTicker = True
Exit Function
tik_ErrorHandler:
autoCreateTicker = False
logSuccess = logMessage("[autoCreateTicker]", "An automated ticker request was attempted, but could not be created for: " & symbol & ". Error description: " & Err.Description)
End Function
Function composeTickerRequest(ByRef reqType As String, ByRef desc As String, ByVal symbol As String, _
ByVal secType As String, ByVal expiry As String, ByVal strike As String, ByVal right As String, _
ByVal multiplier As String, ByVal exchange As String, ByVal currencyCode As String) As Boolean
desc = util.cleanUnderscore(symbol) & "_" & secType & "_"
If ((secType = "OPT" Or secType = "FUT" Or secType = "FOP") And expiry = "") Then
reqType = "req2"
Else
reqType = "req"
If secType = "OPT" Or secType = "FUT" Or secType = "FOP" Then
desc = desc & expiry & "_"
End If
If secType = "OPT" Or secType = "FOP" Then
desc = desc & strike & "_" & right & "_"
If multiplier <> "" Then
desc = desc & multiplier & "_"
End If
End If
desc = desc & util.cleanUnderscore(exchange) & "_" & currencyCode
End If
composeTickerRequest = True
End Function
[/vba]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules