以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- Find语句中能否引用随机产生的数值呢? (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=134277) |
||||
-- 作者:旭日生 -- 发布时间:2019/5/3 12:08:00 -- Find语句中能否引用随机产生的数值呢?
下面这段代码复制到命令窗口,如果: 1、Find("[第二列] Like \'%J%\'") ,则可以正确运行。 2、替换成随机变量,Find("[第二列] Like \'% & vs(Rand.Next(0,vs.Count-1)) & %\'") ,或Find("[第二列] Like \'% & v1 & %\'"), 则不出结果。如何解决? 我的目的是这样的: 1、随机从中声母中选取一个声母。 2、从第二列中找到这个声母的行,以便引用本行相关数据。 Dim value() As String = {"Q","K","D","T","J","G","Y","F","S","Sh","R","L","N","B","P","W","M","Z","Zh","H","C","Ch","X"} Dim v1 As String Dim idx As Integer Dim nList As new List(of String) Dim vs As new List(of String) vs.AddRange(Value) idx = Rand.Next(0,vs.Count-1) v1 = vs(idx) msgbox(v1) Dim dr As DataRow \'dr = DataTables("表A").Find("[第二列] Like \'%J%\'") \'正确运行 \'dr = DataTables("表A").Find("[第二列] Like \'% & vs(Rand.Next(0,vs.Count-1)) & %\'") \'不报错,但也得不到正确结果. dr = DataTables("表A").Find("[第二列] Like \'% & v1 & %\'") \'不报错,但也得不到正确结果. If dr IsNot Nothing Then Dim wz As Integer = Tables("表A").FindRow(dr) If wz >= 0 Then Tables("表A").Position = wz dr("第四列") = 999 End If End If |
||||
-- 作者:旭日生 -- 发布时间:2019/5/3 16:04:00 -- 修改成这样,可以了: dr = DataTables("全脑汉码声韵数字映射规则表").Find("第二列 like " & "\'%" & v1 & "%\' " & " Or 第三列 Like " & "\'%" & v1 & "%\' ") |