2 回答
TA贡献2003条经验 获得超2个赞
再窗体上画出text1,text2,并设置可以多行(multiline=true),一个Command1按钮
用以下的算法,运行时弹出输入框, 输入n就可以了。
Private Sub Command1_Click()
Dim a() As String
Dim str As String '用于输出的 字符串
Dim n, i, j, k As Integer 'i与j用于输出n倍的每行,k用于输出n倍的每列
Dim oldstr As String
n = InputBox("input n", "input a integer", 2) '这个 n就是问题中的n
a = Split(Text1.Text, Chr(13))
b = UBound(a) + 1 '获取text的 行数
For i = 0 To b - 1
For j = 1 To n
str = str & a(i) '在字符串末尾跟进一行原来的字符
Next j
str = str & Chr(13) '换行
Next i
oldstr = str
For k = 1 To n - 1
str = str & vbCrLf & oldstr
Next k
Text2.Text = str
End Sub
Private Sub Form_Load()
Command1.Caption = "复制矩阵"
End Sub
TA贡献2011条经验 获得超2个赞
以复制3次为例的代码:
Private Sub Command1_Click()
Dim R As String, A, I As Integer, N As Integer, J As Integer, S As String
N = 3
R = Text1.Text
A = Split(R, vbCrLf)
For I = LBound(A) To UBound(A)
S = ""
For J = 1 To N
S = S + A(I)
Next J
A(I) = S
Next I
R = Join(A, vbCrLf)
S = ""
For J = 1 To N
S = S + R
Next J
Text2.Text = S
End Sub
- 2 回答
- 0 关注
- 346 浏览
添加回答
举报