猿问

懂VB的大佬请进!急急急~

text1里面有一个0和1组成的N*N的数学矩阵(N不是定值,0和1也不一定间隔出现)
先用下面的作比方
010101
101010
010101
101010
010101
101010
上面这样一个6*6的矩阵怎样将它向右向下复制几次成为一个aN*aN的新的矩阵
输出在text2里面

qq_花开花谢_0
浏览 340回答 2
2回答

湖上湖

再窗体上画出text1,text2,并设置可以多行(multiline=true),一个Command1按钮用以下的算法,运行时弹出输入框, 输入n就可以了。Private Sub Command1_Click()Dim a() As StringDim str As String '用于输出的 字符串Dim n, i, j, k As Integer 'i与j用于输出n倍的每行,k用于输出n倍的每列Dim oldstr As Stringn = InputBox("input n", "input a integer", 2) '这个 n就是问题中的na = Split(Text1.Text, Chr(13))b = UBound(a) + 1 '获取text的 行数For i = 0 To b - 1For j = 1 To nstr = str & a(i) '在字符串末尾跟进一行原来的字符Next jstr = str & Chr(13) '换行Next ioldstr = strFor k = 1 To n - 1str = str & vbCrLf & oldstrNext kText2.Text = strEnd SubPrivate Sub Form_Load()Command1.Caption = "复制矩阵"End Sub

森林海

以复制3次为例的代码:Private Sub Command1_Click()Dim R As String, A, I As Integer, N As Integer, J As Integer, S As StringN = 3R = Text1.TextA = Split(R, vbCrLf)For I = LBound(A) To UBound(A)S = ""For J = 1 To NS = S + A(I)Next JA(I) = SNext IR = Join(A, vbCrLf)S = ""For J = 1 To NS = S + RNext JText2.Text = SEnd Sub
随时随地看视频慕课网APP
我要回答