vb 相同刪除

2023-05-21 09:05:17 字數 3223 閱讀 4897

1樓:難得糊塗

private sub command1_click()t = 北京天氣" &vbcrlf &

計算器" &vbcrlf &

北京天氣" &vbcrlf &

dictionary" &vbcrlf &"南方航空" &vbcrlf &

rehearsal" &vbcrlf &"白羊座" &vbcrlf &

北京天氣" &vbcrlf &

杭州" &vbcrlf &

南京天氣" &vbcrlf &

計算器" &vbcrlf &

廣州天氣" &vbcrlf &

dictionary" &vbcrlf &"合肥天氣" &vbcrlf &

dictionary"

nextprint t2

end sub

請參考,謝謝!

2樓:匿名使用者

這個可以採用迴圈替換的方式刪除有相同項的內容。**如下:

private sub command1_click()dim str as string

dim var as variant

dim i as integer, j as integerstr =

end if

nextnext

= strend sub

該**測試通過。但是要求文字格式與樓主的一致。

vb如何除去陣列中相同的數

3樓:匿名使用者

具體思路:

實現2次迴圈,一個陣列迴圈2次,外迴圈陣列,得出一個值a,然後內迴圈,將a與自身所在的陣列的值對比一次,計算出現次數或者設定為空,如果計算出現次數可以計算次數大於2時候,進行刪除操作。如果設定為空,等於進行刪除操作。

具體**如下:

option explicit

function delete3(arr as variant) as variant

dim i as integer

for i = lbound(arr) to ubound(arr)

if i > ubound(arr) then exit for //累計器大於陣列長度,退出迴圈。

if arr(i) =3 then

dodim j as integer

for j = i to ubound(arr) -1 //陣列從新賦值。

arr(j) =arr(j + 1)

next j

if lbound(arr) =ubound(arr) then

delete3 = empty //刪除相同元素。

exit function

end if

redim preserve arr(lbound(arr) to ubound(arr) -1)

從新定義陣列長度。

if i > ubound(arr) then exit for //累計器大於陣列長度,退出迴圈。

loop while arr(i) =3

end if

next i

delete3 = arr

end function

sub test()

delete3 (array(3, 3, 3, 3, 1, 3, 7, 3, 3, 3, 9, 3, 3))

end sub

測試結果:驗證方式通過計算刪除元素後的陣列長度確認實現功能,輸入了array(3, 3, 3, 3, 1, 3, 7, 3, 3, 3, 9, 3, 3),長度為13(從1開始算),刪除後長度為3,而且只有3個元素是不重複的。說明功能正常。

4樓:匿名使用者

sub 清除陣列重複數()

dim blnok as boolean

dim inttest(99) as integer '未清除重複前的陣列。

dim intnew() as integer '清除重複數後的陣列dim i as integer

dim k as integer

dim a as integer

for i = 0 to 99

inttest(i) =int(rnd * 100) +1 '為測試陣列賦值。

nextfor i = 0 to ubound(inttest)blnok = true

for k = 0 to ubound(inttest)if inttest(i) =inttest(k) and i <>k then

blnok = false '有重複數出現,標誌為假exit for

end if

nextif blnok = true then

標誌為真時 將數值加入新的陣列。

redim preserve intnew(a)intnew(a) =inttest(i) intnew(a)a = a + 1

end if

next

5樓:匿名使用者

dim i,j,k as integer

dim nlength as integerdim a() as integer

dim n as integer

n=100redim a(n-1) as integer'給陣列賦值0--99。

nlength=n-1

for i=0 to nlength-1

for j=i+1 to nlength

if a(j)=a(i) then

for k=j to nlength-1

a(k)=a(k+1)

next k

nlength=nlength-1

end if

next j

next i

for i=0 to nlength

print a(i)

next i

nlength為去除相同數後的陣列長度。

VB和timer控制元件功能相同的函式

標準答案如下 利用api函式實現定時器功能 模組中 option explicit public ltimerid as long private declare function settimer lib user32 byval hwnd as long,byval nidevent as lo...

用VB,,用VB,用VB將123456789這數字分成三位數,各個數字之間比例是

private sub command1 click dim tmpstr as string,tmpstr1 as string dim mpstr2 as string,tmpstr3 as string dim a as integer,b as integer,c as integer di...

VB高手用VB編寫下面勾股定理,vb編寫勾股定理滿足條件一

private sub command1 click for i 1 to 30 for j i 1 to 30 k int sqr j j i i 0.5 if i i k k j j and k i then print i k j end if next j,i end sub vb編寫勾股定...