vb 编程 没那么多财富 只能尽我所能了

设有如下两组数据:
A:2,8,7,6,4,28,70,25
B: 79,27,32,41,57,66,78,80
编程把上面两组数据分别读入两个数组中,然后把两个数组中对应下标的元素相加,即2+79,8+27…,并把相应的结果放入第3个数组C中,最后输出数组C的元素值。
最新回答
花开不败才是姿态

2024-11-30 04:29:45

把两段像2,8,7,6,4,28,70,25的字符串包含的数字相加,返回数组,如果已有数组,那么把for循环保留下来就可以了。
Private Function Add(Param1 As String, Param2 As String) As Long()
Dim i As Long
Dim Number1() As String
Dim Number2() As String
Dim Result() As Long
Number1() = Split(Param1, ",")
Number2() = Split(Param2, ",")
ReDim Result(UBound(Number1()))
For i = 0 To UBound(Number1())
Result(i) = CLng(Number1(i)) + CLng(Number2(i))
Next i
Add = Result()
End Function
Private Sub Form_Click()
Dim Res() As Long
Res() = Add("2,8,7,6,4,28,70,25", "79,27,32,41,57,66,78,80")
Dim i As Long
For i = 0 To UBound(Res())
Print Res(i)
Next i
End Sub
欧巴会发光

2024-11-30 07:51:22

''自定义一个函数
Public Sub Calculate(ByVal btnID As String)
Select Case btnID
Case "/"
TextBox3.Text = TextBox2.Text / TextBox1.Text
TextBox2.Text = "" ‘’清空除数
TextBox1.Text = "" ’清空被除数

Case "\"
TextBox3.Text = TextBox2.Text \ TextBox1.Text
TextBox2.Text = "" ‘’清空除数
TextBox1.Text = "" ’清空被除数

Case "Mod"
TextBox3.Text = TextBox2.Text Mod TextBox1.Text
TextBox2.Text = "" ‘’清空除数
TextBox1.Text = "" ‘’清空被除数

End Select

End Sub
'按钮的单击事件 把他们的Content分别设为 “\”“/” “Mod”就可以 传参到Calculate函数就可以了
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button_Seven.Click

Calculate(Button1.Content)

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button_Seven.Click

Calculate(Button2.Content)

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button_Seven.Click

Calculate(Button3.Content)

End Sub
一页

2024-11-30 06:04:23

Sub test()
Dim a, B, c()
Dim i As Integer
a = Array(2, 8, 7, 6, 4, 28, 70, 25)
B = Array(79, 27, 32, 41, 57, 66, 78, 80)
i = UBound(a)
ReDim c(0 To i)
For i = 0 To UBound(a)
c(i) = a(i) + B(i)
Print c(i)
Next
End Sub