From 584ed55f5c548848443afb7c7d5eb260bbfda41a Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Tue, 18 May 2021 14:22:10 -0300 Subject: [PATCH] fix(basic.gblib): FIND now has an in-line not found message option. --- packages/basic.gblib/services/GBVMService.ts | 12 ++++++++++++ .../basic.gblib/services/SystemKeywords.ts | 18 ++++++++++++++++++ 2 files changed, 30 insertions(+) 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. *