vb 向数组中指定位置添加元素。

vb 向数组中指定位置添加元素。,第1张

Private

Sub

Command1_Click()

Dim

x()

As

Integer,

i%,

n%,

k%

ReDim

x(1

To

10)

As

Integer

Form1.Cls

For

i

=

1

To

10

x(i)

=

Int(Rnd()

*

10)

Print

x(i)

Next

i

n

=

Val(Text1)

'插入数字

k

=

Val(Text2)

'插入位置

If

n

>

0

And

k

>

0

And

k

<

11

Then

ReDim

Preserve

x(1

To

11)

As

Integer

For

i

=

(UBound(x)

-

1)

To

(k

-

1)

Step

-1

x(i

+

1)

=

x(i)

Next

i

x(k)

=

n

Print

For

i

=

1

To

11

Print

x(i)

Next

i

Else

MsgBox

"输入数字有误",

vbCritical

End

If

End

Sub

假定“数据记录3”是控件数组Text1,“字符累计4”是控件数组Text2,“数据输入1”是Text3,“指点位置2”是Text4,按钮是Command1,则

Private Sub Command1_Click()

Dim s As Long, i As Long, j As Long

For i = Text2.LBound To Text2.UBound

If Val(Text2(i).Text) = Val(Text4.Text) Then Exit For

Next

If i <= Text2.UBound Then

For j = Text1.UBound To i + 1 Step -1

Text1(j).Text = Text1(j - 1).Text

Next

Text1(i).Text = Text3.Text

For i = Text1.LBound To Text1.UBound

s = s + Len(Text1(i).Text)

Text2(i).Text = s

Next

End If

End Sub


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

原文地址: http://outofmemory.cn/bake/11403315.html

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

发表评论

登录后才能评论

评论列表(0条)

保存