2 回答

TA貢獻(xiàn)2003條經(jīng)驗(yàn) 獲得超2個贊
再窗體上畫出text1,text2,并設(shè)置可以多行(multiline=true),一個Command1按鈕
用以下的算法,運(yùn)行時彈出輸入框, 輸入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的 行數(shù)
For i = 0 To b - 1
For j = 1 To n
str = str & a(i) '在字符串末尾跟進(jìn)一行原來的字符
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 = "復(fù)制矩陣"
End Sub

TA貢獻(xiàn)2011條經(jīng)驗(yàn) 獲得超2個贊
以復(fù)制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 關(guān)注
- 409 瀏覽
添加回答
舉報