怎么向ActiveX dll中传数组(解决麻烦给分)

wei977 2004-04-27 05:14:32
假设ActiveX dll类中有方法a

s_sql()为数组。

Public Function a(ByRef s_sql() As String) as String
a = UBound(s_sql)
End Function

我这样写好像不对
调用说类型不匹配,这里需要怎么写



...全文
153 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
egxsun 2004-08-02
  • 打赏
  • 举报
回复
数组可以传递,用数组名来传递,ByRef s_sql 就可以了
bluesky23 2004-08-02
  • 打赏
  • 举报
回复
学习,
帮顶
6742 2004-08-02
  • 打赏
  • 举报
回复
上面所说的调用,实际上是只是完成参数的传递而已。
6742 2004-08-02
  • 打赏
  • 举报
回复
在一动态库里
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
zcm123 2004-08-02
  • 打赏
  • 举报
回复
狂赞同 ByRef s_sql As Variant
csdnchenxu 2004-08-02
  • 打赏
  • 举报
回复
最好是属性!

Public Function a(ByVal s_sql() as string) as string
Redim a(UBound(s_sql))
a = s_sql
End Function

OK了,不过存在隐患,就是当s_sql()为空时,UBound(s_sql)报告错误
脆皮大雪糕 2004-08-02
  • 打赏
  • 举报
回复
ByRef s_sql As Variant 试试看
LGYAN 2004-08-02
  • 打赏
  • 举报
回复
拜托你把使用该方法的语句也拿出来
LGYAN 2004-08-02
  • 打赏
  • 举报
回复
不懂耶

在一标准EXE里
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

为什么我可以啊?
csdnchenxu 2004-08-02
  • 打赏
  • 举报
回复
不好意思,搞错了点,改为

Public Function a(ByVal s_sql() as string) as variant
Redim a(UBound(s_sql))
a = s_sql
End Function
grove2003 2004-08-01
  • 打赏
  • 举报
回复
楼主这个问题解决了没有,我也遇到相同的问题?难道说ActiveX DLL中不能传数组?好郁闷哟??
熊孩子开学喽 2004-08-01
  • 打赏
  • 举报
回复
数组不能直接作为参数来使用,只能定义为Variant
相同的例子还有使用Split函数来分割字符串到数组,也是同样的道理。
online 2004-08-01
  • 打赏
  • 举报
回复
Public Function a(ByRef s_sql As Variant) As Long
a = UBound(s_sql)
End Function

如果使用引用传递,将参数的类型设为Variant。这样做可以避免一些错误。不过尽可能的减少引用传递参数
sysmaster 2004-07-23
  • 打赏
  • 举报
回复
可能对你有用:

Private Sub Command1_Click()
Dim myarray(1) As Integer
myarray(0) = 7
myarray(1) = 45
MsgBox sum(myarray)
End Sub

Public Function sum(ByRef array2() As Integer) '这一定要用ByRef
sum = array2(1) + array2(0)
End Function
wei977 2004-04-28
  • 打赏
  • 举报
回复
我先引用这个ActiveX dll
然后
Dim b As New wfwsClient.Class1
Dim c(2) as String

c(0)=0
c(1)=1
c(2)=2
d=b.a(c)但是这里说参数类型不匹配,所以我就不知道那错了啊
wei977 2004-04-28
  • 打赏
  • 举报
回复
但是传到dll里面怎么是说参数不匹配啊
tangxiaosan001 2004-04-27
  • 打赏
  • 举报
回复
下班了,明天再来看.
ukyoxh 2004-04-27
  • 打赏
  • 举报
回复
学习ing

关注ing

正确ing

建议定义新的数据类型来进行传递,这样区分方便一点。

leolan 2004-04-27
  • 打赏
  • 举报
回复
ByRef s_sql() As String應該沒問題呀.
或者用byval s_sql as variant
wei977 2004-04-27
  • 打赏
  • 举报
回复
我是要问ByRef s_sql() As String这样写不对。要怎么写。传数组
加载更多回复(1)

7,762

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