Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unique values only problem

Status
Not open for further replies.

sahmiele

Technical User
Sep 9, 2003
67
US
I am trying to get the variable "MyList" to only have unique values. It works fine when I just load all of the values, but I can't prevent duplicates. The values are sorted alphabetically, so it shouldn't be that difficult, but I am at a loss. Any help would be greatly appreciated. Thanks!



var MyList =
ActiveDocument.Sections["Dashboard - Customer Reports2"].Controls["DropDown2"]
MyList.RemoveAll() ;
var RowCount = ActiveDocument.Sections["Results - Customer Selection"].RowCount
var MyCol = ActiveDocument.Sections["Results - Customer Selection"].Columns["Sales Territory"]
for (j = 1 ; j <= RowCount ; j = j+1)
{
var Temp = MyCol.GetCell(j)
MyList.Add(Temp)
}
 
You aren't checking if it exists before adding...

for (j = 1 ; j <= RowCount ; j = j+1)
{
var Temp = MyCol.GetCell(j)

var item_exist = false;

for(x = 0; x <= MyList.options.Length;x++){
if(mylist.options[x].value == Temp){
item_exist = true;
}
}

if(!item_exist){
MyList.Add(Temp)
}
}
[/code]

something like this perhaps?


"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top