关于假定有如下的Sub过程:
Sub s(x As Single, y As Single)
t = x
x = t / y
v = t Mod y
End Sub
在窗体上画一个命令按钮,然后编写如下事件过程:
Private Sub Commandl_Click()
Dim a As Single
a = 5
b = 4
Call s(a, b)
Print a, b
End Sub
谁能解释一下为什么会发生这个编译错误
by ref 参数类型不符的问题
你的代码有几处错误,一是SUB过程内参数为(X,Y),在按钮事件中CALL S时传递的是(A,B)。二是按显式定义变量要求,T和V未定义。三是尽管你在SUB过程中定义参数的数据类型,显式定义仍要重定义变量,在外称变量,在SUB过程内称参数。
结果并未传递进SUB过程。
下面是修改后的代码,供参考:
Option Explicit
Private x As Single
Private y As Single
Private t As Single
Private v As Single
Private Sub s(x As Single, y As Single)
x = t / y
v = t Mod y
End Sub
Private Sub Command1_Click() ‘在窗体上画一个命令按钮,然后编写如下事件过程:
t = 15
y = 4
Call s(x, y)
Print x, v
End Sub。