以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  关于函数请教  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=37191)

--  作者:atmetmicoo
--  发布时间:2013/7/2 16:16:00
--  关于函数请教
请教:

在一个事件中有一段代码会反复出现,为了让代码显得简洁,我只想调用某一段编码,我尝试过用添加自定义函数,但是自定义函数必须是完整的代码,而我只想调用某一小段代码,请问有没有其他方式可实现。

--  作者:Bin
--  发布时间:2013/7/2 16:17:00
--  
一小段代码一样可以当作自定义函数使用啊,哪怕是一句代码也可以啊.
--  作者:atmetmicoo
--  发布时间:2013/7/2 16:27:00
--  
Bin老师,例如:
dim tabletmp1 as string = "表B"
dim deps as list(of string) = datatables("表a").GetUniqueValues("","仓库")
for each dep as string in deps
    tables(tabletmp1).addnew()
    tables(tabletmp1).current("仓库”) = dep
next

我想将红色部分代码用自定义函数代替,在新建自定义函数的时候,就不让保存,会提是tabletmp1dep等未被定义,像这样如何解决?

--  作者:Bin
--  发布时间:2013/7/2 16:29:00
--  
参数是需要传递进去的. http://www.foxtable.com/help/topics/1486.htm


  tables(Args(0)).addnew()
    tables(Args(0)).current("仓库”) = Args(1)

--  作者:狐狸爸爸
--  发布时间:2013/7/2 16:31:00
--  

函数代码:
 
tables(args(0)).addnew()
tables(args(0)).current("仓库”) = args(1)
 
调用语法:
 
dim tabletmp1 as string = "表B"

dim deps as list(of string) = datatables("表a").GetUniqueValues("","仓库")
for each dep as string in deps
     Functions.Execute("函数名",tabletmp1,dep)

next

 


--  作者:atmetmicoo
--  发布时间:2013/7/3 8:52:00
--  
OK,非常感谢二位长老相助
--  作者:jspta
--  发布时间:2013/7/3 9:41:00
--  
以下是引用atmetmicoo在2013-7-2 16:27:00的发言:
Bin老师,例如:
dim tabletmp1 as string = "表B"
dim deps as list(of string) = datatables("表a").GetUniqueValues("","仓库")
for each dep as string in deps
    tables(tabletmp1).addnew()
    tables(tabletmp1).current("仓库”) = dep
next

我想将红色部分代码用自定义函数代替,在新建自定义函数的时候,就不让保存,会提是tabletmp1dep等未被定义,像这样如何解决?

个人觉得把这整段全封装成函数,效果会更好。整理下思路,形成一个通用的函数,比你单单封装2句话效果更好。