Dim x As Variant, StrX As String, Lngnums(255) As Long, P As Boolean, y As Long
StrX = Text1.Text
For Each x In Lngnums
If x = StrX Then
P = True
Exit For
End If
Next x
If P = False Then
Lngnums(y) = Val(Text1.Text)
y = y + 1
End If
For i = LBound(arr) To UBound(arr)
If arr(i) >= Text1.Text Then
position = i
Exit For
End If
Next i
If arr(position) = Text1.Text Then
For i = position To unbound(arr) - 1
arr(i) = arr(i + 1)
Next i
Else
ReDim Preserve arr(UBound(arr) + 1)
For i = unbound(arr) To position + 1 Step -1
arr(i) = arr(i + 1)
Next i
arr(position) = Text1.Text
End If
致:rainstormmaster(rainstormmaster)
您说的方法看不懂啊,能说详细点吗?我建了个EXT文件,但电脑提示变量未定义。这是我用的FRM文件,请帮忙看一下哪里出问题了!谢谢!
VERSION 5.00
Begin VB.Form Form1
Caption = "Form1"
ClientHeight = 4875
ClientLeft = 4080
ClientTop = 5400
ClientWidth = 6375
LinkTopic = "Form1"
ScaleHeight = 4875
ScaleWidth = 6375
Begin VB.CommandButton Command1
Caption = "Command1"
Height = 975
Left = 4440
TabIndex = 3
Top = 1320
Width = 1695
End
Begin VB.ListBox List1
Height = 3660
Left = 120
TabIndex = 2
Top = 960
Width = 3015
End
Begin VB.TextBox Text2
Height = 615
Left = 120
TabIndex = 1
Text = "Text2"
Top = 120
Width = 6135
End
Begin VB.TextBox Text1
Height = 1095
Left = 4440
TabIndex = 0
Text = "Text1"
Top = 3480
Width = 1695
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Function Exists(Key) As Boolean
Scripting.Dictionary 的成员
Determine if a given key is in the dictionary
Option Explicit
Dim arr() As Long
Dim dic As New Dictionary
Dim i As Long
Private Sub Command1_Click()
Dim j As Long
j = CLng(Text1.Text)
If dic.Exists(j) = False Then
dic.Add j, CStr(j)
ReDim Preserve arr(i + 1)
arr(i + 1) = j
Debug.Print arr(i + 1)
End If
End Sub
Private Sub Form_Load()
'初始化数组和词典
For i = 0 To 200
ReDim Preserve arr(i)
arr(i) = i
dic.Add i, CStr(i)
Next
Option Explicit
Dim arr() As Long
Dim dic As New Dictionary
Dim i As Long
Private Sub Command1_Click()
Dim j As Long
j = CLng(Text1.Text)
If dic.Exists(j) = False Then
dic.Add j, CStr(j)
ReDim Preserve arr(i + 1)
arr(i + 1) = j
Debug.Print arr(i + 1)
End If
End Sub
Private Sub Form_Load()
'初始化数组和词典
For i = 0 To 200
ReDim Preserve arr(i)
arr(i) = i
dic.Add i, CStr(i)
Next
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set dic = Nothing
End Sub