API Support Forum
OEC API > API Support > VB6 anyone?
Author Topic: VB6 anyone?
(6 messages, Page 1 of 1)
Moderators: VPfau
TThomas65
Posts: 9
Joined: Jun 03, 2010


Posted: Aug 17, 2010 @ 03:23 PM             Msg. 1 of 6
Have successfully used the -Sample Com Book.xls- excel workbook and am now attempting to implement a portion of it in VB6--- mostly interested in quotes.

I Developed a simple form to connect and show a single contract with price.

Code from the Quotes SubscribeAll sub was put into a module. Minor code changes were made to address the interface with a VB form instead of an excel workbook.

Problem 1.
The connection works as does the pass-off of variable c, an OECClient, to the SubscribeAll subroutine. However the contract always ends up as nothing. I’ve tried it with various symbols that worked in the spreadsheet.

Problem 2.
I don’t understand the OECAPICOM objects that begin with an “I”. For instance .Icontract . IOECClient, .IPrice , other things beginning in I. They don’t appear in the object browser, yet the compiler has no complaints: What are these???

Thomas Ketcheson
VictorV
Posts: 746
Joined: May 08, 2007


Posted: Aug 17, 2010 @ 04:49 PM             Msg. 2 of 6
Hello,

Problem 2: objects beginning in I are "interfaces"

Problem 1: could you show the code that you mentioned above?

Victor Vins
Software Developer
TThomas65
Posts: 9
Joined: Jun 03, 2010


Posted: Aug 18, 2010 @ 11:43 AM             Msg. 3 of 6
Interfaces?
.. Interesting. I've not used these before but see the use of them now. Thanks for shedding light on the issue.

Code:
IN the VB project I have a form called 'frmLogin' with textboxes 'tbConnectStatus' and 'tbContract' and a connect and disconnect butten

Here's the code after 'login' has proved sucessful.

IN the OECClass
'Declarations
Public WithEvents c As oecApicom.OECClient
.
.
.
Private Sub c_OnLoginComplete()
frmLogin.tbConnectStatus.Text = "Connected"
frmLogin.tbContract.Text = "ZNU0" 'this can change..
Quotes.SubscribeAll c, True
End Sub


IN module Quotes:

' Declarations:
Private SubscribedContracts(100) As oecApicom.Contract
Private api As oecApicom.IOECClient
---
Public Sub SubscribeAll(oecApi As oecApicom.IOECClient, lookup As Boolean)
Set api = oecApi
Dim i As Integer

' For i = 1 To 100 '**TK Don't bother with loop
i = 1 '**TK
Dim Name As String
Name = frmLogin.tbContract.Text '**TK [Name = Range("A" & (i + 2)).value]
Dim Contract As oecApicom.IContract
Set Contract = api.Contracts.Item(Name)
If Contract Is Nothing Then
Set Contract = Glob.FindNearest(Name)
If Not (Contract Is Nothing) Then
frmLogin.tbContract.Text = Contract.Symbol '**TK [ Range("A" & (i + 2)).value = contract.Symbol ]
ElseIf Len(Name) > 1 Then
If lookup Then
LookupRequest Name
End If
End If
End If
If Not (Contract Is Nothing) Then
api.Subscribe Contract
Set SubscribedContracts(i) = Contract
Else
Set SubscribedContracts(i) = Nothing
End If
' Next '**TK Don't bother with loop
End Sub

' Note : LookupRequest is unchanged from Excel example
'updateContract has been changed in line 3 to
' "For I=a to 1 'instead of 100
'UpdatePrices has been changed as follows:

Private Sub UpdatePrices(Contract As oecApicom.Contract, row As Integer)
On Error GoTo Err
Dim Price As oecApicom.IPrice
Set Price = Contract.CurrentPrice
If Not (Price Is Nothing) Then

frmLogin.TbPrice = Price.LastPrice '**TK

End If
Exit Sub
Err:
End Sub

Thomas Ketcheson
VictorV
Posts: 746
Joined: May 08, 2007


Posted: Aug 18, 2010 @ 04:54 PM             Msg. 4 of 6
Initially, OECAPI has no loaded contracts, except contracts that are required for orders and positions. Excel sample sends lookup requests for unknown symbols and then, on response, tries to resubscribe quotes with updated list of contracts.

Victor Vins
Software Developer
TThomas65
Posts: 9
Joined: Jun 03, 2010


Posted: Aug 19, 2010 @ 02:14 PM             Msg. 5 of 6
Thanks Victor. Guess I was just examining things too soon. The entire code seems to work now.

Thanks for your help

Tom

Thomas Ketcheson