下面是一个小型测试项目,用于显示您的 apos 进度,我从您的代码中尽可能少地更改
你可以看到最后 apos 将用 '1' 填充,除了最后一个元素的字符串长度为 sInput 加 1
'1 form with
' 1 command button : name=Command1
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Sub Command1_Click()
Dim X As Integer
Dim sInput As String
Dim apos() As Integer
Dim lngTime As Long
sInput = "Hello"
ReDim apos(1 To Len(sInput)) As Integer
Do
apos(1) = apos(1) + 1
For X = 1 To Len(sInput) - 1
If apos(X) > Len(sInput) Then
apos(X) = 1
apos(X + 1) = apos(X + 1) + 1
ShowApos apos
lngTime = GetTickCount + 100
Do Until GetTickCount > lngTime
DoEvents
Loop
End If
Next X
If apos(Len(sInput)) > Len(sInput) Then Exit Do
Loop
End Sub
Private Sub ShowApos(apos() As Integer)
Dim intIndex As Integer
Dim strShow As String
For intIndex = LBound(apos) To UBound(apos)
strShow = strShow & CStr(apos(intIndex)) & " "
Next intIndex
Caption = strShow
End Sub
所以它所做的只是有一些计数器填充到 len(sInput)+1 并将数组的所有其他元素设置为 1
最后一行将确保您在达到最终值时退出循环