Private Sub Command1_Click()
Dim a, b, c, d As String
Dim i, t As Integer
a = Text1.Text
t = Len(a)
For i = 1 To t
b = b & Mid(a, t - i + 1, 1) 这里是什么意思?
Next i
For i = 1 To t
c = c & Mid(b, i, 1) 这里是什么意思?
If (i Mod 3 = 0 And i <> t) Then
c = c & ","
End If
Next i
t = Len(c)
For i = 1 To t
d = d & Mid(c, t - i + 1, 1) 这里是什么意思?
Next i
Print d
End Sub
为什么要提取三次字符?
这个程序,把简单的事情搞复杂化了。
解释如下:
Private Sub Command1_Click()
Dim a As String
Dim i, t As Integer
a = Text1.Text
t = Len(a)
For i = 1 To t
b = b & Mid(a, t - i + 1, 1) '把数字串倒过来,个位数在最前
Next i
For i = 1 To t
c = c & Mid(b, i, 1) '把倒过来的数字串,再连接一次
If (i Mod 3 = 0 And i <> t) Then '从个位开始,每三位(最高位除外)
c = c & "," '加一个逗号
End If
Next i
t = Len(c)
For i = 1 To t
d = d & Mid(c, t - i + 1, 1) '把加入了逗号的反序的数字串,再倒一遍
Next i
Print d
End Sub
只要这样就可以了:
Private Sub Command1_Click()
Dim a, b, c, d As String
Dim i, t As Integer
a = Text1.Text
t = (Len(a) - 1) \ 3
For i = t To 1 Step -1
a = Left(a, Len(a) - 3 * i) & "," & Right(a, 3 * i)
Next i
Print a
End Sub