VB可使用& 运算符将字符串串接的方式来实现,将VB代码执行的结果输出到文本框显示。
& 运算符,用来强制两个表达式作字符串连接。
Option Explicit
Dim strSj As String
Dim i As Long, j As Long
Private Sub Command1_Click()
For i = 1 To 1000
If i Mod 3 = 2 Or i Mod 5 = 3 Or i Mod 7 = 2 Then
'Print i;
strSj = strSj & i & " "
If j = 10 Then
j = 0
'Print vbCrLf
strSj = strSj & vbCrLf
End If
j = j + 1
End If
Next i
Text1 = strSj
End Sub
Private Sub Command1_Click()
dim s as string
s=""
For i = 1 To 1000
If i Mod 3 = 2 Or i Mod 5 = 3 Or i Mod 7 = 2 Then
Print i;
s=s & i
If j = 10 Then
j = 0
Print vbCrLf
s=s & vbCrlf
End If
j = j + 1
End If
Next i
text1.text=s
'前面的print 也可以不写,最后来一下print s,效果是一样的
End Sub
这样改
Private Sub Command1_Click()
Text1.Text=""
For I = 1 To 1000
If I Mod 3 = 2 Or I Mod 5 = 3 Or I Mod 7 = 2 Then
J = J + 1
Text1.Text = Text1.Text & Str(I)
If J Mod 10 = 0 Then Text1.Text = Text1.Text & vbCrLf
End If
Next I
End Sub