View Full Version : Dim - Compile Error: Syntax Error
jrussell25
10-15-2016, 04:27 AM
Hi,
I'm relatively new to VBA and i'm getting a compile error on the following code and have no idea why :(
Dim shopClient As API.PublicAPISoapClient = New API.PublicAPISoapClient("PublicAPISoap", "endpointhere")
Any help would be great :)
Thanks very much
Jamie
Kenneth Hobs
10-15-2016, 05:33 AM
Welcome to the forum!
Since you are using early binding, I would assume that you have downloaded and installed the API object and set the reference in the Visual Basic Editor (VBE) Tools > References?
Without that object, I have no way to check syntax.
In VBA, if New is even needed, we do it like this.
Sub Main() 'Add Tools > References > Microsoft Scripting Runtime
Dim fso As FileSystemObject
Set fso = New FileSystemObject
MsgBox Environ("temp") & "\" & fso.GetTempName, vbInformation, "Temp Filename"
End Sub
Paul_Hossler
10-15-2016, 07:24 AM
Doing this freehand and guessing (a lot), but usually in VBA it'd be something like
Dim shopClient As API.PublicAPISoapClient
Set shopClient = New API.PublicAPISoapClient
Call shopClient ("PublicAPISoap", "endpointhere")
'Dim' allocates a variable definition for a API.PublicAPISoapClient
'Set' instantiates a API.PublicAPISoapClient variable named shopClient
'Call' executes a method in the shopClient instance of a API.PublicAPISoapClient
jrussell25
10-15-2016, 08:41 AM
Sorry - realise i was beyond vague when i sent the message first. Basically i am trying to use an endpoint and an API key to download a list of orders from my online shop. I am currently at is this...
Private Sub CommandButton1_Click()
Dim shopClient As API.PublicAPISoapClient
Set shopClient = New API.PublicAPISoapClient
Call shopClient("PublicAPISoap", "endpointhere")
Dim getOrdersRequest As API.getOrdersRequest
Set getOrdersRequest = New API.getOrdersRequest
' Your unique APIKey must be passed with each request
getOrdersRequest.APIKey = "apikeyhere"
Dim getOrdersResponse As var = shopClient.GetOrders(getOrdersRequest)
' Check if the request failed
If (getOrdersResponse.Status = API.StatusCodes.Failure) Then
' Output the errors explaining why the request failed
For Each Error In getOrdersResponse.Errors
Console.WriteLine (Error)
Next
Console.ReadKey
Return
End If
' Output the shop data (List of shops orders)
For Each Order In getOrdersResponse.Orders
Console.WriteLine (Order.OrderNumber)
Console.WriteLine (Order.OrderDate)
Console.WriteLine (Order.OrderStatus)
Next
Console.ReadKey
End Sub
Thanks in advance :)
Dim getOrdersResponse As var = shopClient.GetOrders(getOrdersRequest)
Should be:
Dim getOrdersResponse As Variant
getOrdersResponse = shopClient.GetOrders(getOrdersRequest)It looks like shopClient.GetOrders returns an Array. If so, the rest of the code won't work as is.
Otherwise:
For Each Order In getOrdersResponse.Orders
Bad dog. No biscuit for you.
Is Order a keyword and getOrdersResponse not an Array?
Then:
Dim Ordr as Object
Or
Dim Ordr as API.PublicAPISoapClient.Order
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.