以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]调用重复代码  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=170854)

--  作者:lgj716330
--  发布时间:2021/8/9 17:08:00
--  [求助]调用重复代码
我下面这段代码在同一窗口的很多Button中用到,我想弄一个通用的Button,然后在其他Button中调用,其他Button中要怎么写
With e.Form.Controls("YF1") 
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "月份 >= \'" & .value & "\'"
    End If
End With
With e.Form.Controls("YF2") 
    If .Value IsNot Nothing Then
        If Filter > "" Then
            Filter = Filter & " And "
        End If
        Filter = Filter & "月份 <= \'" & .value & "\'"
    End If
End With



--  作者:有点蓝
--  发布时间:2021/8/9 17:20:00
--  
方法1、http://www.foxtable.com/webhelp/topics/2309.htm
2、把代码放到自定义函数里:http://www.foxtable.com/webhelp/topics/1486.htm

--  作者:lgj716330
--  发布时间:2021/8/12 10:28:00
--  
我可否专门有个窗口用于存放可重复调用的代码,然后在其他窗口调用

Forms("通用代码").open()
Dim btn2 As WinForm.Button = Forms("通用代码").Controls("Button1")
btn2.PerformClick()

Button1里我放的是格式设置的代码,但结果没有起作用
For Each c As Col In CurrentTable.Cols
    If c.Caption Like "*增长*" Or c.Caption Like "*增加*" Or c.Caption Like "*占比*"   Then
        c.DataCol.SetFormat("0.00%")
    Else
        c.DataCol.SetFormat("0.")
    End If
Next

CurrentTable.AutoSizeCols()
CurrentTable.AutoSizeRows() \'设置行高
CurrentTable.DataTable.SysStyles("Subtotal0").BackColor = Color.pink \'设置报表样式
CurrentTable.DataTable.SysStyles("Subtotal0").FontBold = True
CurrentTable.DataTable.SysStyles("Subtotal1").BackColor = Color.SkyBlue \'设置报表样式
CurrentTable.DataTable.SysStyles("Subtotal1").FontBold = True
CurrentTable.DataTable.SysStyles("GrandTotal").FontBold = True
CurrentTable.DataTable.SysStyles("GrandTotal").BackColor = Color.GreenYellow


[此贴子已经被作者于2021/8/12 10:29:33编辑过]

--  作者:有点蓝
--  发布时间:2021/8/12 10:29:00
--  
把代码放到自定义函数里:http://www.foxtable.com/webhelp/topics/1486.htm
--  作者:lgj716330
--  发布时间:2021/8/12 10:39:00
--  
写在自定义函数里也试过了,也是不行
调用代码
Functions.Execute("fzzzhz")

--  作者:有点蓝
--  发布时间:2021/8/12 10:44:00
--  
不要使用CurrentTable,函数调用的时候传入具体的表格

函数
dim t as table = args(0)
For Each c As Col In t.Cols
    If c.Caption Like "*增长*" Or c.Caption Like "*增加*" Or c.Caption Like "*占比*"   Then
……

调用
Functions.Execute("fzzzhz",tables("xx表"))

--  作者:lgj716330
--  发布时间:2021/8/12 12:45:00
--  
自定义函数AAA
Dim frm As WinForm.Form =args(0)

    If frm.Controls("GC").Value IsNot Nothing Then
        If Filter > "" Then
            Filter  = Filter & " And "
        End If
        Filter  = Filter & "生产区域 In ( \'" & frm.Controls("GC").Value.replace(",","\',\'") & "\')"
    End If

调用函数

Functions.Execute("AAA",Forms("生产分析报表"))

筛选条件没起作用,哪里有问题帮忙看看

--  作者:有点蓝
--  发布时间:2021/8/12 13:45:00
--  
上面代码只是生成了筛选条件,却没有任何地方使用这个条件

自定义函数AAA
Dim frm As WinForm.Form =args(0)
Dim Filter As string =args(1)
    If frm.Controls("GC").Value IsNot Nothing Then
        If Filter > "" Then
            Filter  = Filter & " And "
        End If
        Filter  = Filter & "生产区域 In ( \'" & frm.Controls("GC").Value.replace(",","\',\'") & "\')"
    End If
return Filter  
调用函数
dim Filter   as string
Filter   = Functions.Execute("AAA",Forms("生产分析报表"),Filter   )
tables("表A").Filter   =Filter