求助 含有窗口文本框中字符2个以上的行筛选出来
此主题相关图片如下:2录入a筛选出第3、5、6绿色这3行.jpg
Dim s, s1, Filter As String
s = Forms("窗口1").Controls("textbox1").Value
For Each dr As DataRow In DataTables("表A").DataRows
s1 = dr("第一列")
If s1.Length - s1.Replace(s, "").Length > s.Length * 2 - 1 Then
If Filter.Contains(s1) = False Then
Filter = Filter & "|" & s1
End If
End If
Next
Filter = Filter.Trim("|")
Filter = "第一列 = '" & Filter.Replace("|", "' and 第一列 = '") & "'"
Tables("表A").Filter = Filter
Tables("表A").Filter = ""
Dim s, s1, Filter As String
s = Forms("窗口1").Controls("textbox1").Value
For Each dr As DataRow In DataTables("表A").DataRows
s1 = dr("第一列")
If s1.Length - s1.Replace(s, "").Length > s.Length * 2 - 1 Then
If Filter.Contains(s1) = False Then
Filter = Filter & "|" & s1
End If
End If
Next
Filter = Filter.Trim("|")
Filter = "第一列 = '" & Filter.Replace("|", "' and 第一列 = '") & "'"
Tables("表A").Filter = Filter
感谢程总,这么早哈程总,上面代码执行没效果,报错,有空,辛苦帮忙再看看
.NET Framework 版本:4.0.30319.42000
Foxtable 版本:2022.8.18.1
错误所在事件:窗口,窗口1,Button3,Click
详细错误信息:
未将对象引用设置到对象的实例。
还有一点要求就是想不是固定表A第一列,想动态表当前列都能实现这个搜索功能
Dim t As Table = currenttable
Dim tb As String = t.cols(t.colsel).name
[此贴子已经被作者于2024/8/28 8:34:05编辑过]
Dim s, s1, Filter As String
s = Forms("窗口1").Controls("combobox1").text
For Each dr As DataRow In DataTables("表A").DataRows
s1 = dr("第一列")
If s1.Length - s1.Replace(s, "").Length >= 2 Then
Filter = Filter & "," & dr("_identify")
End If
Next
Filter = Filter.Trim(",")
Filter = "_identify in (" & Filter & ")"
Output.Show(filter)
Tables("表A").Filter = Filter
.Value改为.text即可,我的的码考虑了a可以为一个连续的字符串,因为没有看您的文件,控件、表、字段名称自己修改,估计报错的原因是您修改后currenttable的问题,也就currenttable不存在!