diff --git a/packages/basic.gblib/services/GBVMService.ts b/packages/basic.gblib/services/GBVMService.ts index b8e40917..102b8fd0 100644 --- a/packages/basic.gblib/services/GBVMService.ts +++ b/packages/basic.gblib/services/GBVMService.ts @@ -220,6 +220,18 @@ export class GBVMService extends GBService { return `${$2} = hear()`; }); + code = code.replace(/(\w)\s*\=\s*find\s*(.*)\s*or talk\s*(.*)/gi, ($0, $1, $2, $3) => { + return `${$1} = sys().find(${$2})\n + if (!${$1}) { + if (resolve){ + resolve(); + } + talk (${$3})\n; + return; + } + `; + }); + code = code.replace(/(\w)\s*\=\s*find\s*(.*)/gi, ($0, $1, $2, $3) => { return `${$1} = sys().find(${$2})\n`; }); diff --git a/packages/basic.gblib/services/SystemKeywords.ts b/packages/basic.gblib/services/SystemKeywords.ts index 06a2228c..a36c772b 100644 --- a/packages/basic.gblib/services/SystemKeywords.ts +++ b/packages/basic.gblib/services/SystemKeywords.ts @@ -265,6 +265,24 @@ export class SystemKeywords { return val; } + /** + * Finds a value or multi-value results in a tabular file. + * + * @example + * + * rows = FIND "file.xlsx", "A2=active" WHEN NOT FOUND TALK "" + * i = 1 + * do while i < ubound(row) + * row = rows[i] + * send sms to "+" + row.mobile, "Hello " + row.namee + "! " + * loop + * + */ + public async findWithExit(file: string, talk, ...args): Promise { + this.find(file, args); + } + + /** * Finds a value or multi-value results in a tabular file. *