Link to home
Start Free TrialLog in
Avatar of Dushan Silva
Dushan SilvaFlag for Australia

asked on

Create executable from vbs

Hi Experts,
This is related to following question.
https://www.experts-exchange.com/questions/26853882/Create-executable-from-vbs.html

When I try to implement price object it give's error as in attached image file.

Seems following function is not implemented correctly on the DoRequest function.

DfsCmd.DataPending

I changed to Dfs as DfsCmd, but still same error occurs.

Please help me.

BR Dushan.
Call Main


Function DoRequest(obj, lTimeOutMilliseconds, bRequestNext)
    DoRequest = False
    
    Const SLEEP_VALUE = 200
    Dim bTimeoutCheck
    Dim lTimeCount
    Dim state
    Dim lErrorNumber
    Dim strErrorDescription

    ' Handle any automation exception errors generated when calling Request method
    On Error Resume Next

    If (bRequestNext) Then
        obj.RequestNext
    Else
        obj.Request
    End If

    lErrorNumber = Err.Number

    strErrorDescription = Err.Description

    On Error GoTo 0

    If lErrorNumber <> 0 Then
        MsgBox "An automation exception error occurred with the request: " & strErrorDescription
        Exit Function
    End If

    bTimeoutCheck = (lTimeOutMilliseconds > 0)
    lTimeCount = 0
    state = obj.state

    Do Until state <> DfsCmd.DataPending
        ' Check if timeout occurred
        If bTimeoutCheck And lTimeCount >= lTimeOutMilliseconds Then Exit Do

        DoEvents ' Allow system events to be processed while looping
        WScript.Sleep SLEEP_VALUE
        state = obj.state
        ' Increment time counter if checking for timeouts
        If bTimeoutCheck Then lTimeCount = lTimeCount + SLEEP_VALUE
    Loop

    Select Case state
        Case DfsCmd.Error
            MsgBox "An error occurred with the request: " & obj.Error
        Case DfsCmd.DataReady
            DoRequest = True

        Case DfsCmd.DataIncomplete
            MsgBox "The data was incomplete at the time of the request. Please try again later!"
        Case DfsCmd.DataMorePending
        '    DoRequest obj, lTimeOutMilliseconds, True
         MsgBox "Request Data More Pending!"
        Case Else
            ' Determine if timeout occurred
            If (lTimeOutMilliseconds > 0) And (lTimeCount >= lTimeOutMilliseconds) Then
                MsgBox "Request timeout occurred!"
            Else

                MsgBox "Unexpected Error in Request"
            End If
    End Select
End Function


Sub Main()
    Set dataMgr = CreateObject("Dfs.DataManager")
  '  Set price = DfsPrice.DataPrice
    Set price = dataMgr.CreateOb("Price")

   
    'Set the Request Parameters
    price.Security(0) = "ARC"
    price.Exchange(0) = "EWG"
    price.Security(1) = "HUJ"
    price.Exchange(1) = "KYM"
    price.Security(2) = "OTQ"
    price.Exchange(2) = "ZSA"

    
    'Make the request and wait until the data is returned
    iTimout = 20000
    bReqNext = False
    If Not DoRequest(price, iTimeOut, bReqNext) Then WScript.Quit
    
    'Process the data returned
    Dim i
    For i = 0 To price.RowCount - 1
        MsgBox price.Security(i) & price.LastPriceDouble(i) & price.AskFlag(i) & price.AskNumLong(i) & vbCrLf
        MsgBox price.AskPriceDouble(i) & price.AskVolumeDouble(i) & price.BidFlag(i) & price.BidNumLong(i) & BidPriceDouble(i) & vbCrLf

        MsgBox price.BidVolumeDouble(i) & price.CumValueDouble(i) & price.CumVolumeDouble(i) & price.HighPriceDouble(i) & price.LowPriceDouble(i) & vbCrLf
        MsgBox price.MktValueDouble(i) & price.MktVolumeDouble(i) & price.MovementDouble(i) & price.QuoteBasis(i) & price.StatusNotes(i) & vbCrLf
        MsgBox price.ReportCode(i) & price.TradeDate(i) & price.TradeTime(i) & price.UpdateTime(i) & vbCrLf

        MsgBox price.UnadjustedLastPrice(i) & price.Units(i) & price.NumberOfTrades & vbCrLf
    Next
End Sub

Open in new window

DfsCmd-not-found.JPG
Avatar of RobSampson
RobSampson
Flag of Australia image

Hi, in the DoRequest function, change all instances of
DfsCmd.

to
datamgr.

or
obj.

and see what happens.

Regards,

Rob.
Avatar of Dushan Silva

ASKER

Hi RobSampson,
Thanks a lot again!

datamgr. is giving same above error.
obj. is giving error in attached image.

BR Dushan.
obj-error.JPG
Hmmmm, try
dataMgr.

again, but also, above this line:
Call Main

add this:
Dim dataMgr

and see what you get.

Regards,

Rob.
I kept following line on the top of the code.
Dim dataMgr
And Changed datamgr to dataMgr.
It's giving the same error on the image which I've attached last.

BR Dushan
OK then.  Somewhere, these five values with be constant integers defined somehow:

DfsCmd.DataPending
DfsCmd.Error
DfsCmd.DataReady
DfsCmd.DataIncomplete
DfsCmd.DataMorePending

What you will need to do, is use code in Excel, add the right references, and then add:
MsgBox "DataPending: " & DfsCmd.DataPending & VbCrLf & _
   "Error: "  & DfsCmd.Error & VbCrLf & _
   "DataReady: " & DfsCmd.DataReady & VbCrLf & _
   "DataIncomplete: " & DfsCmd.DataIncomplete & VbCrLf & _
   "DataMorePending: " & DfsCmd.DataMorePending

Then, when you see that MsgBox, post that here, and I'll show you how to add constants for it.

Regards,

Rob.
Hi RobSampson,
You really really helpful!
It gives attached output of image "dfsCmd_int.JPG".
I tried attached code and it gives "DoEvent.JPG" error.

Do Until state <> 1
        ' Check if timeout occurred
        If bTimeoutCheck And lTimeCount >= lTimeOutMilliseconds Then Exit Do

        DoEvents ' Allow system events to be processed while looping
        WScript.Sleep SLEEP_VALUE
        state = obj.state
        ' Increment time counter if checking for timeouts
        If bTimeoutCheck Then lTimeCount = lTimeCount + SLEEP_VALUE
    Loop

    Select Case state
        Case 3
            MsgBox "An error occurred with the request: " & obj.Error
        Case 2
            DoRequest = True

        Case 4
            MsgBox "The data was incomplete at the time of the request. Please try again later!"
        Case 5
        '    DoRequest obj, lTimeOutMilliseconds, True
         MsgBox "Request Data More Pending!"
        Case Else
            ' Determine if timeout occurred
            If (lTimeOutMilliseconds > 0) And (lTimeCount >= lTimeOutMilliseconds) Then
                MsgBox "Request timeout occurred!"
            Else

                MsgBox "Unexpected Error in Request"
            End If
    End Select

Open in new window

dfsCmd-int.JPG
DoEvent.JPG
Hi RobSampson,

If I comment 'DoEvents line, then it will return the data, but only one message box is popping, not continuously coming.

BR Dushan.
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi Rob,
Thanks a lot!
I'm really really appreciate you kind help!!!

BR Dushan.
No worries. Glad it worked.

Rob.