数组和字符串比较分析
Const n = 20
Dim a(1 To n) As Integer
Dim lenA As Integer '数组a的实际长度
Dim s As String
Private Sub Form_Load()
Dim i As Integer
lenA = 10
Randomize
a(1) = Int(Rnd * 5) + 1
For i = 2 To lenA
a(i) = Int(Rnd * 5)
Next i
s = ""
For i = 1 To lenA
s = s + Str(a(i))
Next i
Text1.Text = s
End Sub
Private Sub Command5_Click()
Dim i As Integer, j As Integer, c As Integer
For i = 1 To lenA - 1
c = 0 '用来累计重复元素的数量
For j = i + 1 To lenA
If a(i) = a(j) Then
' 第1空
Else
' 第2空
End If
Next j
lenA = lenA - c
Next i
s = ""
For i = 1 To lenA
s = s + Str(a(i))
Next i
Text2.Text = s
End Sub
需要本文PPT和源代码的,可以加入“选考VB算法解析”知识星球参与讨论和下载文件,“选考VB算法解析”知识星球汇集了数量众多的同好,更多有趣的话题在这里讨论,更多有用的资料在这里分享。
我们专注选考VB算法,感兴趣就一起来!
相关优秀文章: