473,406 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

array of objects changing unusually

hi,
i have an array of 30 adgroup objects, called arrAdGroup. i am using a loop
to traverse through the array to set the adgroup.id property to a value
(which is different every time).
the code sets the value of all the objects in the array to the value of the
last object.
the code is below:

For i = 0 To counter - 1

With oKeyword
..adGroupId = adgroupID(i)
..criterionType =
criterion.com.google.adwords.CriterionType.Keyword
'.criterionTypeSpecified = True
If BidChange(i) Then
..maxCpc = Bid(i)
..maxCpcSpecified = True
End If
Select Case keywordType(i)
Case 1
..type = criterion.com.google.adwords.KeywordType.Broad
Case 2
..type = criterion.com.google.adwords.KeywordType.Exact
Case 3
..type =
criterion.com.google.adwords.KeywordType.Phrase
End Select
If DURLChange(i) Then
..destinationUrl = destinationURL(i)
End If
If paused(i) Then
..paused = True
..pausedSpecified = True
End If
..id = keywordID(i)

End With

' here is where the code is breaking.
If keywordID(i) 0 Then
arrKeyword(i) = oKeyword
End If
' every time this code executes, the previous object that was set in the
earlier 'loop is overwritten and a new instance of the object appears in the
(i) instance of 'the array.
Next

please help.
Aug 24 '07 #1
1 1167
You only have one instance of oKeyword. Each time through the loop
you set various properties of oKeyword, and then at the end you set
arrKeyword(i) = oKeyword.

Each arrKeyword() entry has a reference to the same oKeyword object.
You need to allocate a new oKeyword object each time through the loop.

Also, since you do nothing useful in the For loop if keywordID(i) <= 0
it would be more efficient to put this right after the For:

If keywordID(i) <= 0 Then
Continue For
End If

On Fri, 24 Aug 2007 09:42:03 -0700, R C <RC@discussions.microsoft.com>
wrote:
>hi,
i have an array of 30 adgroup objects, called arrAdGroup. i am using a loop
to traverse through the array to set the adgroup.id property to a value
(which is different every time).
the code sets the value of all the objects in the array to the value of the
last object.
the code is below:

For i = 0 To counter - 1

With oKeyword
.adGroupId = adgroupID(i)
.criterionType =
criterion.com.google.adwords.CriterionType.Keywor d
'.criterionTypeSpecified = True
If BidChange(i) Then
.maxCpc = Bid(i)
.maxCpcSpecified = True
End If
Select Case keywordType(i)
Case 1
.type = criterion.com.google.adwords.KeywordType.Broad
Case 2
.type = criterion.com.google.adwords.KeywordType.Exact
Case 3
.type =
criterion.com.google.adwords.KeywordType.Phrase
End Select
If DURLChange(i) Then
.destinationUrl = destinationURL(i)
End If
If paused(i) Then
.paused = True
.pausedSpecified = True
End If
.id = keywordID(i)

End With

' here is where the code is breaking.
If keywordID(i) 0 Then
arrKeyword(i) = oKeyword
End If
' every time this code executes, the previous object that was set in the
earlier 'loop is overwritten and a new instance of the object appears in the
(i) instance of 'the array.
Next

please help.
Aug 24 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: jerrygarciuh | last post by:
Hello, In this sample script I create an array of objects. Print out their data with print_r().Update their data with a sub called v_set(). Print out data showing the chnages using print_r(). I...
3
by: John MacIntyre | last post by:
Hi, Can anybody give me a hint as to how to convert a javascript array into a vbscript array? BTW-it only needs to work in IE5 & 6 Thanks in advance, John MacIntyre VC++ / VB / ASP /...
8
by: Mike S. Nowostawsky | last post by:
I tried using the "toUpperCase()" property to change the value of an array entity to uppercase BUT it tells me that the property is invalid. It seems that an array is not considered an object when...
32
by: Joe Rattz | last post by:
Hmmm, I wrote the following code. I want an array of bools and I want to intialize them to false. bool bits = new bool; foreach(bool bit in bits) { bit = false; } The compiler complains...
1
by: Craig | last post by:
Hey Everyone - I'm trying to determine the fastest way of moving array information around and could use some help. Here's the setup: Class A stores a DateTime and an amount (a payment)....
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
5
by: Paulers | last post by:
Hello all, I have a string array with duplicate elements. I need to create a new string array containing only the unique elements. Is there an easy way to do this? I have tried looping through...
23
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.