vb程序编写(数组)

vb程序编写(数组),第1张

Option Base 1

Private Sub Command1_Click()

Dim i%, m%, j%, s%, u%

Dim a As Variant

a = Array(23, 4, 14, 5, 57, 85, 43, 24, 78, 54)

u = UBound(a)

m = Val(InputBox("Input a number"))

For i = 1 To u

    If a(i) = m Then

        If i = u Then

            u = u - 1

            i = i - 1

            ReDim Preserve a(u)

            Exit For

        End If

        u = u - 1

        For j = i To u

            a(j) = a(j + 1)

        Next

        Exit For

    End If

Next

If i > u Then

    s = Val(InputBox("没有这个数,你想让它成为第几个数?"))

    u = u + 1

    ReDim Preserve a(u)

    For i = u - 1 To s Step -1

        a(i + 1) = a(i)

    Next

    a(s) = m

End If

For i = 1 To u

Print a(i)

Next

Private Sub Command1_Click()

Dim a(1 To 5, 1 To 5) As Integer

Dim b(1 To 5, 1 To 5) As Integer

Randomize

Label1.Caption = ""

Label2.Caption = ""

For i = 1 To 5

For j = 1 To 5

a(i, j) = Int(Rnd * 90) + 10

Label1.Caption = Label1.Caption &a(i, j) &Space(2)

Next

Label1.Caption = Label1.Caption &vbCrLf

Next

For i = 1 To 5

For j = 1 To 5

b(i, j) = a(j, i)

Label2.Caption = Label2.Caption &b(i, j) &Space(2)

Next

Label2.Caption = Label2.Caption &vbCrLf

Next

End Sub

Private Sub Form_Load()

Label1.AutoSize = True

Label2.AutoSize = True

Label1.Caption = ""

Label2.Caption = ""

Command1.Caption = "生成方阵"

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11082873.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-13
下一篇 2023-05-13

发表评论

登录后才能评论

评论列表(0条)

保存