主要為x(0)=ab,x(1)=ac,x(2)=ac,x(3)=ab,希望執行結果為y(0)=ab,y(1)=ac
(即我只要不同的就好),以下程式不知很那裡錯了,想了好久!
For i = 0 To UBound(x)
If i = 0 Then
ReDim Preserve rdstnew(rdcount)
rdstnew(rdcount) = x(i)
Else
If Array.IndexOf(rdstnew, x(i)) < 0 Then
rdcount = rdcount + 1
ReDim Preserve rdstnew(rdcount)
rdstnew(rdcount) = x(i)
End If
End If
Next
2006-02-02 17:42:50 · 1 個解答 · 發問者 cat 1 in 電腦與網際網路 ➔ 程式設計
謝謝您,問題已經解決了!我想撰寫程式重於邏輯及經驗,和語法較無關係,謝謝你的一直協助!因為在寫碩士論文所以會常常會發問,所以最近還要麻煩你哦!謝謝!
2006-02-03 03:59:50 · update #1
原來您是使用VB.NET....XD
我不會VB.NET,不過我想以下的CODE應該也可以用,若不適用的話看看鳳凰大這幾天有沒有上線,他NET很強低...Orz
Private Sub Command1_Click()
Dim X(3) As String, Y() As String, I As Integer, J As Integer, B As Boolean
X(0) = "ab": X(1) = "ac": X(2) = ac: X(3) = "ab"
ReDim Preserve Y(0)
Y(0) = X(0)
For I = 0 To UBound(X)
B = True
For J = 0 To UBound(Y)
If X(I) = Y(J) Then B = False: Exit For
Next
If B Then ReDim Preserve Y(UBound(Y) + 1): Y(UBound(Y)) = X(I)
Next
Print Join(Y, ",")
End Sub
2006-02-02 18:22:14 · answer #1 · answered by W.J.S. 7 · 0⤊ 0⤋