假设ActiveX dll类中有方法as_sql()为数组。 Public Function a(ByRef s_sql() As String) as String
a = UBound(s_sql)
End Function我这样写好像不对
调用说类型不匹配,这里需要怎么写
a = UBound(s_sql)
End Function我这样写好像不对
调用说类型不匹配,这里需要怎么写
解决方案 »
- 怎么通过代码在一个窗体上创建与另一个窗体上的控件一样的控件
- 有谁知道火星文是通过替换,还是算法来生成的呢?
- 求读串口数据源代码
- 请问怎样设置VB报表的参数,例如怎样设成A3纸?
- 你选择怎样保护你的软件
- 把TEXT1内字符串的前6位赋值给TEXT2这个语句怎么写?急呀!!
- FORM1-LOAD() 中有LISTBOX控件,显示某一表单的某一字段的内容,但在运行时提示错误"对象不支持该属性和操作" ,而且LISTBOX中有几个项目,就
- 端午节快乐!送TTS发音代码,求意见!
- text文本框怎么换行....(循环语句中)
- 一手给代码,一手交分!
- 在线急等!怎么样是button按钮失去焦点!
- 如何取得网络上计算机的MAC地址
Public Function a(ByRef s_sql() As String) as String
a = UBound(s_sql)
End Function
數組:
Public Function a(ByRef s_sql() As String) as Variant
a = s_sql
End Function
字串:
Public Function a(ByRef s_sql() As String) as String
a = s_sql(Ubound(s_sql))
End Function
或者用byval s_sql as variant
然后
Dim b As New wfwsClient.Class1
Dim c(2) as Stringc(0)=0
c(1)=1
c(2)=2
d=b.a(c)但是这里说参数类型不匹配,所以我就不知道那错了啊
Dim myarray(1) As Integer
myarray(0) = 7
myarray(1) = 45
MsgBox sum(myarray)
End SubPublic Function sum(ByRef array2() As Integer) '这一定要用ByRef
sum = array2(1) + array2(0)
End Function
a = UBound(s_sql)
End Function如果使用引用传递,将参数的类型设为Variant。这样做可以避免一些错误。不过尽可能的减少引用传递参数
相同的例子还有使用Split函数来分割字符串到数组,也是同样的道理。
Private Sub Form_Load()
Dim a As New Class1
Dim e(0 To 23) As String
MsgBox a.a(e)
End Sub
在一动态库里
Public Function a(ByRef s_sql() As String) As Long
a = UBound(s_sql)
End Function为什么我可以啊?
Redim a(UBound(s_sql))
a = s_sql
End FunctionOK了,不过存在隐患,就是当s_sql()为空时,UBound(s_sql)报告错误
Public Function a(ByRef s_sql() As String) As Variant
Dim b As Variant
b = s_sql
For i = LBound(s_sql) To UBound(s_sql)
MsgBox b(i)
Next
End Function
在标准EXE文件中
Private Sub Form_Load()
Dim a1 As New Class1
Dim e(0 To 22) As String
For I = 0 To 22
e(I) = "LKGFD" & I
Next
Dim aaa
aaa = a1.a(e)'调用
End Sub
Redim a(UBound(s_sql))
a = s_sql
End Function