威纶通官方论坛

配方数据库搜索/字符串比较

[复制链接]
发表于 昨天 09:05 | 显示全部楼层 |阅读模式
macro_command main()

char ori[20], search[20]
int start = 0
int count = 0
bool result = false

//获取配方数量
GetData(count, "Local HMI", RECIPE, "canshu.Count")
//获取搜索关键词
GetData(search[0], "Local HMI", LW, 10, 20)

for start = 0 to count - 1 step 1
        SetData(start,"Local HMI", RECIPE, "canshu.Selection")
        //获取当前编号的配方数据
        result = RecipeGetData(ori[0], "canshu.mingcheng", start)
        //比较字符串
        result = StringCompareNoCase(search[0], ori[0])
        if (result) then
                break
        end if
next start
       
end macro_command

这个是我的宏指令,我想实现配方数据库的搜索功能,但StringCompareNoCase函数只比较了search, ori这两个字符串的第一个字符,比如两个字符一个是abc,一个是ac,返回结果是true(因为开头都是a),请问有什么解决方法吗?
 楼主| 发表于 昨天 09:39 | 显示全部楼层
换了个函数重新写了一下,还是一样的情况,求指点
macro_command main()

char ori[20], search[20]
char res1[26] = "搜索完成,已找到搜索结果!"
char res2[26] = "搜索完成,未找到搜索结果!"

int start = 0
int count = 0
bool result = false

//获取搜索关键词
GetData(search[0], "Local HMI", LW, 10, 20)
//获取配方数量
RecipeQuery("SELECT * FROM canshu", count)

//循环对比每笔数据的mingcheng与输入是否相同
for start = 0 to count - 1
        result = RecipeQueryGetData(ori[0], "canshu.mingcheng", start)
       
        if(search[0] == ori[0])then
                SetData(res1[0], "Local HMI", LW, 20, 26)
                //选中当前位置
                SetData(start, "Local HMI", RECIPE, "canshu.Selection")
                break
        else if start == count - 1 then
                SetData(res2[0], "Local HMI", LW, 20, 26)
        end if
next start

end macro_command
发表于 昨天 13:36 | 显示全部楼层
if(search[0] == ori[0])这一句改一下
if(search[0] == ori[0] and search[1] == ori[1] and search[2] == ori[2])
一直写到你需要的地址位置。
 楼主| 发表于 昨天 14:10 | 显示全部楼层
pcsms_BsKJa84Z 发表于 2024-10-21 13:36
if(search[0] == ori[0])这一句改一下
if(search[0] == ori[0] and search[1] == ori[1] and search[2] = ...

对,我也发现它是一个地址只有一个字符,这样写的话运行起来会不会很慢,我到时候配方可能得有上千个
 楼主| 发表于 昨天 15:02 | 显示全部楼层
已找到解决方法,RecipeQuery函数可以直接查询与搜索值相同的配方的笔数,再用RecipeQueryGetRecordID获取前面获取的笔数的实际的列编号。这样可以不用对比字符串。
您需要登录后才可以发帖 登录 | 注册

本版积分规则

回复帖子

Archiver|小黑屋|威纶通官网 ( 粤ICP备06054553号 )

GMT+8, 2024-10-22 20:20

Powered by Discuz! X3.4

© 2001-2023 Comsenz Inc.

快速回复 返回顶部 返回列表