Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/474.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VBA JavaScript对象没有';不支持此属性或方法_Javascript_Vba_Scriptcontrol - Fatal编程技术网

VBA JavaScript对象没有';不支持此属性或方法

VBA JavaScript对象没有';不支持此属性或方法,javascript,vba,scriptcontrol,Javascript,Vba,Scriptcontrol,我正在尝试从中获取文本统计功能 在Excel中工作 我已经缩小了JavaScript代码以缩短连接 Function Text_Statistics1(textString As String) Dim code As String code = "function text_stats(teststringtoprocess){(function(e){function t(e){var t=['li','p','h1','h2','h3','h4','h5','h6','dd'];t.f

我正在尝试从中获取文本统计功能

在Excel中工作

我已经缩小了JavaScript代码以缩短连接

Function Text_Statistics1(textString As String)

Dim code As String

code = "function text_stats(teststringtoprocess){(function(e){function t(e){var t=['li','p','h1','h2','h3','h4','h5','h6','dd'];t.forEach(function(t){e=e.replace('</'+t+'>','.')});e=e.replace(/<[^>]+>/g,'').replace(/[,:;()\-]/,' ').replace(/[\.!?]/,'.').replace(/^\s+/,'').replace(/[ ]*(\n|\r\n|\r)[ ]*/,' ').replace(/([\.])[\. ]+/,'.').replace(/[ ]*([\.])/,'. ').replace(/\s+/,' ').replace(/\s+$/,'');e+='.';return e}function r(e){return new n(e)}var n=function(n){this.text=n?t(n):this.text};n.prototype.fleschKincaidReadingEase=function(e){e=e?t(e):this.text;return Math.round((206.835-1.015*this.averageWordsPerSentence(e)-84.6*this.averageSyllablesPerWord(e))*10)/10};n.prototype.fleschKincaidGradeLevel=function(e){e=e?t(e):this.text;return Math.round((.39*this.averageWordsPerSentence(e)+11.8*this.averageSyllablesPerWord(e)-15.59)*10)/10};n.prototype.gunningFogScore=function(e){e=e?t(e):this.text;"
code = code + "return Math.round((this.averageWordsPerSentence(e)+this.percentageWordsWithThreeSyllables(e,false))*.4*10)/10};n.prototype.colemanLiauIndex=function(e){e=e?t(e):this.text;return Math.round((5.89*(this.letterCount(e)/this.wordCount(e))-.3*(this.sentenceCount(e)/this.wordCount(e))-15.8)*10)/10};n.prototype.smogIndex=function(e){e=e?t(e):this.text;return Math.round(1.043*Math.sqrt(this.wordsWithThreeSyllables(e)*(30/this.sentenceCount(e))+3.1291)*10)/10};n.prototype.automatedReadabilityIndex=function(e){e=e?t(e):this.text;"
code = code + "return Math.round((4.71*(this.letterCount(e)/this.wordCount(e))+.5*(this.wordCount(e)/this.sentenceCount(e))-21.43)*10)/10};n.prototype.textLength=function(e){e=e?t(e):this.text;return e.length};n.prototype.letterCount=function(e){e=e?t(e):this.text;e=e.replace(/[^a-z]+/ig,'');return e.length};n.prototype.sentenceCount=function(e){e=e?t(e):this.text;return e.replace(/[^\.!?]/g,'').length||1};n.prototype.wordCount=function(e){e=e?t(e):this.text;return e.split(/[^a-z0-9]+/i).length||1};n.prototype.averageWordsPerSentence=function(e){e=e?t(e):this.text;"
code = code + "return this.wordCount(e)/this.sentenceCount(e)};n.prototype.averageSyllablesPerWord=function(e){e=e?t(e):this.text;var n=0,r=this.wordCount(e),i=this;e.split(/\s+/).forEach(function(e){n+=i.syllableCount(e)});return(n||1)/(r||1)};n.prototype.wordsWithThreeSyllables=function(e,n){e=e?t(e):this.text;var r=0,i=this;n=n===false?false:true;e.split(/\s+/).forEach(function(e){if(!e.match(/^[A-Z]/)||n){if(i.syllableCount(e)>2)r++}});return r};n.prototype.percentageWordsWithThreeSyllables=function(e,n){e=e?t(e):this.text;return this.wordsWithThreeSyllables(e,n)/this.wordCount(e)*100};n.prototype.syllableCount=function(e){var t=0,n=0,r=0;e=e.toLowerCase().replace(/[^a-z]/g,'');var i={simile:3,forever:3,shoreline:2};if(i.hasOwnProperty(e))return i[e];var s=[/cial/,/tia/,/cius/,/cious/,/giu/,/ion/,/iou/,/sia$/,/[^aeiuoyt]{2,}ed$/,/.ely$/,/[cg]h?e[rsd]?$/,/rved?$/,/[aeiouy][dt]es?$/,/[aeiouy][^aeiouydt]e[rsd]?$/,/^[dr]e[aeiou][^aeiou]+$/,/[aeiouy]rse$/];"
code = code + "var o=[/ia/,/riet/,/dien/,/iu/,/io/,/ii/,/[aeiouym]bl$/,/[aeiou]{3}/,/^mc/,/ism$/,/([^aeiouy])\1l$/,/[^l]lien/,/^coa[dglx]./,/[^gq]ua[^auieo]/,/dnt$/,/uity$/,/ie(r|st)$/];var u=[/^un/,/^fore/,/ly$/,/less$/,/ful$/,/ers?$/,/ings?$/];u.forEach(function(t){if(e.match(t)){e=e.replace(t,'');n++}});r=e.split(/[^aeiouy]+/ig).filter(function(e){return!!e.replace(/\s+/ig,'').length}).length;t=r+n;s.forEach(function(n){if(e.match(n))t--});o.forEach(function(n){if(e.match(n))t++});return t||1};typeof module!='undefined'&&module.exports?module.exports=r:typeof define!='undefined'?define('textstatistics',[],function(){return r}):e.textstatistics=r})(this);"

