VB二级上机考试调试--如何调用数组

来源:百度知道 编辑:UC知道 时间:2024/05/29 06:36:16
请问如何进行数组调用? 如第一题,我在form_click 中调用 p(a%()) 程序出现子程序或函数未定义,调用 p,则出现参数不可选,调用
dim a(4) as integer
a(0)=-2
a(1)=1
a(2)=3
a(3)=-5
a(4)=6
call p(a)则什么都没有出现!! 请高手帮忙 ,以下两道题目究竟应该怎么调用?如果成功的话会加分!题目如下:

题目1:
Option Explicit
Public Sub p(a%())
'该过程是用于整理数组a,使其中小于零的元素移到数组的前端,
'大于零的元素移到数组的后端,等于零的元素留在数组的中间。
Dim i%, low%, high%, t%
low = 0
i = 0
high = UBound(a) - 1
Do While low < high
If a(i) < 0 Then
t = a(i)
a(i) = a(low)
a(low) = t
low = low + 1
i = i + 1
ElseIf a(i) > 0 Then
t = a(i)
a(i) = a(high)
a(high) = t
high = high - 1
Else
i = i + 1
End If
Loop
End Sub

题目2:
Option Explicit
Public Sub MoveStr(a$(), m%, Tag As Boolean)
'该过程是把字符数组移动m个位置,当Tag为True左移,则前m个字符移到字符数组尾。
Dim i%, j%, t$
Dim c

If Tag Then
For i = 1 To m
c =

汗,记得回答过一次的
call p(a)没错,程序本身就没有输出语句,当然没有反应
1/
Private Sub Form_Click()
Dim a(4) As Integer
a(0) = -2
a(1) = 1
a(2) = 3
a(3) = -5
a(4) = 6
Call p(a)
For i = 0 To 4
Print a(i)
Next i
End Sub
Public Sub p(a%())
'该过程是用于整理数组a,使其中小于零的元素移到数组的前端,
'大于零的元素移到数组的后端,等于零的元素留在数组的中间。
Dim i%, low%, high%, t%
low = 0
i = 0
high = UBound(a) - 1
Do While low < high
If a(i) < 0 Then
t = a(i)
a(i) = a(low)
a(low) = t
low = low + 1
i = i + 1
ElseIf a(i) > 0 Then
t = a(i)
a(i) = a(high)
a(high) = t
high = high - 1
Else
i = i + 1
End If
Loop
End Sub

2/
Private Sub Form_Click()
Dim a(4) As String
a(0) = "a"
a(1) = "b"
a(2) = "c"
a(3) = "d"
a(4) = "e"
Call MoveStr(a, 2, True)
For i = 0 To 4
Print a