vb高手进,多行文本存入二维数组问题
每行有144个“0”和“1”组成的数。先把每行为144个数变成每行8个数18行,然后将每8列18行的数存入二维数组将行列转换,并输出到另一个多行文本框...
每行有144个“0”和“1”组成的数。先把每行为144个数变成每行8个数18行,然后将每8列18行的数存入二维数组将行列转换,并输出到另一个多行文本框
展开
4个回答
展开全部
'我这个是在2楼的基础上改进的,更简洁
'在窗体上加入控件text1,text2,command1,text1用来输入每行有144个“0”和“1”组成的数
'text2(text2 的Multiline设置为True)用来显示结果,command1表示开始转换
'复制下面代码到窗体中,在text1中输入有关数据,按command1,即可在text2中看到结果。
'====代码部分====
Private Sub Command1_Click()
Dim i As Integer, j As Integer, k As Integer
Dim t(7, 17) As String, Tmp As String
For i = 0 To 7
For j = 0 To 17 '把每行为144个数变成每行8个数18行
t(i, j) = Mid(Text1.Text, i * 8 + j + 1, 1)
Next
Next
'行列转换
k = 1
For i = 0 To 17
For j = 0 To 7
Tmp = Tmp & t(j, i) & IIf(k Mod 18 = 0, vbNewLine, "")
k = k + 1
Next
Next
Text2.Text = Tmp '输出到文本框text2
End Sub
'在窗体上加入控件text1,text2,command1,text1用来输入每行有144个“0”和“1”组成的数
'text2(text2 的Multiline设置为True)用来显示结果,command1表示开始转换
'复制下面代码到窗体中,在text1中输入有关数据,按command1,即可在text2中看到结果。
'====代码部分====
Private Sub Command1_Click()
Dim i As Integer, j As Integer, k As Integer
Dim t(7, 17) As String, Tmp As String
For i = 0 To 7
For j = 0 To 17 '把每行为144个数变成每行8个数18行
t(i, j) = Mid(Text1.Text, i * 8 + j + 1, 1)
Next
Next
'行列转换
k = 1
For i = 0 To 17
For j = 0 To 7
Tmp = Tmp & t(j, i) & IIf(k Mod 18 = 0, vbNewLine, "")
k = k + 1
Next
Next
Text2.Text = Tmp '输出到文本框text2
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
'在窗体上加入控件text1,text2,command1,text1用来输入每行有144个“0”和“1”组成的数,text2用来显示结果,command1表示开始转换
'复制下面代码到窗体中,在text1中输入有关数据,按command1,即可在text2中看到结果。
'====代码部分====
Private Sub Command1_Click()
Dim zf() As String, s(1 To 18), t(1 To 18, 1 To 8)
Dim i As Integer, j As Integer, k As Integer, Tmp As String
Text2.Text = ""
zf = Split(Text1.Text, vbNewLine)
For i = 0 To UBound(zf)
For j = 1 To 18 '把每行为144个数变成每行8个数18行
s(j) = Mid(zf(i), 8 * j - 7, 8)
For k = 1 To 8 '将每8列18行的数存入二维数组
t(j, k) = Mid(s(j), k, 1)
Next
Next
'行列转换
Tmp = ""
For j = 1 To 8
For k = 1 To 18
Tmp = Tmp & t(k, j)
Next
Tmp = Tmp & vbNewLine
Next
Text2.Text = Text2.Text & Tmp '输出到文本框text2
Next
End Sub
'复制下面代码到窗体中,在text1中输入有关数据,按command1,即可在text2中看到结果。
'====代码部分====
Private Sub Command1_Click()
Dim zf() As String, s(1 To 18), t(1 To 18, 1 To 8)
Dim i As Integer, j As Integer, k As Integer, Tmp As String
Text2.Text = ""
zf = Split(Text1.Text, vbNewLine)
For i = 0 To UBound(zf)
For j = 1 To 18 '把每行为144个数变成每行8个数18行
s(j) = Mid(zf(i), 8 * j - 7, 8)
For k = 1 To 8 '将每8列18行的数存入二维数组
t(j, k) = Mid(s(j), k, 1)
Next
Next
'行列转换
Tmp = ""
For j = 1 To 8
For k = 1 To 18
Tmp = Tmp & t(k, j)
Next
Tmp = Tmp & vbNewLine
Next
Text2.Text = Text2.Text & Tmp '输出到文本框text2
Next
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
x&=str(y)'y即144个1或0
dim z(17) as string
do while i<18
z(i)=mid(x&,i*8)
i=i+1
loop
dim xyz()
redim xyz(18,dongt)
dongt=1
i=0
do while i<18
xyz(i,dongt)=z(i)
i=i+1
loop
dongt=2
.....
dongt=3
....
自己完整一下.
dim z(17) as string
do while i<18
z(i)=mid(x&,i*8)
i=i+1
loop
dim xyz()
redim xyz(18,dongt)
dongt=1
i=0
do while i<18
xyz(i,dongt)=z(i)
i=i+1
loop
dongt=2
.....
dongt=3
....
自己完整一下.
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Dim a()
Dim i As Integer, j As Integer, k As Integer
Dim strLine As String, x As String
Open "c:\1.txt" For Input As #1 '打开文件,改成你自己的文件路径
Do While Not EOF(1)
ReDim a(1 To 18, 1 To 8)
Line Input #1, strLine
k = 0
For i = 1 To 18
For j = 1 To 8
k = k + 1
a(i, j) = Mid(strLine, k, 1) '读取数据到数组
Next
Print
Next
For j = 1 To 8
For i = 1 To 18
x = x & a(i, j) '行列转化,列变行
Next
Text1 = Text1 & x & vbCrLf '输出到文本框
x = ""
Next
Loop
End Sub
Dim a()
Dim i As Integer, j As Integer, k As Integer
Dim strLine As String, x As String
Open "c:\1.txt" For Input As #1 '打开文件,改成你自己的文件路径
Do While Not EOF(1)
ReDim a(1 To 18, 1 To 8)
Line Input #1, strLine
k = 0
For i = 1 To 18
For j = 1 To 8
k = k + 1
a(i, j) = Mid(strLine, k, 1) '读取数据到数组
Next
Next
For j = 1 To 8
For i = 1 To 18
x = x & a(i, j) '行列转化,列变行
Next
Text1 = Text1 & x & vbCrLf '输出到文本框
x = ""
Next
Loop
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询