java怎么去除數(shù)組中重復(fù)的數(shù) VBA中如何利用動態(tài)數(shù)組去除重復(fù)值?
VBA中如何利用動態(tài)數(shù)組去除重復(fù)值?方法1dim a(9) as integrdim b() as integerdim i as integer,j as integerredim preserve
VBA中如何利用動態(tài)數(shù)組去除重復(fù)值?
方法1
dim a(9) as integr
dim b() as integer
dim i as integer,j as integer
redim preserve b(0)
b(0)=a(0)
for i= 1 to ubound (a)
for j= 0 to ubound(b)
if a(i) = b(j) then goto net ,有相同的就跳出
next
redim preserve b(ubound(b) 1)
b(ubound(b))=a(i)
net: ,跳到這里,匹配下一個(gè)數(shù)據(jù)
next
a = b
方法2,有10個(gè)數(shù),先找出最大的數(shù),按照這個(gè)數(shù)定義一個(gè)數(shù)組,把對應(yīng)的值寫入對應(yīng)的元素中,最好先設(shè)置一個(gè)默認(rèn)值
dim a(9) as integer
dim i as integer,temp as integer
temp=a(0)
for i= 1 to ubound(a)
if a(i) > temp then
temp = a(i)
end if
next i
redim b(temp) as integer
for i= 0 to ubound(a)
b(a(i)) = a(i)
next