哦哦,差不多就是这种意思~
这样从资料数 0 到全部加满,速度会从快到慢
我也来贴一下我的写法~(不过我的是 VB6 ...),这样就颠倒过来是从慢到快
不知哪种速度比较快呢?
譬如 25 RndSeedS 是 "/1/2/3/4/5......./25/"
第一个乱数位置(RndN) 譬如 4 就用 UserInstr 找到第 4 个 斜线的位置,结果取出来就是 "4"
第二个乱数位置譬如 5 但是取出来就是 6 了因为 RndSeedS 经过上一次取出已经变成 "/1/2/3/5/6/7..../25/" (4 不见了)
最后 RndSeedS 就剩下例如 "/19/" 乱数位置肯定是 1 就取到 19
这时 RndSeedS 就变成 "/" 取光光了~
底下需要 3 个元件:
TextBox 名称 TB1
ListBox 名称 LB1
CommandButton 名称 CMD_Proc
复制程式
Option Explicit
Dim RndSeedS As String
Private Sub CMD_Proc_Click()
Dim RndN As Long, Ct As Long, i As Long, k1 As Long, k2 As Long
Dim tempS As String
Dim LastTimer As Double
LastTimer = Timer
'------- Ini. Var. & Obj. -------
Ct = Val(TB1.Text)
If Ct <= 0 Then Exit Sub
LB1.Clear
'------- Ini. Randomized Seed --------
RndSeedS = "/"
For i = 1 To Ct
RndSeedS = RndSeedS & i & "/"
Next i
'------ Start Proc. > Select Rnd Num In RndSeedS Then Delete -------
Do
RndN = Fix((Ct) * Rnd + 1) 'Find Pos. of Slash
k1 = UserInstr(RndN) '/x/ < 1st slash
k2 = InStr(k1 + 1, RndSeedS, "/") '/x/ < 2nd slash
tempS = Mid(RndSeedS, k1 + 1, k2 - k1 - 1)
RndSeedS = Left(RndSeedS, k1) & Right(RndSeedS, Len(RndSeedS) - k2)
LB1.AddItem tempS
Ct = Ct - 1
Loop While Ct <> 0
'-------- Show The Time ------
LastTimer = Timer - LastTimer
'Label_C(1).Caption = "Time : " & Format(LastTimer, "0.0000") & " s"
End Sub
Public Function UserInstr(ByVal Ti As Long) As Long 'Find String (Instr) In RndSeedS Continuously
Dim m As Long
m = 0
Do
Ti = Ti - 1
m = InStr(m + 1, RndSeedS, "/")
If m = 0 Then UserInstr = Len(RndSeedS): Exit Function
If Ti = 0 Then UserInstr = m: Exit Function
Loop
End Function
我也来附上我的小程式,也来玩玩看吧,我做了一个 Scan 功能(好像有点无聊..):