O
Okiebug
I am having issues after upgrading the VB.NET to use .NET 2 as needed per a
Web Service.
I am having problems with the return variable from the VB.NET to the VBA code:
VBA invoked from Excel:
<code>
Public Sub MSNAddTemplateCampaigns(ByVal AccountID As Long, ByRef
MonthlyBudget As Long)
Dim API As New ADcenter.API
Dim result As Object
Dim Row As Integer
Dim aResults() As Long
Dim Campaigns() As ADcenter.AdCenterCampaign
Dim var As Variant
Dim sheet As Worksheet
Dim intI As Integer
Dim sCampaignName As String
On Error GoTo errhndle
Application.ScreenUpdating = False
Set sheet = Sheets(CampaignsSheetName)
'Build Campaigns object to send to API.AddCampaigns
MSNTemplateCreateCampaignsObject Campaigns, MonthlyBudget
'Define Variant var to be equal to the Campaigns() just created and pass
into AddCampaigns API
var = Campaigns
Set result = API.AddCampaigns(AccountID, var)
aResults = result
sheet.Cells(19, 1) = "Campaign ID"
Row = 21
For i = LBound(aResults) To UBound(aResults)
If aResults(i) <> "0" Then
'Store the newly created campaign ids
If sCampaignName <> var(aResults(i)).CampaignName Then
sCampaignName = var(aResults(i)).CampaignName
MsgBox "Finished Adding Campaign: " & sCampaignName, vbOKOnly,
"MSN AdCenter"
End If
Do While sheet.Cells(Row, 3) <> ""
If LCase(Trim(sheet.Cells(Row, 3))) = LCase(var(i).CampaignName)
Then
sheet.Cells(Row, 1) = aResults(i)
End If
Row = Row + 1
Loop
End If
Next i
MSNHandleAPIErrors result, "addcampaigns", var
Set API = Nothing
Exit Sub
Application.ScreenUpdating = True
errhndle: MsgBox Err.Description, vbOKOnly, Err.Number
Set API = Nothing
End Sub
</code>
Throws an error, 424 Object Required, after completing the Set result =
API.AddCampaigns(AccountID, var) when attempting the assignment aResults =
result...
<.NET code>
Public Function AddCampaigns(ByVal accountID As Integer, ByRef
Campaigns As Object) As Object Implements _main.AddCampaigns
Dim pAPI As CampaignManagement = New CampaignManagement
SetAuthCredentials(pAPI)
Dim i As Integer
Dim lCampaigns() As AdCenterCampaign
ReDim lCampaigns(UBound(Campaigns) - LBound(Campaigns))
Dim aResults() As Long
ReDim aResults(UBound(Campaigns) - LBound(Campaigns))
Dim result As EntityResultType = New EntityResultType
For i = LBound(Campaigns) To UBound(Campaigns)
lCampaigns(i - -LBound(Campaigns)) = Campaigns(i)
aResults(i) = 0
Next i
Try
result = pAPI.AddCampaigns(0, accountID, lCampaigns)
'Handle the Campaigns created successfully
'created.Id is the Campaign ID;
'created.Index is the corresponding index into Campaign
For Each created As EntitySuccessType In result.SuccessRow
aResults(created.Index) = created.Id
Next
AddCampaigns = aResults
Catch e As Exception
WriteToEventLog(accountID & ":" & lCampaigns(0).CampaignId &
lCampaigns(0).CampaignName & ":" & accountID & ":" & UBound(Campaigns) & ":"
& LBound(Campaigns) & ":i=" & i & ":" & e.Message & ":" & e.Source & ":" &
e.StackTrace)
End Try
'AddCampaigns = pAPI.AddCampaigns(0, accountID, lCampaigns)
pAPI = Nothing
End Function
</.NET code>
Guess I'm doing something wrong in the type of variables I'm using.
David
Web Service.
I am having problems with the return variable from the VB.NET to the VBA code:
VBA invoked from Excel:
<code>
Public Sub MSNAddTemplateCampaigns(ByVal AccountID As Long, ByRef
MonthlyBudget As Long)
Dim API As New ADcenter.API
Dim result As Object
Dim Row As Integer
Dim aResults() As Long
Dim Campaigns() As ADcenter.AdCenterCampaign
Dim var As Variant
Dim sheet As Worksheet
Dim intI As Integer
Dim sCampaignName As String
On Error GoTo errhndle
Application.ScreenUpdating = False
Set sheet = Sheets(CampaignsSheetName)
'Build Campaigns object to send to API.AddCampaigns
MSNTemplateCreateCampaignsObject Campaigns, MonthlyBudget
'Define Variant var to be equal to the Campaigns() just created and pass
into AddCampaigns API
var = Campaigns
Set result = API.AddCampaigns(AccountID, var)
aResults = result
sheet.Cells(19, 1) = "Campaign ID"
Row = 21
For i = LBound(aResults) To UBound(aResults)
If aResults(i) <> "0" Then
'Store the newly created campaign ids
If sCampaignName <> var(aResults(i)).CampaignName Then
sCampaignName = var(aResults(i)).CampaignName
MsgBox "Finished Adding Campaign: " & sCampaignName, vbOKOnly,
"MSN AdCenter"
End If
Do While sheet.Cells(Row, 3) <> ""
If LCase(Trim(sheet.Cells(Row, 3))) = LCase(var(i).CampaignName)
Then
sheet.Cells(Row, 1) = aResults(i)
End If
Row = Row + 1
Loop
End If
Next i
MSNHandleAPIErrors result, "addcampaigns", var
Set API = Nothing
Exit Sub
Application.ScreenUpdating = True
errhndle: MsgBox Err.Description, vbOKOnly, Err.Number
Set API = Nothing
End Sub
</code>
Throws an error, 424 Object Required, after completing the Set result =
API.AddCampaigns(AccountID, var) when attempting the assignment aResults =
result...
<.NET code>
Public Function AddCampaigns(ByVal accountID As Integer, ByRef
Campaigns As Object) As Object Implements _main.AddCampaigns
Dim pAPI As CampaignManagement = New CampaignManagement
SetAuthCredentials(pAPI)
Dim i As Integer
Dim lCampaigns() As AdCenterCampaign
ReDim lCampaigns(UBound(Campaigns) - LBound(Campaigns))
Dim aResults() As Long
ReDim aResults(UBound(Campaigns) - LBound(Campaigns))
Dim result As EntityResultType = New EntityResultType
For i = LBound(Campaigns) To UBound(Campaigns)
lCampaigns(i - -LBound(Campaigns)) = Campaigns(i)
aResults(i) = 0
Next i
Try
result = pAPI.AddCampaigns(0, accountID, lCampaigns)
'Handle the Campaigns created successfully
'created.Id is the Campaign ID;
'created.Index is the corresponding index into Campaign
For Each created As EntitySuccessType In result.SuccessRow
aResults(created.Index) = created.Id
Next
AddCampaigns = aResults
Catch e As Exception
WriteToEventLog(accountID & ":" & lCampaigns(0).CampaignId &
lCampaigns(0).CampaignName & ":" & accountID & ":" & UBound(Campaigns) & ":"
& LBound(Campaigns) & ":i=" & i & ":" & e.Message & ":" & e.Source & ":" &
e.StackTrace)
End Try
'AddCampaigns = pAPI.AddCampaigns(0, accountID, lCampaigns)
pAPI = Nothing
End Function
</.NET code>
Guess I'm doing something wrong in the type of variables I'm using.
David