vb 截取文本框内容并计算 文本框内容(text1): 8&8 9&10 6&8 7&11 4&2 77&10 6&5 4&2

分成两列896747764和81081121052如何分别计算每列之和,大家帮忙帮忙,结果格式为(第一列之和)&(第二列之和)... 分成两列
8
9
6
7
4
77
6
4


8
10
8
11
2
10
5
2如何分别计算每列之和,大家帮忙帮忙,结果格式为(第一列之和)&(第二列之和)
展开
 我来答
龙lingfeng
2012-10-20 · TA获得超过106个赞
知道小有建树答主
回答量:258
采纳率:0%
帮助的人:165万
展开全部
Private Sub Command1_Click()
Dim a() As String, b() As String, tmp() As String
Dim NumA As Integer, NumB As Integer,c as integer

tmp = Split(Trim(Text1), " ")
For i = LBound(tmp) To UBound(tmp)
c = InStr(1, tmp(i), "&", 1)
'Exit For
ReDim Preserve a(i)
ReDim Preserve b(i)
a(i) = Left(tmp(i), c - 1)
b(i) = Right(tmp(i), Len(tmp(i)) - c)
NumA = NumA + Val(a(i))
NumB = NumB + Val(b(i))

Next
MsgBox "第一列之和为:" & NumA & vbCrLf & "第二列之和为:" & NumB
End Sub

'或着:
Private Sub Command1_Click()
Dim tmp() As String
Dim NumA As Integer, NumB As Integer, c As Integer

tmp = Split(Trim(Text1), " ")
For i = LBound(tmp) To UBound(tmp)
c = InStr(1, tmp(i), "&", 1)
NumA = NumA + Val(Left(tmp(i), c - 1))
NumB = NumB + Val(Right(tmp(i), Len(tmp(i)) - c))

Next
MsgBox "第一列之和为:" & NumA & vbCrLf & "第二列之和为:" & NumB
End Sub
追问
太好了,谢谢啊 ,文本框内容(text1)为竖的能否可以计算到
8&8
9&10
6&8
7&11
4&2
77&10
6&5
4&2
追答
将:
tmp = Split(Trim(Text1), " ")

替换为:
tmp = Split(Trim(Text1), vbcrlf)
匿名用户
2012-10-20
展开全部
Private Sub Command1_Click()
Dim i As Integer, A(8) As Integer, B(8) As Integer
Dim TR2 As String, P2 As Integer, TR1 As String, P As Integer
Dim SUMA As Integer, SUMB As Integer, F As Boolean
TR1 = Text1
Print TR1
P = 0
F = True
Do
P = InStr(1, TR1, " ")
If P <> 0 Then
TR2 = Left(TR1, P - 1)
Else
TR2 = TR1
F = False
End If
P2 = InStr(1, TR2, "&")
A(i) = Left(TR2, P2 - 1)
B(i) = Right(TR2, Len(TR2) - P2)
SUMA = SUMA + A(i)
SUMB = SUMB + B(i)
Print A(i), B(i)
i = i + 1
If F Then TR1 = Right(TR1, Len(TR1) - P) Else Exit Do
Loop
Print "(" & SUMA & ") & (" & SUMB & ")"
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式