Solved

Create executable from vbs

Posted on 2011-02-28
10
579 Views
Last Modified: 2012-05-11
Hi Experts,
This is related to following question.
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_26853882.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
0
Comment
Question by:Dushan911
  • 5
  • 5
10 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 35003712
Hi, in the DoRequest function, change all instances of
DfsCmd.

to
datamgr.

or
obj.

and see what happens.

Regards,

Rob.
0
 
LVL 17

Author Comment

by:Dushan911
ID: 35003730
Hi RobSampson,
Thanks a lot again!

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

BR Dushan.
obj-error.JPG
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 35003755
Hmmmm, try
dataMgr.

again, but also, above this line:
Call Main

add this:
Dim dataMgr

and see what you get.

Regards,

Rob.
0
 
LVL 17

Author Comment

by:Dushan911
ID: 35003806
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
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 35003831
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.
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 17

Author Comment

by:Dushan911
ID: 35003965
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
0
 
LVL 17

Author Comment

by:Dushan911
ID: 35003990
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.
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 35004033
So if you use this, what output do you get, and what are you expecting?

Rob.
Call Main


Function DoRequest(obj, lTimeOutMilliseconds, bRequestNext)
    DoRequest = False
    
    Const SLEEP_VALUE = 200
    Const DFS_DATAPENDING = 1
    Const DFS_ERROR = 3
    Const DFS_DATAREADY = 2
    Const DFS_DATAINCOMPLETE = 4
    Const DFS_DATAMOREPENDING = 5
    
    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 <> DFS_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 DFS_ERROR
            MsgBox "An error occurred with the request: " & obj.Error
        Case DFS_DATAREADY
            DoRequest = True

        Case DFS_DATAINCOMPLETE
            MsgBox "The data was incomplete at the time of the request. Please try again later!"
        Case DFS_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

0
 
LVL 17

Author Closing Comment

by:Dushan911
ID: 35004074
Hi Rob,
Thanks a lot!
I'm really really appreciate you kind help!!!

BR Dushan.
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 35004086
No worries. Glad it worked.

Rob.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now