Foxtable(狐表)用户栏目专家坐堂 → 【求助】如何在点击窗口的组合框时重复调用某段代码


  共有2887人关注过本帖树形打印复制链接

主题:【求助】如何在点击窗口的组合框时重复调用某段代码

帅哥哟,离线,有人找我吗?
wangjx817
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:261 积分:2150 威望:0 精华:0 注册:2018/4/30 16:00:00
【求助】如何在点击窗口的组合框时重复调用某段代码  发帖心情 Post By:2021/4/21 14:08:00 [只看该作者]

老师,我在设计窗口的某组合框控件时,在该组合框控件的enter事件中编写了以下一段代码,能够实现在点击该组合框时就出现下拉组合内容。但是在窗口中有很多组合框,为了减少代码的重复拷贝,在设计其他组合框时能自动调用除了最后一行之外其他重复部分的代码,如何使用内部函数实现,减少代码的重复拷贝,以及在修改段重复代码时不需要到每个组合框的enter事件中去修改的麻烦。
Dim gls As WinForm.ComboBox = e.Form.Controls("管理所")
Dim glz As WinForm.ComboBox = e.Form.Controls("管理站")
Dim jb As WinForm.CheckedComboBox = e.Form.Controls("级别")
Dim sx As WinForm.CheckedComboBox = e.Form.Controls("属性")
Dim yxzt As WinForm.CheckedComboBox = e.Form.Controls("运行状态")
Dim sbzt As WinForm.ComboBox = e.Form.Controls("状态")
Dim fdkj As WinForm.ComboBox = e.Form.Controls("分段口径")
Dim kj As WinForm.CheckedComboBox = e.Form.Controls("口径")
Dim ssgs As WinForm.ComboBox = e.Form.Controls("所属公司")
Dim ssdw As WinForm.ComboBox = e.Form.Controls("所属单位")
Dim sszd As WinForm.CheckedComboBox = e.Form.Controls("所属站点")
Dim ysdw As WinForm.CheckedComboBox = e.Form.Controls("原属单位")
Dim wbdw As WinForm.ComboBox = e.Form.Controls("维保单位")
Dim ybcs As WinForm.CheckedComboBox = e.Form.Controls("仪表厂商")
Dim jydw As WinForm.ComboBox = e.Form.Controls("校验单位")
Dim gdfs As WinForm.CheckedComboBox = e.Form.Controls("供电方式")
Dim xtlx As WinForm.ComboBox = e.Form.Controls("SCADA类型")
Dim aznf As WinForm.ComboBox = e.Form.Controls("安装年份")
Dim jcsj As WinForm.CheckedComboBox = e.Form.Controls("其他监测数据")
Dim czlx As WinForm.CheckedComboBox = e.Form.Controls("操作类型")
Dim zxyf As WinForm.ComboBox = e.Form.Controls("流量点在线与否")


Dim v1 As String = e.Form.Controls("级别").text
Dim v2 As String = e.Form.Controls("属性").text
Dim v3 As String = e.Form.Controls("运行状态").text
Dim v4 As String = e.Form.Controls("口径").text
Dim v5 As String = e.Form.Controls("所属站点").text
Dim v6 As String = e.Form.Controls("原属单位").text
Dim v7 As String = e.Form.Controls("仪表厂商").text
Dim v8 As String = e.Form.Controls("供电方式").text
Dim v9 As String = e.Form.Controls("其他监测数据").text
Dim v10 As String = e.Form.Controls("操作类型").text

Dim f As String

f  = IIF(gls.value > ""," 管理所 like '*" & gls.value & "*' and","") & _
     IIF(glz.value > ""," 管理站 like '*" & glz.value & "*' and","") & _
     IIF(v1 > ""," [级别] In ('" & v1.replace(",","','") & "') and","")  & _
     IIF(v2 > ""," [流量仪性质] In ('" & v2.replace(",","','") & "') and","")  & _
     IIF(v3 > ""," [运行状态] In ('" & v3.replace(",","','") & "') and","")  & _
     IIF(sbzt.value > ""," 设备状态 = '" & sbzt.value & "' and","") & _
     IIF(fdkj.value > ""," 分段口径 = '" & fdkj.value & "' and","") & _
     IIF(v4 > ""," [口径] In ('" & v4.replace(",","','") & "') and","")  & _
     IIF(ssgs.value > ""," 所属公司 = '" & ssgs.value & "' and","") & _
     IIF(ssdw.value > ""," 所属单位 = '" & ssdw.value & "' and","") & _
     IIF(v5 > ""," [所属站点] In ('" & v5.replace(",","','") & "') and","")  & _
     IIF(v6 > ""," [原属单位] In ('" & v6.replace(",","','") & "') and","")  & _
     IIF(wbdw.value > ""," 维保单位 = '" & wbdw.value & "' and","")  & _
     IIF(v7 > ""," [仪表厂商] In ('" & v7.replace(",","','") & "') and","")  & _
     IIF(jydw.value > ""," 校验单位 = '" & jydw.value & "' and","")  & _
     IIF(v8 > ""," [供电方式] In ('" & v8.replace(",","','") & "') and","")  & _ 
     IIF(xtlx.value > ""," SCADA类型 = '" & xtlx.value & "' and","")  & _
     IIF(aznf.value > ""," 安装年份 = '" & aznf.value & "' and","")  & _
     IIF(v9 > ""," [其他监测设备] In ('" & v9.replace(",","','") & "') and","")  & _
     IIF(v10 > ""," [操作类型] In ('" & v10.replace(",","','") & "') and","") & _
     IIF(zxyf.value > ""," SCADA流量点在线与否 = '" & zxyf.value & "'","")  


f = f.trimend("","d","n","a")
‘除了下面这行这行代码不重复、之前的代码都是一样不变的
e.Form.Controls("操作类型").Combolist = DataTables("流量仪").getcomboliststring("操作类型",f)  

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:110443 积分:562081 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By:2021/4/21 14:10:00 [只看该作者]


 回到顶部
帅哥哟,离线,有人找我吗?
wangjx817
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:童狐 帖子:261 积分:2150 威望:0 精华:0 注册:2018/4/30 16:00:00
  发帖心情 Post By:2021/4/21 14:32:00 [只看该作者]

非常感谢老师的指点和提醒,懂了。

 回到顶部