From 330858b937e5bf108428246838d0ebcf635ff8bc Mon Sep 17 00:00:00 2001 From: losgehts Date: Sat, 28 Jul 2018 15:30:03 +0200 Subject: [PATCH 1/3] added stepsize to for-loop --- vb2js.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/vb2js.js b/vb2js.js index 618345c..bff433b 100644 --- a/vb2js.js +++ b/vb2js.js @@ -92,9 +92,19 @@ function vbsTojs(vbs){ a[i]=a[i].replace(counter,"").replace(from,"").replace(/\bTO\b/i,""); to = a[i].match(/\s*[\w\(\)]+\s*/)[0]; to=to.replace(/=/,"").replace(/\s+/g,""); - a[i] = "for(" + counter + "=" + from + "; " + counter + "<=" + to + "; " + counter + "++){" + // stepsize + if(a[i].search(/\bSTEP\b\s+/i)==-1) a[i] = a[i] + " STEP 1"; + steps = a[i].match(/\bSTEP\b\s*(-?)([*+-\/\s\w\(\)]*)$/i); + steps[1] = steps[1].replace(/\s{2,}/g,"")=="" ? "+" : "-"; + cmpop = (steps[1] == "+") ? "<=" : ">="; + if (steps[2] == "1") { + stepsize = counter + steps[1] + steps[1]; + }else{ + stepsize = (counter + " = " + counter + " " + steps[1] + " " + steps[2]).replace(/\s{2,}/g," "); + } + + a[i] = "for(" + counter + "=" + from + "; " + counter + cmpop + to + "; " + stepsize + "){"; - //NEXT }else if(a[i].search(/^NEXT\b/i)>-1){ a[i] = "}"; From e681764aea76b6016d732a0cad13f819ae3f6813 Mon Sep 17 00:00:00 2001 From: losgehts Date: Sat, 28 Jul 2018 19:35:42 +0200 Subject: [PATCH 2/3] better regex pattern for whitespaces --- vb2js.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vb2js.js b/vb2js.js index bff433b..303cb79 100644 --- a/vb2js.js +++ b/vb2js.js @@ -95,12 +95,12 @@ function vbsTojs(vbs){ // stepsize if(a[i].search(/\bSTEP\b\s+/i)==-1) a[i] = a[i] + " STEP 1"; steps = a[i].match(/\bSTEP\b\s*(-?)([*+-\/\s\w\(\)]*)$/i); - steps[1] = steps[1].replace(/\s{2,}/g,"")=="" ? "+" : "-"; + steps[1] = steps[1].replace(/\s*/g,"")=="" ? "+" : "-"; cmpop = (steps[1] == "+") ? "<=" : ">="; if (steps[2] == "1") { stepsize = counter + steps[1] + steps[1]; }else{ - stepsize = (counter + " = " + counter + " " + steps[1] + " " + steps[2]).replace(/\s{2,}/g," "); + stepsize = (counter + " = " + counter + " " + steps[1] + " " + steps[2]).replace(/\s*/g," "); } a[i] = "for(" + counter + "=" + from + "; " + counter + cmpop + to + "; " + stepsize + "){"; From a0a06d60f74a8f4a670ba00b95a5c63804826312 Mon Sep 17 00:00:00 2001 From: losgehts Date: Sat, 28 Jul 2018 21:57:29 +0200 Subject: [PATCH 3/3] update readme concerning stepsize in for loops --- README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/README.md b/README.md index 4525980..763377c 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Currently, this translator works with: * Basic IF THEN Statements * SELECT CASE Statements * Most Comparison Operators -* Basic FOR x TO y Loops +* Basic FOR x TO y STEP z Loops * Most variations of DO LOOPS * Basic MSGBOX calls @@ -24,7 +24,6 @@ This tool currently does NOT accurately translate * Built in VBA functions * References to Office Objects * WITH Statements -* STEP Constructs in FOR Loops * FOR EACH Loops (in fact these cause the tool to return nothing at all. I'm still working out why that is) I offer the source code up to anyone interested in helping make enhancements to this tool in order to develop a more robust utility for the VBA community.