'code = code + " return textstatistics(s).fleschKincaidReadingEase();" & _
'"return stat.fleschKincaidReadingEase();" & _

code = code + "return textstatistics(teststringtoprocess).fleschKincaidReadingEase();}"
'code = code + "return textstatistics(teststringtoprocess);}"



Dim o As New ScriptControl
    o.Language = "JScript"
    With o
        .AddCode code
        Text_Statistics1 = .Run("text_stats", textString)
    End With

End Function
函数文本\u统计1(文本字符串作为字符串)
将代码设置为字符串
“功能(e)函数(e)e=e.取代(e)e.e.取代(e)替换(e.e.替换(/)))。更换(/[,,,,()()(),,,,'h3,,,'h3,,'h3','h4','h4','h4',“h4',,,'h4',,'h4',,,'h4',,,'h4',,,'h4',,,,'h4',,'h4',,,,,'h5',,'h5',,,,'h5',,,'h5',,,,'h5',,,,,,'h5',,,,'h5',,,,,,,,,,,,,,,,'h5',,,,,,,,,,,,'h5',,,,,,,,,,,,,)[\.]+/,'.')。替换(/[]*([\.])/替换(/\s+/,”)。替换(/\s+$/,”);e+=”;返回e}函数r(e){return new n(e)}var n=function(n){this.text=n?t(n):this.text};n.prototype.fleschkincaidardingease=function(e){e=e?t(e):this.text;return Math.round((206.835-1.015*this.averageWordsPerContent(e)-84.6.averageLessPerword)/10};n.prototype.fleschKincaidGradeLevel=function(e){e=e?t(e):this.text;return Math.round(.39*this.averagewordsperscontence(e)+11.8*this.average音节perword(e)-15.59)*10)/10};n.prototype.gunningFogScore=function(e){e=e=e?t(e):this.text
code=code+“返回数学.round((this.averageWordsPersence(e)+this.percentageWordswithThree音节(e,false))*.4*10)/10};n.prototype.colemanLiauIndex=function(e){e=e?t(e):this.text;返回数学.round((5.89*(this.letterCount(e)/this.wordCount(e))-.3*(this.sentenceCount(e)/this.wordCount(e))-15.8)*-10)/10};n.prototype.smogin=function(e){(e) :this.text;return Math.round(1.043*Math.sqrt(this.words有三个音节(e)*(30/this.sentenceCount(e))+3.1291)*10)/10};n.prototype.automatedReadabilityIndex=函数(e){e=e?t(e):this.text
代码=代码+“返回数学.round((4.71*(this.letterCount(e)/this.wordCount(e))+.5*(this.wordCount(e)/this.sentenceCount(e))-21.43)*10)/10};n.prototype.textLength=函数(e){e=e?t(e):this.text;返回e.length};n.prototype.letterCount=函数(e){e=e=e?t(e):this.text;e=e.text;e=e.replace.replace替换(/^a-z]+/ig,”);返回e.length};n.prototype=e{e=e?t(e):this.text;返回e.replace(/[^.!?]/g.).length | | 1};n.prototype.wordCount=function(e){e=e?t(e):this.text;返回e.split(/[^a-z0-9]+//i).length | | 1};n.prototype.averageWordsPerSentence=function(e){e=e?t(e):this.text;”
code=code+“返回this.wordCount(e)/this.sentenceCount(e)};n.prototype.averageSyllelesPerword=function(e){e=e?t(e):this.text;var n=0,r=this.wordCount(e),i=this;e.split(/\s+/).forEach(function(e){n+=i.syllelecount(e)});返回(n | 1)/(r | 1)};n.prototype.wordswithes=function(e,n,n){t=e):this.text;var r=0,i=this;n=n==false?false:true;e.split(/\s++/).forEach(函数(e){if(!e.match(/^[A-Z]/)| n){if(i.syllelecount(e)>2.r++}});返回r};n.prototype.percentageWordswiththThree音节=函数(e,n){e=e?t(e):this.text;返回this.WordswithThree音节(e,n)/this.wordCount Three音节数(e)*Thrototype=100(一)var i={3,永久:3,永久:3,海岸线:2};若(一拥有拥有拥有财产的财产)3,海岸线:2};若(一拥有拥有拥有财产的财产)3,海岸线:2};若(一拥有拥有财产的财产(e))返回i[e”,r=0,r=0;r=0;r=0;r=0;e;e;r=e;r=e;r=e;r=e.t;r=e;r=s=[社会///社会/////,/社会/,/cius/,/国家/,/国家/,/,/国家/年,/iou/,/iou/,/iou/,/iou,/iou/,/州/年/年/年/年/年/年/年/年/年/年/年/年/年/年/月/年/年/年/年/月/年/年/新新亚/年/e[rsd]?$/,/^[dr]e[aeiou][^aeiou]+$/,/[aeiouy]rse$/];”
第二/二/二/二/二/二/二/二/二/二/二/二/二/二/二/二/二/二/二/二/二/二/二/二/二/二/二/二/二/二/三/三/三/三/三/三/三/三/三/三/五/三/三/三/三/三/三/三/三/三/三/三/三/三/三/三/三/三/三/三/三/三/三/三/三/三/三/三/三/三/三/三/三/三/三/三/三/三/三/三/三/三/三/三/五/三/五/三/三/三/五/五/三/五/三/五/三/三/三/五/五/五/五/三/三/三/五/五/五/三/五/五/五/五/五/五/五/五/五/五/Ach(函数(t){if(e.match(t)){e=e.replace(t',);n++}});r=e.split(/[^aeiouy]+/ig)。过滤器(函数(e) {return!!e.replace(/\s++/ig,).length}.length;t=r+n;s.forEach(函数n{if(e.match(n))t--});o.forEach(函数n{if(e.match(n))t++});return t | 1};typeof模块!='undefined'&&module exports?module exports.exports=r:typeof defined!='undefined'='defined''defined'?defined'?defined('textstatistics',[],function(){return r}):e.textstatistics=r})(this);”
'code=code+“return textstatistics.fleschkincaidardingease();”和_
“返回统计FleschkincaiFeardingEase();”&_
code=code+“返回textstatistics(teststringtoprocess).fleschKincaidReadingEase();}”
'code=code+“返回文本统计信息(teststringtoprocess);}”
Dim o作为新的脚本控件
o、 Language=“JScript”
与o
.AddCode代码
Text\u Statistics1=.Run(“Text\u stats”,textString)
以
端函数
我得到的对象不支持此属性或方法-我认为这是由于文本统计信息的实例化

我是否需要将javascript转换为一组函数

更新: 使用eval的方法略有不同

Function Text_Stat(textString As String, textstat As String)

Dim code As String

code = "(function(e){function t(e){var t=['li','p','h1','h2','h3','h4','h5','h6','dd'];t.forEach(function(t){e=e.replace('</'+t+'>','.')});e=e.replace(/<[^>]+>/g,'').replace(/[,:;()\-]/,' ').replace(/[\.!?]/,'.').replace(/^\s+/,'').replace(/[ ]*(\n|\r\n|\r)[ ]*/,' ').replace(/([\.])[\. ]+/,'.').replace(/[ ]*([\.])/,'. ').replace(/\s+/,' ').replace(/\s+$/,'');e+='.';return e}function r(e){return new n(e)}var n=function(n){this.text=n?t(n):this.text};n.prototype.fleschKincaidReadingEase=function(e){e=e?t(e):this.text;return Math.round((206.835-1.015*this.averageWordsPerSentence(e)-84.6*this.averageSyllablesPerWord(e))*10)/10};n.prototype.fleschKincaidGradeLevel=function(e){e=e?t(e):this.text;" & _
"return Math.round((.39*this.averageWordsPerSentence(e)+11.8*this.averageSyllablesPerWord(e)-15.59)*10)/10};n.prototype.gunningFogScore=function(e){e=e?t(e):this.text;return Math.round((this.averageWordsPerSentence(e)+this.percentageWordsWithThreeSyllables(e,false))*.4*10)/10};n.prototype.colemanLiauIndex=function(e){e=e?t(e):this.text;return Math.round((5.89*(this.letterCount(e)/this.wordCount(e))-.3*(this.sentenceCount(e)/this.wordCount(e))-15.8)*10)/10};n.prototype.smogIndex=function(e){e=e?t(e):this.text;return Math.round(1.043*Math.sqrt(this.wordsWithThreeSyllables(e)*(30/this.sentenceCount(e))+3.1291)*10)/10};n.prototype.automatedReadabilityIndex=function(e){e=e?t(e):this.text;" & _
"return Math.round((4.71*(this.letterCount(e)/this.wordCount(e))+.5*(this.wordCount(e)/this.sentenceCount(e))-21.43)*10)/10};n.prototype.textLength=function(e){e=e?t(e):this.text;return e.length};n.prototype.letterCount=function(e){e=e?t(e):this.text;e=e.replace(/[^a-z]+/ig,'');return e.length};n.prototype.sentenceCount=function(e){e=e?t(e):this.text;return e.replace(/[^\.!?]/g,'').length||1};n.prototype.wordCount=function(e){e=e?t(e):this.text;return e.split(/[^a-z0-9]+/i).length||1};n.prototype.averageWordsPerSentence=function(e){e=e?t(e):this.text;return this.wordCount(e)/this.sentenceCount(e)};n.prototype.averageSyllablesPerWord=function(e){e=e?t(e):this.text;var n=0,r=this.wordCount(e),i=this;e.split(/\s+/).forEach(function(e){n+=i.syllableCount(e)});return(n||1)/(r||1)};n.prototype.wordsWithThreeSyllables=function(e,n){e=e?t(e):this.text;" & _
"var r=0,i=this;n=n===false?false:true;e.split(/\s+/).forEach(function(e){if(!e.match(/^[A-Z]/)||n){if(i.syllableCount(e)>2)r++}});return r};n.prototype.percentageWordsWithThreeSyllables=function(e,n){e=e?t(e):this.text;" & _
"return this.wordsWithThreeSyllables(e,n)/this.wordCount(e)*100};n.prototype.syllableCount=function(e){var t=0,n=0,r=0;e=e.toLowerCase().replace(/[^a-z]/g,'');var i={simile:3,forever:3,shoreline:2};if(i.hasOwnProperty(e))return i[e];var s=[/cial/,/tia/,/cius/,/cious/,/giu/,/ion/,/iou/,/sia$/,/[^aeiuoyt]{2,}ed$/,/.ely$/,/[cg]h?e[rsd]?$/,/rved?$/,/[aeiouy][dt]es?$/,/[aeiouy][^aeiouydt]e[rsd]?$/,/^[dr]e[aeiou][^aeiou]+$/,/[aeiouy]rse$/];var o=[/ia/,/riet/,/dien/,/iu/,/io/,/ii/,/[aeiouym]bl$/,/[aeiou]{3}/,/^mc/,/ism$/,/([^aeiouy])\1l$/,/[^l]lien/,/^coa[dglx]./,/[^gq]ua[^auieo]/,/dnt$/,/uity$/,/ie(r|st)$/];" & _
"var u=[/^un/,/^fore/,/ly$/,/less$/,/ful$/,/ers?$/,/ings?$/];u.forEach(function(t){if(e.match(t)){e=e.replace(t,'');n++}});r=e.split(/[^aeiouy]+/ig).filter(function(e){return!!e.replace(/\s+/ig,'').length}).length;t=r+n;s.forEach(function(n){if(e.match(n))t--});o.forEach(function(n){if(e.match(n))t++});return t||1};typeof module!='undefined'&&module.exports?module.exports=r:typeof define!='undefined'?define('textstatistics',[],function(){return r}):e.textstatistics=r})(this);" & _
"var stat = new textstatistics('Your text here');alert(stat.sentenceCount('This. dfgdfg. is. a. long. sentence.'));"


Dim o As New ScriptControl
    o.Language = "JScript"
    With o
        .AllowUI = True
        .AddCode code
        .Eval "stat.sentenceCount('This. dfgdfg. is. a. long. sentence.')"
        'result = .Eval(code)
        'Debug.Print .Eval("'Hello World'.substring(1, 4);")
        'result = .Eval(result)
        'Text_Stat = .Run(result)
    End With

End Function
函数Text\u Stat(textString作为字符串,textstat作为字符串)
将代码设置为字符串
(函数(e)(e)(函数(e)(e)(e)(e)(函数(t)(t)(t)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(t)(t)(t)(t)(t)(t)(t)(e)(t)(t)(t)(e)(t)(t)(t)(t)(t)(t)(t)(t)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(e)(替换)(替换)(替换)(替换)(替换)(替换)(替换)(替换)(替换)(替换)(替换)(替换)(替换)(替换)(替换)(替换)(替换)(替换)(替换)(替换)(以以以以以以以以以以以,,,,“(,“(,,,“(,“(,“(,,“(,“(,“(,(/[]*([\.]/,”)。替换(/\s+/,“”)。替换(/\s+$/,“”)返回函数r(e){return new n(e)}var n=function(n){this.text=n?t(n):this.text};n.prototype.fleschkincai恐惧症=function(e){e=e?t(e):this.text;return Math.round((206.835-1.015*this.averageWordsPerSentence(e)-84.6*this.averagementallesspectlessperword(e))/10};n.prototype.fleschkincaidgrade=function=e?t=e){_
“return Math.round(.39*this.averageWordsPerSentence(e)+11.8*this.average音节perword(e)-15.59)*10)/10};n.prototype.gunningFogScore=function(e){e=e?t(e):this.text;return Math.round((this.averageWordsPerSentence(e)+this.percentagewords(e)(e,false))*.4*10)/10};n.prototype.colemanlianliauindex=function(e){=e=e=e?t(e):this.text;return Math.round((5.89*(this.letterCount(e)/this.wordCount(e))-.3*(this.sentenceCount(e)/this.wordCount(e))-15.8)*10)/10};n.prototype.smogIndex=函数(e){e=e?t(e):this.text;return Math.round(1.043*Math.sqrt(this.w
Function Text_Statistics(statType As Integer, textString As String)

Dim wc, sc As Integer
Dim s1, s2, code As String
Dim oTextStats As Object
Dim o As New ScriptControl

code = "function cleanText(e){var t=['li','p','h1','h2','h3','h4','h5','h6','dd'];t.forEach(function(t){e=e.replace('</'+t+'>','.')});e=e.replace(/<[^>]+>/g,'').replace(/[,:;()\-]/,' ').replace(/[\.!?]/,'.').replace(/^\s+/,'').replace(/[ ]*(\n|\r\n|\r)[ ]*/,' ').replace(/([\.])[\. ]+/,'.').replace(/[ ]*([\.])/,'. ').replace(/\s+/,' ').replace(/\s+$/,'');e+='.';return e}function textStatistics(e){return new TextStatistics(e)}if(!Array.prototype.forEach){Array.prototype.forEach=function(e){var t=this.length;" & _
"if(typeof e!='function')throw new TypeError;var n=arguments[1];for(var r=0;r<t;r++){if(r in this)e.call(n,this[r],r,this)}}}if(!Array.prototype.filter){Array.prototype.filter=function(e){'use strict';if(this===void 0||this===null){throw new TypeError}var t=Object(this);var n=t.length>>>0;if(typeof e!=='function'){throw new TypeError}var r=[];var i=arguments.length>=2?arguments[1]:void 0;for(var s=0;s<n;s++){if(s in t){var o=t[s];if(e.call(i,o,s,t)){r.push(o)}}}return r}}var TextStatistics=function(t){this.text=t?cleanText(t):this.text};TextStatistics.prototype.fleschKincaidReadingEase=function(e){e=e?cleanText(e):this.text;return Math.round((206.835-1.015*this.averageWordsPerSentence(e)-84.6*this.averageSyllablesPerWord(e))*10)/10};TextStatistics.prototype.fleschKincaidGradeLevel=function(e){e=e?cleanText(e):this.text;" & _
"return Math.round((.39*this.averageWordsPerSentence(e)+11.8*this.averageSyllablesPerWord(e)-15.59)*10)/10};TextStatistics.prototype.gunningFogScore=function(e){e=e?cleanText(e):this.text;return Math.round((this.averageWordsPerSentence(e)+this.percentageWordsWithThreeSyllables(e,false))*.4*10)/10};TextStatistics.prototype.colemanLiauIndex=function(e){e=e?cleanText(e):this.text;return Math.round((5.89*(this.letterCount(e)/this.wordCount(e))-.3*(this.sentenceCount(e)/this.wordCount(e))-15.8)*10)/10};" & _
"TextStatistics.prototype.smogIndex=function(e){e=e?cleanText(e):this.text;return Math.round(1.043*Math.sqrt(this.wordsWithThreeSyllables(e)*(30/this.sentenceCount(e))+3.1291)*10)/10};TextStatistics.prototype.automatedReadabilityIndex=function(e){e=e?cleanText(e):this.text;return Math.round((4.71*(this.letterCount(e)/this.wordCount(e))+.5*(this.wordCount(e)/this.sentenceCount(e))-21.43)*10)/10};TextStatistics.prototype.textLength=function(e){e=e?cleanText(e):this.text;return e.length};TextStatistics.prototype.letterCount=function(e){e=e?cleanText(e):this.text;e=e.replace(/[^a-z]+/ig,'');return e.length};TextStatistics.prototype.sentenceCount=function(e){e=e?cleanText(e):this.text;" & _
"return e.replace(/[^\.!?]/g,'').length||1};TextStatistics.prototype.wordCount=function(e){e=e?cleanText(e):this.text;return e.split(/[^a-z0-9]+/i).length||1};TextStatistics.prototype.averageWordsPerSentence=function(e){e=e?cleanText(e):this.text;return this.wordCount(e)/this.sentenceCount(e)};TextStatistics.prototype.averageSyllablesPerWord=function(e){e=e?cleanText(e):this.text;" & _
"var t=0,n=this.wordCount(e),r=this;e.split(/\s+/).forEach(function(e){t+=r.syllableCount(e)});return(t||1)/(n||1)};TextStatistics.prototype.wordsWithThreeSyllables=function(e,t){e=e?cleanText(e):this.text;var n=0,r=this;t=t===false?false:true;e.split(/\s+/).forEach(function(e){if(!e.match(/^[A-Z]/)||t){if(r.syllableCount(e)>2)n++}});return n};TextStatistics.prototype.percentageWordsWithThreeSyllables=function(e,t){e=e?cleanText(e):this.text;return this.wordsWithThreeSyllables(e,t)/this.wordCount(e)*100};" & _
"TextStatistics.prototype.syllableCount=function(e){var t=0,n=0,r=0;e=e.toLowerCase().replace(/[^a-z]/g,'');var i={simile:3,forever:3,shoreline:2};if(i.hasOwnProperty(e))return i[e];var s=[/cial/,/tia/,/cius/,/cious/,/giu/,/ion/,/iou/,/sia$/,/[^aeiuoyt]{2,}ed$/,/.ely$/,/[cg]h?e[rsd]?$/,/rved?$/,/[aeiouy][dt]es?$/,/[aeiouy][^aeiouydt]e[rsd]?$/,/^[dr]e[aeiou][^aeiou]+$/,/[aeiouy]rse$/];var o=[/ia/,/riet/,/dien/,/iu/,/io/,/ii/,/[aeiouym]bl$/,/[aeiou]{3}/,/^mc/,/ism$/,/([^aeiouy])\1l$/,/[^l]lien/,/^coa[dglx]./,/[^gq]ua[^auieo]/,/dnt$/,/uity$/,/ie(r|st)$/];" & _
"var u=[/^un/,/^fore/,/ly$/,/less$/,/ful$/,/ers?$/,/ings?$/];u.forEach(function(t){if(e.match(t)){e=e.replace(t,'');n++}});r=e.split(/[^aeiouy]+/ig).filter(function(e){return!!e.replace(/\s+/ig,'').length}).length;t=r+n;s.forEach(function(n){if(e.match(n))t--});o.forEach(function(n){if(e.match(n))t++});return t||1}"

With o
    .Language = "JScript"
    .AddCode code
    ' Create a TextStatistics object initially with no text.
    ' textStatistics is a function that creates TextStatistics objects
    Set oTextStats = .Eval("textStatistics()")

    ' Now simply call TextStatistics methods directly
    wc = oTextStats.averageWordsPerSentence(textString)
    sc = oTextStats.syllableCount(textString)

    ' Alternatively you can create a TextStatistics object with the text
    ' and call the methods with a blank string to return the values
    ' for the string passed in the constructor

    'Set oTextStats = .Eval("textStatistics('" + textString + "')")
    'wc = oTextStats.wordCount("")
    'sc = oTextStats.sentenceCount("")


    Select Case statType
    Case 1
        Text_Statistics = oTextStats.wordCount(textString)
    Case 2
        Text_Statistics = oTextStats.sentenceCount(textString)
    Case 3
        Text_Statistics = oTextStats.fleschKincaidReadingEase(textString)
    Case 4
        Text_Statistics = oTextStats.fleschKincaidGradeLevel(textString)
    Case 5
        Text_Statistics = oTextStats.gunningFogScore(textString)
    Case 6
        Text_Statistics = oTextStats.colemanLiauIndex(textString)
    Case 7
        Text_Statistics = oTextStats.smogIndex(textString)
    Case 8
        Text_Statistics = oTextStats.automatedReadabilityIndex(textString)
    Case 9
        Text_Statistics = oTextStats.textLength(textString)
   Case 10
        Text_Statistics = oTextStats.letterCount(textString)
   Case 11
        Text_Statistics = oTextStats.averageWordsPerSentence(textString)
   Case 12
        Text_Statistics = oTextStats.averageSyllablesPerWord(textString)

End Select

End With
End Function
(function(glob) {
(typeof module != "undefined" && module.exports) ? (module.exports = textStatistics) : (typeof define != "undefined" ? (define("textstatistics", [], function() { return textStatistics; })) : (glob.textstatistics = textStatistics));
})(this);
if (!Array.prototype.forEach) {
    Array.prototype.forEach = function (fun /*, thisp*/ ) {
        var len = this.length;
        if (typeof fun != 'function') throw new TypeError();

        var thisp = arguments[1];
        for (var i = 0; i < len; i++) {
            if (i in this) fun.call(thisp, this[i], i, this);
        }
    };
}
if (!Array.prototype.filter) {
  Array.prototype.filter = function(fun/*, thisArg*/) {
    'use strict';

    if (this === void 0 || this === null) {
      throw new TypeError();
    }

    var t = Object(this);
    var len = t.length >>> 0;
    if (typeof fun !== 'function') {
      throw new TypeError();
    }

    var res = [];
    var thisArg = arguments.length >= 2 ? arguments[1] : void 0;
    for (var i = 0; i < len; i++) {
      if (i in t) {
        var val = t[i];

        // NOTE: Technically this should Object.defineProperty at
        //       the next index, as push can be affected by
        //       properties on Object.prototype and Array.prototype.
        //       But that method's new, and collisions should be
        //       rare, so use the more-compatible alternative.
        if (fun.call(thisArg, val, i, t)) {
          res.push(val);
        }
      }
    }

    return res;
  };
}
if (!Array.prototype.forEach) {
    Array.prototype.forEach = function (fun /*, thisp*/ ) {
        var len = this.length;
        if (typeof fun != 'function') throw new TypeError();

        var thisp = arguments[1];
        for (var i = 0; i < len; i++) {
            if (i in this) fun.call(thisp, this[i], i, this);
        }
    };
}

if (!Array.prototype.filter) {
  Array.prototype.filter = function(fun/*, thisArg*/) {
    'use strict';

    if (this === void 0 || this === null) {
      throw new TypeError();
    }

    var t = Object(this);
    var len = t.length >>> 0;
    if (typeof fun !== 'function') {
      throw new TypeError();
    }

    var res = [];
    var thisArg = arguments.length >= 2 ? arguments[1] : void 0;
    for (var i = 0; i < len; i++) {
      if (i in t) {
        var val = t[i];

        // NOTE: Technically this should Object.defineProperty at
        //       the next index, as push can be affected by
        //       properties on Object.prototype and Array.prototype.
        //       But that method's new, and collisions should be
        //       rare, so use the more-compatible alternative.
        if (fun.call(thisArg, val, i, t)) {
          res.push(val);
        }
      }
    }

    return res;
  };
}

function cleanText(text) {
    // all these tags should be preceeded by a full stop. 
    var fullStopTags = ['li', 'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'dd'];

    fullStopTags.forEach(function (tag) {
        text = text.replace('</' + tag + '>', '.');
    });

    text = text.replace(/<[^>]+>/g, '') // Strip tags
    .replace(/[,:;()\-]/, ' ') // Replace commans, hyphens etc (count them as spaces)
    .replace(/[\.!?]/, '.') // Unify terminators
    .replace(/^\s+/, '') // Strip leading whitespace
    .replace(/[ ]*(\n|\r\n|\r)[ ]*/, ' ') // Replace new lines with spaces
    .replace(/([\.])[\. ]+/, '.') // Check for duplicated terminators
    .replace(/[ ]*([\.])/, '. ') // Pad sentence terminators
    .replace(/\s+/, ' ') // Remove multiple spaces
    .replace(/\s+$/, ''); // Strip trailing whitespace

    text += '.'; // Add final terminator, just in case it's missing.

    return text;
}

var TextStatistics = function TextStatistics(text) {
    this.text = text ? cleanText(text) : this.text;
};

TextStatistics.prototype.fleschKincaidReadingEase = function (text) {
    text = text ? cleanText(text) : this.text;
    return Math.round((206.835 - (1.015 * this.averageWordsPerSentence(text)) - (84.6 * this.averageSyllablesPerWord(text))) * 10) / 10;
};

TextStatistics.prototype.fleschKincaidGradeLevel = function (text) {
    text = text ? cleanText(text) : this.text;
    return Math.round(((0.39 * this.averageWordsPerSentence(text)) + (11.8 * this.averageSyllablesPerWord(text)) - 15.59) * 10) / 10;
};

TextStatistics.prototype.gunningFogScore = function (text) {
    text = text ? cleanText(text) : this.text;
    return Math.round(((this.averageWordsPerSentence(text) + this.percentageWordsWithThreeSyllables(text, false)) * 0.4) * 10) / 10;
};

TextStatistics.prototype.colemanLiauIndex = function (text) {
    text = text ? cleanText(text) : this.text;
    return Math.round(((5.89 * (this.letterCount(text) / this.wordCount(text))) - (0.3 * (this.sentenceCount(text) / this.wordCount(text))) - 15.8) * 10) / 10;
};

TextStatistics.prototype.smogIndex = function (text) {
    text = text ? cleanText(text) : this.text;
    return Math.round(1.043 * Math.sqrt((this.wordsWithThreeSyllables(text) * (30 / this.sentenceCount(text))) + 3.1291) * 10) / 10;
};

TextStatistics.prototype.automatedReadabilityIndex = function (text) {
    text = text ? cleanText(text) : this.text;
    return Math.round(((4.71 * (this.letterCount(text) / this.wordCount(text))) + (0.5 * (this.wordCount(text) / this.sentenceCount(text))) - 21.43) * 10) / 10;
};

TextStatistics.prototype.textLength = function (text) {
    text = text ? cleanText(text) : this.text;
    return text.length;
};

TextStatistics.prototype.letterCount = function (text) {
    text = text ? cleanText(text) : this.text;
    text = text.replace(/[^a-z]+/ig, '');
    return text.length;
};

TextStatistics.prototype.sentenceCount = function (text) {
    text = text ? cleanText(text) : this.text;

    // Will be tripped up by 'Mr.' or 'U.K.'. Not a major concern at this point.
    return text.replace(/[^\.!?]/g, '').length || 1;
};

TextStatistics.prototype.wordCount = function (text) {
    text = text ? cleanText(text) : this.text;
    return text.split(/[^a-z0-9]+/i).length || 1;
};

TextStatistics.prototype.averageWordsPerSentence = function (text) {
    text = text ? cleanText(text) : this.text;
    return this.wordCount(text) / this.sentenceCount(text);
};

TextStatistics.prototype.averageSyllablesPerWord = function (text) {
    text = text ? cleanText(text) : this.text;
    var syllableCount = 0,
        wordCount = this.wordCount(text),
        self = this;

    text.split(/\s+/).forEach(function (word) {
        syllableCount += self.syllableCount(word);
    });

    // Prevent NaN...
    return (syllableCount || 1) / (wordCount || 1);
};

TextStatistics.prototype.wordsWithThreeSyllables = function (text, countProperNouns) {
    text = text ? cleanText(text) : this.text;
    var longWordCount = 0,
        self = this;

    countProperNouns = countProperNouns === false ? false : true;

    text.split(/\s+/).forEach(function (word) {

        // We don't count proper nouns or capitalised words if the countProperNouns attribute is set.
        // Defaults to true.
        if (!word.match(/^[A-Z]/) || countProperNouns) {
            if (self.syllableCount(word) > 2) longWordCount++;
        }
    });

    return longWordCount;
};

TextStatistics.prototype.percentageWordsWithThreeSyllables = function (text, countProperNouns) {
    text = text ? cleanText(text) : this.text;

    return (this.wordsWithThreeSyllables(text, countProperNouns) / this.wordCount(text)) * 100;
};

TextStatistics.prototype.syllableCount = function (word) {
    var syllableCount = 0,
        prefixSuffixCount = 0,
        wordPartCount = 0;

    // Prepare word - make lower case and remove non-word characters
    word = word.toLowerCase().replace(/[^a-z]/g, '');

    // Specific common exceptions that don't follow the rule set below are handled individually
    // Array of problem words (with word as key, syllable count as value)
    var problemWords = {
        'simile': 3,
            'forever': 3,
            'shoreline': 2
    };

    // Return if we've hit one of those...
    if (problemWords.hasOwnProperty(word)) return problemWords[word];

    // These syllables would be counted as two but should be one
    var subSyllables = [
        /cial/,
        /tia/,
        /cius/,
        /cious/,
        /giu/,
        /ion/,
        /iou/,
        /sia$/,
        /[^aeiuoyt]{2,}ed$/,
        /.ely$/,
        /[cg]h?e[rsd]?$/,
        /rved?$/,
        /[aeiouy][dt]es?$/,
        /[aeiouy][^aeiouydt]e[rsd]?$/,
        /^[dr]e[aeiou][^aeiou]+$/, // Sorts out deal, deign etc
    /[aeiouy]rse$/ // Purse, hearse
    ];

    // These syllables would be counted as one but should be two
    var addSyllables = [
        /ia/,
        /riet/,
        /dien/,
        /iu/,
        /io/,
        /ii/,
        /[aeiouym]bl$/,
        /[aeiou]{3}/,
        /^mc/,
        /ism$/,
        /([^aeiouy])\1l$/,
        /[^l]lien/,
        /^coa[dglx]./,
        /[^gq]ua[^auieo]/,
        /dnt$/,
        /uity$/,
        /ie(r|st)$/];

    // Single syllable prefixes and suffixes
    var prefixSuffix = [
        /^un/,
        /^fore/,
        /ly$/,
        /less$/,
        /ful$/,
        /ers?$/,
        /ings?$/];

    // Remove prefixes and suffixes and count how many were taken
    prefixSuffix.forEach(function (regex) {
        if (word.match(regex)) {
            word = word.replace(regex, '');
            prefixSuffixCount++;
        }
    });

    wordPartCount = word.split(/[^aeiouy]+/ig)
        .filter(function (wordPart) {
        return !!wordPart.replace(/\s+/ig, '').length;
    })
        .length;

    // Get preliminary syllable count...
    syllableCount = wordPartCount + prefixSuffixCount;

    // Some syllables do not follow normal rules - check for them
    subSyllables.forEach(function (syllable) {
        if (word.match(syllable)) syllableCount--;
    });

    addSyllables.forEach(function (syllable) {
        if (word.match(syllable)) syllableCount++;
    });

    return syllableCount || 1;
};

function textStatistics(text) {
    return new TextStatistics(text);
}
Dim wc, sc As Integer
Dim s1, s2, code As String
Dim oTextStats As Object
Dim o As New ScriptControl

code = "function cleanText(e){var t=['li','p','h1','h2','h3','h4','h5','h6','dd'];t.forEach(function(t){e=e.replace('</'+t+'>','.')});e=e.replace(/<[^>]+>/g,'').replace(/[,:;()\-]/,' ').replace(/[\.!?]/,'.').replace(/^\s+/,'').replace(/[ ]*(\n|\r\n|\r)[ ]*/,' ').replace(/([\.])[\. ]+/,'.').replace(/[ ]*([\.])/,'. ').replace(/\s+/,' ').replace(/\s+$/,'');e+='.';return e}function textStatistics(e){return new TextStatistics(e)}if(!Array.prototype.filter){Array.prototype.filter=function(e){'use strict';if(this===void 0||this===null){throw new TypeError}var t=Object(this);" & _
       "var n=t.length>>>0;if(typeof e!=='function'){throw new TypeError}var r=[];var i=arguments.length>=2?arguments[1]:void 0;for(var s=0;s<n;s++){if(s in t){var o=t[s];if(e.call(i,o,s,t)){r.push(o)}}}return r}}if(!Array.prototype.forEach){Array.prototype.forEach=function(e){var t=this.length;if(typeof e!='function')throw new TypeError;var n=arguments[1];for(var r=0;r<t;r++){if(r in this)e.call(n,this[r],r,this)}}}var TextStatistics=function(t){this.text=t?cleanText(t):this.text};" & _
       "TextStatistics.prototype.fleschKincaidReadingEase=function(e){e=e?cleanText(e):this.text;return Math.round((206.835-1.015*this.averageWordsPerSentence(e)-84.6*this.averageSyllablesPerWord(e))*10)/10};TextStatistics.prototype.fleschKincaidGradeLevel=function(e){e=e?cleanText(e):this.text;return Math.round((.39*this.averageWordsPerSentence(e)+11.8*this.averageSyllablesPerWord(e)-15.59)*10)/10};TextStatistics.prototype.gunningFogScore=function(e){e=e?cleanText(e):this.text;" & _
       "return Math.round((this.averageWordsPerSentence(e)+this.percentageWordsWithThreeSyllables(e,false))*.4*10)/10};TextStatistics.prototype.colemanLiauIndex=function(e){e=e?cleanText(e):this.text;return Math.round((5.89*(this.letterCount(e)/this.wordCount(e))-.3*(this.sentenceCount(e)/this.wordCount(e))-15.8)*10)/10};TextStatistics.prototype.smogIndex=function(e){e=e?cleanText(e):this.text;return Math.round(1.043*Math.sqrt(this.wordsWithThreeSyllables(e)*(30/this.sentenceCount(e))+3.1291)*10)/10};" & _
       "TextStatistics.prototype.automatedReadabilityIndex=function(e){e=e?cleanText(e):this.text;return Math.round((4.71*(this.letterCount(e)/this.wordCount(e))+.5*(this.wordCount(e)/this.sentenceCount(e))-21.43)*10)/10};TextStatistics.prototype.textLength=function(e){e=e?cleanText(e):this.text;return e.length};TextStatistics.prototype.letterCount=function(e){e=e?cleanText(e):this.text;e=e.replace(/[^a-z]+/ig,'');return e.length};TextStatistics.prototype.sentenceCount=function(e){e=e?cleanText(e):this.text;" & _
       "return e.replace(/[^\.!?]/g,'').length||1};TextStatistics.prototype.wordCount=function(e){e=e?cleanText(e):this.text;return e.split(/[^a-z0-9]+/i).length||1};TextStatistics.prototype.averageWordsPerSentence=function(e){e=e?cleanText(e):this.text;return this.wordCount(e)/this.sentenceCount(e)};TextStatistics.prototype.averageSyllablesPerWord=function(e){e=e?cleanText(e):this.text;var t=0,n=this.wordCount(e),r=this;e.split(/\s+/).forEach(function(e){t+=r.syllableCount(e)});return(t||1)/(n||1)};" & _
       "TextStatistics.prototype.wordsWithThreeSyllables=function(e,t){e=e?cleanText(e):this.text;var n=0,r=this;t=t===false?false:true;e.split(/\s+/).forEach(function(e){if(!e.match(/^[A-Z]/)||t){if(r.syllableCount(e)>2)n++}});return n};TextStatistics.prototype.percentageWordsWithThreeSyllables=function(e,t){e=e?cleanText(e):this.text;return this.wordsWithThreeSyllables(e,t)/this.wordCount(e)*100};TextStatistics.prototype.syllableCount=function(e){var t=0,n=0,r=0;e=e.toLowerCase().replace(/[^a-z]/g,'');" & _
       "var i={simile:3,forever:3,shoreline:2};if(i.hasOwnProperty(e))return i[e];var s=[/cial/,/tia/,/cius/,/cious/,/giu/,/ion/,/iou/,/sia$/,/[^aeiuoyt]{2,}ed$/,/.ely$/,/[cg]h?e[rsd]?$/,/rved?$/,/[aeiouy][dt]es?$/,/[aeiouy][^aeiouydt]e[rsd]?$/,/^[dr]e[aeiou][^aeiou]+$/,/[aeiouy]rse$/];var o=[/ia/,/riet/,/dien/,/iu/,/io/,/ii/,/[aeiouym]bl$/,/[aeiou]{3}/,/^mc/,/ism$/,/([^aeiouy])\1l$/,/[^l]lien/,/^coa[dglx]./,/[^gq]ua[^auieo]/,/dnt$/,/uity$/,/ie(r|st)$/];var u=[/^un/,/^fore/,/ly$/,/less$/,/ful$/,/ers?$/,/ings?$/];" & _
       "u.forEach(function(t){if(e.match(t)){e=e.replace(t,'');n++}});r=e.split(/[^aeiouy]+/ig).filter(function(e){return!!e.replace(/\s+/ig,'').length}).length;t=r+n;s.forEach(function(n){if(e.match(n))t--});o.forEach(function(n){if(e.match(n))t++});return t||1}"


s1 = "the quick brown fox jumps over the lazy dog"
s2 = "help me! Some Short sentence fragments. Just a test"

With o
    .Language = "JScript"
    .AddCode code
    ' Create a TextStatistics object initially with no text.
    ' textStatistics is a function that creates TextStatistics objects
    Set oTextStats = .Eval("textStatistics()")

    ' Now simply call TextStatistics methods directly
    wc = oTextStats.wordCount(s1)
    sc = oTextStats.sentenceCount(s2)

    ' Alternatively you can create a TextStatistics object with the text
    ' and call the methods with a blank string to return the values
    ' for the string passed in the constructor
    Set oTextStats = .Eval("textStatistics('" + s1 + "')")
    wc = oTextStats.wordCount("")
    sc = oTextStats.sentenceCount("")
End With