Public Function tt(n As Integer, p As Integer) As Integer
tt = n * p
End FunctionPrivate Sub Form_Load()
Dim cc As Integer
Dim p As Integer
Dim arrid(1) As Integer
Dim fun_name As String '函数名称
Dim n As Integer '参数
fun_name = "tt"
arrid(0) = 3
arrid(1) = 5
cc = CallByName(Form1, fun_name, VbMethod, arrid( ))
MsgBox cc
End Subcc = CallByName(Form1, fun_name, VbMethod, arrid( ))
为什么我这样来传递这个数组就不行,正确的要怎么传递?
谢谢..
tt = n * p
End FunctionPrivate Sub Form_Load()
Dim cc As Integer
Dim p As Integer
Dim arrid(1) As Integer
Dim fun_name As String '函数名称
Dim n As Integer '参数
fun_name = "tt"
arrid(0) = 3
arrid(1) = 5
cc = CallByName(Form1, fun_name, VbMethod, arrid( ))
MsgBox cc
End Subcc = CallByName(Form1, fun_name, VbMethod, arrid( ))
为什么我这样来传递这个数组就不行,正确的要怎么传递?
谢谢..
tt = a(0) * a(1)
End Function
dim i as integer
dim arr as variants="ABC"
i=101
arr=array(1,"D")cc = CallByName(Form1, fun_name, VbMethod, s, i,arr)
对了,家人:
s="ABC"
i=101
arr=array(1,"D")cc = CallByName(Form1, fun_name, VbMethod, s, i,arr)这里面要怎么调用函数的?
arraystr1(0) = "1"
arraystr1(1)="2"
cc = CallByName(Form1, fun_name, VbMethod, arraystr1(0), arraystr1(2))
但一改成这样又可以了:
a = "1"
b ="2"
cc = CallByName(Form1, fun_name, VbMethod, a, b)
好像明显着不支持数组的.
谢谢。
数据库存储的数据如下,
其中:function_name为函数名,function_value为函数格式,
content_info为函数的具体参数值.id function_name function_value content_info
1 selecttype1 str,1 1;
2 selecttype2 str 2例如现在从数据库读出ID为1这条纪录的时候,
会执行这个selecttype1(1;,1)的函数并把处理后的结果赋给另外一个变量vb_CallBy
其中函数名(selecttype1)、函数格式(str,1)、函数参数值(1;)
即是将function_value字段里面的"str,1"中的str替换成参数值里面的1;变为(1;,1),然后用这个函数selecttype1来执行,并把执行结果赋给另外一个变量vb_CallBy。
因为数据库里面存储的是不同的函数格式及函数内容,所以仍需站在一个通用的高度上解决。
再次谢谢!
现在主要是读出来后怎么执行函数,并且不同的函数有不同的格式。
要怎么进行包含考虑?
谢谢
但是,现在好像CallByName又认不了数组。
private sub from_load()
print "test!"
end sub
print "test!"
end sub
private sub from_load()
print "test!"
end sub
'下面这个函数需要三个函数,一个string,一个integer,一个string数组
Function test(s As String, n As Integer, arr() As String) As Integer
Dim tmp As Integer, i As Integer
tmp = Len(s) + n
For i = 0 To UBound(arr)
tmp = tmp + Len(arr(i))
Next
test = tmp
End FunctionPrivate Sub Command1_Click()
Dim strS As String '参数s
Dim intN As Integer '参数n
Dim arrS(1) As String '参数arr
Dim v As Integer
strS = "ABC"
intN = 1000
arrS(0) = "D"
arrS(1) = "FF"
v = CallByName(Me, "test", VbMethod, strS, intN, arrS)
MsgBox v
End Sub
Option ExplicitPublic Function Test(intData() As Integer, intSize As Integer) As Integer
Dim intLoop As Integer
For intLoop = 0 To intSize
Test = Test + intData(intLoop) 'Count
Next
End FunctionPrivate Sub Command1_Click()
Dim intReturn As Integer 'Count
Dim arrid(1) As Integer
Dim fun_name As String '函数名称
Dim ArrSize As Integer 'arrary Size
fun_name = "Test" 'set Name of function
ArrSize = UBound(arrid) 'set UpIndex of Arrary
arrid(0) = 3
arrid(1) = 5
intReturn = CallByName(Me, fun_name, VbMethod, arrid(), ArrSize)
MsgBox intReturn
End Sub你把函数这样写,经过测试通过,经过为8
Public Function Test(intData() As Integer, intSize As Integer) As Integer
Dim intLoop As Integer
For intLoop = 0 To intSize
Test = Test + intData(intLoop) 'Count
Next
End FunctionPrivate Sub Command1_Click()
Dim intReturn As Integer 'Count
Dim arrid(1) As Integer
Dim fun_name As String '函数名称
Dim ArrSize As Integer 'arrary Size
fun_name = "Test" 'set Name of function
ArrSize = UBound(arrid) 'set UpIndex of Arrary
arrid(0) = 3
arrid(1) = 5
intReturn = CallByName(Me, fun_name, VbMethod, arrid(), ArrSize)
MsgBox intReturn
End Sub你把函数这样写,经过测试通过,经过为8
嘿嘿,终于有点眉目了.
不过,对了,ZOU_SEAFARER,我需要传送的数组类型是这样的,都是字符型来的.
arrid(0)="1;"
arrid(1)="1" 这个要怎么改的?
'其中outdata1接收的是"1;",outdata2接收的是"1"
'之所以outdata1接收的是"1;"是因为有时候要传递的值可能是"1;2;3;",我在函数里面会有一个循环读取的程序。
***************代码太多了,暂先略掉。
end sub
谢谢。
数据库存储的数据如下,
其中:function_name为函数名,function_value为函数格式,
content_info为函数的具体参数值. id function_name function_value content_info
1 selecttype1 str,1 1;
2 selecttype2 str 2 例如现在从数据库读出ID为1这条纪录的时候,
会执行这个selecttype1(1;,1)的函数并把处理后的结果赋给另外一个变量vb_CallBy
其中函数名(selecttype1)、函数格式(str,1)、函数参数值(1;)
即是将function_value字段里面的"str,1"中的str替换成参数值里面的1;变为(1;,1),然后用这个函数selecttype1来执行,并把执行结果赋给另外一个变量vb_CallBy。
因为数据库里面存储的是不同的函数格式及函数内容,所以仍需站在一个通用的高度上解决。
再次谢谢! ----------------------------------------------------------
dim rs as adodb.recordset
'......dim fun as string
dim p1 as string,p2 as string
dim vb_CallBy fun=rs!function_name '得到函数名
if ubound(split(rs!function_value,","))>0 then
'如果function_value有逗号
p1=rs!content_info '参数1就是rs!content_info
p2=split(rs!function_value,",")(1)'参数2是function_value中的逗号后面的值
end ifvb_CallBy =callbyname(me,"selecttype1",vbmethod,p1,p2)这个意思?
被你这样一分,好像清淅很多呀。
没错,只要能执行这个selecttype1(1;,1)函数就行了,要传递的参数是1;1这两个。
CHANGE to Dim
这个是什么东东啊,我一加又就提示错了?
print "test!"
end sub