Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #34038 > unrolled thread
| Started by | Bart Smissaert <bart.smissaert@gmail.com> |
|---|---|
| First post | 2017-09-26 16:00 -0700 |
| Last post | 2017-09-29 14:20 -0700 |
| Articles | 16 on this page of 36 — 4 participants |
Back to article view | Back to comp.lang.javascript
VB6/VBA array to JavaScript array Bart Smissaert <bart.smissaert@gmail.com> - 2017-09-26 16:00 -0700
Re: VB6/VBA array to JavaScript array "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2017-09-28 05:45 -0700
Re: VB6/VBA array to JavaScript array Bart Smissaert <bart.smissaert@gmail.com> - 2017-09-28 06:21 -0700
Re: VB6/VBA array to JavaScript array Bart Smissaert <bart.smissaert@gmail.com> - 2017-09-28 06:37 -0700
Re: VB6/VBA array to JavaScript array "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2017-09-28 08:44 -0700
Re: VB6/VBA array to JavaScript array Bart Smissaert <bart.smissaert@gmail.com> - 2017-09-28 09:07 -0700
Re: VB6/VBA array to JavaScript array Julio Di Egidio <julio@diegidio.name> - 2017-09-28 09:47 -0700
Re: VB6/VBA array to JavaScript array Bart Smissaert <bart.smissaert@gmail.com> - 2017-09-28 10:15 -0700
Re: VB6/VBA array to JavaScript array Bart Smissaert <bart.smissaert@gmail.com> - 2017-09-29 02:52 -0700
Re: VB6/VBA array to JavaScript array Julio Di Egidio <julio@diegidio.name> - 2017-09-29 05:55 -0700
Re: VB6/VBA array to JavaScript array Julio Di Egidio <julio@diegidio.name> - 2017-09-29 06:00 -0700
Re: VB6/VBA array to JavaScript array Bart Smissaert <bart.smissaert@gmail.com> - 2017-09-29 06:29 -0700
Re: VB6/VBA array to JavaScript array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-09-29 17:06 +0200
Re: VB6/VBA array to JavaScript array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-09-29 16:10 +0200
Re: VB6/VBA array to JavaScript array Bart Smissaert <bart.smissaert@gmail.com> - 2017-09-29 07:13 -0700
Re: VB6/VBA array to JavaScript array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-09-29 17:14 +0200
Re: VB6/VBA array to JavaScript array Bart Smissaert <bart.smissaert@gmail.com> - 2017-09-29 08:24 -0700
Re: VB6/VBA array to JavaScript array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-09-29 19:08 +0200
Re: VB6/VBA array to JavaScript array Bart Smissaert <bart.smissaert@gmail.com> - 2017-09-29 10:41 -0700
Re: VB6/VBA array to JavaScript array Bart Smissaert <bart.smissaert@gmail.com> - 2017-09-29 08:27 -0700
Re: VB6/VBA array to JavaScript array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2017-09-29 19:11 +0200
Re: VB6/VBA array to JavaScript array Bart Smissaert <bart.smissaert@gmail.com> - 2017-09-29 10:43 -0700
Re: VB6/VBA array to JavaScript array Bart Smissaert <bart.smissaert@gmail.com> - 2017-09-29 08:42 -0700
Re: VB6/VBA array to JavaScript array Julio Di Egidio <julio@diegidio.name> - 2017-09-29 11:28 -0700
Re: VB6/VBA array to JavaScript array Bart Smissaert <bart.smissaert@gmail.com> - 2017-09-29 12:23 -0700
Re: VB6/VBA array to JavaScript array Bart Smissaert <bart.smissaert@gmail.com> - 2017-09-29 13:18 -0700
Re: VB6/VBA array to JavaScript array Julio Di Egidio <julio@diegidio.name> - 2017-09-29 15:34 -0700
Re: VB6/VBA array to JavaScript array Bart Smissaert <bart.smissaert@gmail.com> - 2017-09-30 04:44 -0700
Re: VB6/VBA array to JavaScript array Bart Smissaert <bart.smissaert@gmail.com> - 2017-09-30 05:43 -0700
Re: VB6/VBA array to JavaScript array Bart Smissaert <bart.smissaert@gmail.com> - 2017-09-30 08:48 -0700
Re: VB6/VBA array to JavaScript array Bart Smissaert <bart.smissaert@gmail.com> - 2017-09-30 07:52 -0700
Re: VB6/VBA array to JavaScript array "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2017-09-30 08:52 -0700
Re: VB6/VBA array to JavaScript array Bart Smissaert <bart.smissaert@gmail.com> - 2017-09-30 09:12 -0700
Re: VB6/VBA array to JavaScript array Bart Smissaert <bart.smissaert@gmail.com> - 2017-09-30 10:10 -0700
Re: VB6/VBA array to JavaScript array Bart Smissaert <bart.smissaert@gmail.com> - 2017-09-30 10:16 -0700
Re: VB6/VBA array to JavaScript array Bart Smissaert <bart.smissaert@gmail.com> - 2017-09-29 14:20 -0700
Page 2 of 2 — ← Prev page 1 [2]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2017-09-29 19:11 +0200 |
| Message-ID | <3199571.hdfAi7Kttb@PointedEars.de> |
| In reply to | #34068 |
Bart Smissaert wrote: [Restored attribution] > [Thomas 'PointedEars' Lahn wrote: ] >> I presume it is Microsoft Internet Explorer > > It doesn't run in MS Internet Explorer. OK. > It all runs in a VB6 ActiveX dll. Unless I am very much mistaken, a DLL does not run by itself. Also, one can use *JScript* code in a *VB6* ActiveX DLL? > Unless I am mistaken, MS Internet Explorer has nil to do with this. Where are you using the DLL, then? -- PointedEars FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix> <https://github.com/PointedEars> | <http://PointedEars.de/wsvn/> Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | Bart Smissaert <bart.smissaert@gmail.com> |
|---|---|
| Date | 2017-09-29 10:43 -0700 |
| Message-ID | <1bbcca66-3a1d-4565-baca-4411e9315f0d@googlegroups.com> |
| In reply to | #34071 |
On Friday, 29 September 2017 18:11:57 UTC+1, Thomas 'PointedEars' Lahn wrote: > Bart Smissaert wrote: > > [Restored attribution] > > > [Thomas 'PointedEars' Lahn wrote: ] > >> I presume it is Microsoft Internet Explorer > > > > It doesn't run in MS Internet Explorer. > > OK. > > > It all runs in a VB6 ActiveX dll. > > Unless I am very much mistaken, a DLL does not run by itself. > > Also, one can use *JScript* code in a *VB6* ActiveX DLL? > > > Unless I am mistaken, MS Internet Explorer has nil to do with this. > > Where are you using the DLL, then? > > -- > PointedEars > FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix> > <https://github.com/PointedEars> | <http://PointedEars.de/wsvn/> > Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail. >> Unless I am very much mistaken, a DLL does not run by itself. That dll runs from Excel VBA. >> Also, one can use *JScript* code in a *VB6* ActiveX DLL? Yes, I am doing that and it works. RBS
[toc] | [prev] | [next] | [standalone]
| From | Bart Smissaert <bart.smissaert@gmail.com> |
|---|---|
| Date | 2017-09-29 08:42 -0700 |
| Message-ID | <4d77182f-1e30-491d-bdce-add23a113859@googlegroups.com> |
| In reply to | #34066 |
I have done away with the lBytes variable as JS can't pass arguments ByRef.
So my JS code is now like this:
function JS_ArrayTest(lParamCount, strParam1, lParam2, dParam3)
{
var a = new VBArray(UDF.GetIntegerArray(1));
var b = a.ToArray();
return b.length;
}
GetIntegerArray (function in the class UDF in my VB6 dll) is declared like this:
Public Function GetIntegerArray(ParamIdxOneBased As Long) As Integer()
and the produced array declared like this:
ReDim arrInteger(0 To lBytes - 1, 0 To 1) As Integer
With this I get this error:
VBArray expected
JS code line:
var a = new VBArray(UDF.GetIntegerArray(1));
So, what exactly do I have to supply to VBArray( ?
RBS
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2017-09-29 11:28 -0700 |
| Message-ID | <a7f14dc4-6bf8-429d-b9f5-674a4f00807a@googlegroups.com> |
| In reply to | #34069 |
On Friday, September 29, 2017 at 5:42:41 PM UTC+2, Bart Smissaert wrote:
>
> I have done away with the lBytes variable as JS can't pass arguments ByRef.
> So my JS code is now like this:
>
> function JS_ArrayTest(lParamCount, strParam1, lParam2, dParam3)
> {
> var a = new VBArray(UDF.GetIntegerArray(1));
>
> var b = a.ToArray();
>
> return b.length;
> }
>
> GetIntegerArray (function in the class UDF in my VB6 dll) is declared like this:
>
> Public Function GetIntegerArray(ParamIdxOneBased As Long) As Integer()
>
> and the produced array declared like this:
>
> ReDim arrInteger(0 To lBytes - 1, 0 To 1) As Integer
>
> With this I get this error:
>
> VBArray expected
>
> JS code line:
> var a = new VBArray(UDF.GetIntegerArray(1));
>
> So, what exactly do I have to supply to VBArray( ?
A VB safe array: <https://docs.microsoft.com/en-us/scripting/javascript/reference/vbarray-object-javascript>
You just show little portion of the VB function so still impossible to tell
what's going wrong: what you show, the JS and the VB, look fine now, except
that VBArray does not have a length property, so your JS function would be
returning undefined, i.e. if it weren't failing.
Anyway, I won't be able to help further unless you show full code of what
you are trying. Also, I'd suggest you try and start from reproducing the
example that is on that documentation page, in fact make it even simpler,
just return a fixed array and see if you can get that working.
Julio
[toc] | [prev] | [next] | [standalone]
| From | Bart Smissaert <bart.smissaert@gmail.com> |
|---|---|
| Date | 2017-09-29 12:23 -0700 |
| Message-ID | <3253f01d-56f4-4659-aac2-b429d982c37b@googlegroups.com> |
| In reply to | #34074 |
On Friday, 29 September 2017 19:29:11 UTC+1, Julio Di Egidio wrote:
> On Friday, September 29, 2017 at 5:42:41 PM UTC+2, Bart Smissaert wrote:
> >
> > I have done away with the lBytes variable as JS can't pass arguments ByRef.
> > So my JS code is now like this:
> >
> > function JS_ArrayTest(lParamCount, strParam1, lParam2, dParam3)
> > {
> > var a = new VBArray(UDF.GetIntegerArray(1));
> >
> > var b = a.ToArray();
> >
> > return b.length;
> > }
> >
> > GetIntegerArray (function in the class UDF in my VB6 dll) is declared like this:
> >
> > Public Function GetIntegerArray(ParamIdxOneBased As Long) As Integer()
> >
> > and the produced array declared like this:
> >
> > ReDim arrInteger(0 To lBytes - 1, 0 To 1) As Integer
> >
> > With this I get this error:
> >
> > VBArray expected
> >
> > JS code line:
> > var a = new VBArray(UDF.GetIntegerArray(1));
> >
> > So, what exactly do I have to supply to VBArray( ?
>
> A VB safe array: <https://docs.microsoft.com/en-us/scripting/javascript/reference/vbarray-object-javascript>
>
> You just show little portion of the VB function so still impossible to tell
> what's going wrong: what you show, the JS and the VB, look fine now, except
> that VBArray does not have a length property, so your JS function would be
> returning undefined, i.e. if it weren't failing.
>
> Anyway, I won't be able to help further unless you show full code of what
> you are trying. Also, I'd suggest you try and start from reproducing the
> example that is on that documentation page, in fact make it even simpler,
> just return a fixed array and see if you can get that working.
>
> Julio
>> except
that VBArray does not have a length property, so your JS function would be
returning undefined, i.e. if it weren't failing.
Isn't b now a JS array?
I will try with a fixed array and see that works.
RBS
[toc] | [prev] | [next] | [standalone]
| From | Bart Smissaert <bart.smissaert@gmail.com> |
|---|---|
| Date | 2017-09-29 13:18 -0700 |
| Message-ID | <4af0b534-9f9f-433e-ada2-88c111958b7b@googlegroups.com> |
| In reply to | #34074 |
On Friday, 29 September 2017 19:29:11 UTC+1, Julio Di Egidio wrote:
> On Friday, September 29, 2017 at 5:42:41 PM UTC+2, Bart Smissaert wrote:
> >
> > I have done away with the lBytes variable as JS can't pass arguments ByRef.
> > So my JS code is now like this:
> >
> > function JS_ArrayTest(lParamCount, strParam1, lParam2, dParam3)
> > {
> > var a = new VBArray(UDF.GetIntegerArray(1));
> >
> > var b = a.ToArray();
> >
> > return b.length;
> > }
> >
> > GetIntegerArray (function in the class UDF in my VB6 dll) is declared like this:
> >
> > Public Function GetIntegerArray(ParamIdxOneBased As Long) As Integer()
> >
> > and the produced array declared like this:
> >
> > ReDim arrInteger(0 To lBytes - 1, 0 To 1) As Integer
> >
> > With this I get this error:
> >
> > VBArray expected
> >
> > JS code line:
> > var a = new VBArray(UDF.GetIntegerArray(1));
> >
> > So, what exactly do I have to supply to VBArray( ?
>
> A VB safe array: <https://docs.microsoft.com/en-us/scripting/javascript/reference/vbarray-object-javascript>
>
> You just show little portion of the VB function so still impossible to tell
> what's going wrong: what you show, the JS and the VB, look fine now, except
> that VBArray does not have a length property, so your JS function would be
> returning undefined, i.e. if it weren't failing.
>
> Anyway, I won't be able to help further unless you show full code of what
> you are trying. Also, I'd suggest you try and start from reproducing the
> example that is on that documentation page, in fact make it even simpler,
> just return a fixed array and see if you can get that working.
>
> Julio
Tried with a fixed array, so this is the VB6 function in the UDF class:
Public Function GetIntegerArray(ParamIdxOneBased As Long) As Integer()
Dim i As Long
Dim a(0 To 10, 0 To 0) As Integer
If bLog Then LogData strLogFile, "GetIntegerArray, start of Function"
For i = 0 To 10
a(i, 0) = i
Next i
GetIntegerArray = a()
If bLog Then LogData strLogFile, "GetIntegerArray, end of Function"
End Function
And this is the JS code:
function JS_ArrayTest(lParamCount, strParam1, lParam2, dParam3)
{
var a = new VBArray(UDF.GetIntegerArray(1));
return 4;
}
GetIntegerArray does indeed run as I can see from the log.
I still get though:
JS error description:
VBArray expected
JS line number: 87
JS code line:
var a = new VBArray(UDF.GetIntegerArray(1));
So, what is wrong with the array produced by GetIntegerArray?
For sure it is a VB SafeArray.
RBS
[toc] | [prev] | [next] | [standalone]
| From | Julio Di Egidio <julio@diegidio.name> |
|---|---|
| Date | 2017-09-29 15:34 -0700 |
| Message-ID | <f46659b6-e320-438b-81de-a7a9f00b7733@googlegroups.com> |
| In reply to | #34076 |
On Friday, September 29, 2017 at 10:18:38 PM UTC+2, Bart Smissaert wrote:
> Tried with a fixed array, so this is the VB6 function in the UDF class:
>
> Public Function GetIntegerArray(ParamIdxOneBased As Long) As Integer()
>
> Dim i As Long
> Dim a(0 To 10, 0 To 0) As Integer
>
> If bLog Then LogData strLogFile, "GetIntegerArray, start of Function"
>
> For i = 0 To 10
> a(i, 0) = i
> Next i
>
> GetIntegerArray = a()
Shouldn't that be:
GetIntegerArray = a
Apart from that, I cannot see anything wrong with the code.
Julio
> If bLog Then LogData strLogFile, "GetIntegerArray, end of Function"
>
> End Function
>
> And this is the JS code:
>
> function JS_ArrayTest(lParamCount, strParam1, lParam2, dParam3)
>
> {
> var a = new VBArray(UDF.GetIntegerArray(1));
>
> return 4;
> }
>
> GetIntegerArray does indeed run as I can see from the log.
> I still get though:
>
> JS error description:
> VBArray expected
>
> JS line number: 87
> JS code line:
> var a = new VBArray(UDF.GetIntegerArray(1));
>
> So, what is wrong with the array produced by GetIntegerArray?
> For sure it is a VB SafeArray.
[toc] | [prev] | [next] | [standalone]
| From | Bart Smissaert <bart.smissaert@gmail.com> |
|---|---|
| Date | 2017-09-30 04:44 -0700 |
| Message-ID | <18636b05-0c91-411e-9657-ac7a82da6863@googlegroups.com> |
| In reply to | #34078 |
On Friday, 29 September 2017 23:34:29 UTC+1, Julio Di Egidio wrote:
> On Friday, September 29, 2017 at 10:18:38 PM UTC+2, Bart Smissaert wrote:
>
> > Tried with a fixed array, so this is the VB6 function in the UDF class:
> >
> > Public Function GetIntegerArray(ParamIdxOneBased As Long) As Integer()
> >
> > Dim i As Long
> > Dim a(0 To 10, 0 To 0) As Integer
> >
> > If bLog Then LogData strLogFile, "GetIntegerArray, start of Function"
> >
> > For i = 0 To 10
> > a(i, 0) = i
> > Next i
> >
> > GetIntegerArray = a()
>
> Shouldn't that be:
>
> GetIntegerArray = a
>
> Apart from that, I cannot see anything wrong with the code.
>
> Julio
GetIntegerArray = a()
is fine and works. Without the brackets there will be an error.
I have made progress now with this and I think I am getting the VB array fine
now in my JS code. Having problems though converting this to a regular JS array:
function JS_ArrayTest(lParamCount, strParam1, lParam2, dParam3)
{
//this works now and produces a VB array
var a = new VBArray(UDF.GetVariantArray(1));
//The return statement stops the execution of a function and returns a value from that function.
//this works now and does the early exit if needed
if (a.getItem(0, 0) == -1) {
return 0;
}
//this works as well, so VB array seems to be fine
//return a.getItem(0, 0);
//this does not work, gives error:
//Object expected
//var b = new a.ToArray();
var b = new a.ToArray();
return a.getItem(1, 0);
//return a.ubound(1);
//return b.length;
}
Note that the VB array is declared like this in the UDF class:
ReDim arrVariant(0 To lBytes - 1, 0 To 0) As Variant
It seems it needs to be declared a variant.
RBS
[toc] | [prev] | [next] | [standalone]
| From | Bart Smissaert <bart.smissaert@gmail.com> |
|---|---|
| Date | 2017-09-30 05:43 -0700 |
| Message-ID | <beec6228-31ac-4f8f-b5cd-090f635b5747@googlegroups.com> |
| In reply to | #34079 |
On Saturday, 30 September 2017 12:44:45 UTC+1, Bart Smissaert wrote:
> On Friday, 29 September 2017 23:34:29 UTC+1, Julio Di Egidio wrote:
> > On Friday, September 29, 2017 at 10:18:38 PM UTC+2, Bart Smissaert wrote:
> >
> > > Tried with a fixed array, so this is the VB6 function in the UDF class:
> > >
> > > Public Function GetIntegerArray(ParamIdxOneBased As Long) As Integer()
> > >
> > > Dim i As Long
> > > Dim a(0 To 10, 0 To 0) As Integer
> > >
> > > If bLog Then LogData strLogFile, "GetIntegerArray, start of Function"
> > >
> > > For i = 0 To 10
> > > a(i, 0) = i
> > > Next i
> > >
> > > GetIntegerArray = a()
> >
> > Shouldn't that be:
> >
> > GetIntegerArray = a
> >
> > Apart from that, I cannot see anything wrong with the code.
> >
> > Julio
>
> GetIntegerArray = a()
>
> is fine and works. Without the brackets there will be an error.
>
> I have made progress now with this and I think I am getting the VB array fine
> now in my JS code. Having problems though converting this to a regular JS array:
>
> function JS_ArrayTest(lParamCount, strParam1, lParam2, dParam3)
>
> {
>
> //this works now and produces a VB array
> var a = new VBArray(UDF.GetVariantArray(1));
>
> //The return statement stops the execution of a function and returns a value from that function.
>
> //this works now and does the early exit if needed
> if (a.getItem(0, 0) == -1) {
> return 0;
> }
>
> //this works as well, so VB array seems to be fine
> //return a.getItem(0, 0);
>
> //this does not work, gives error:
> //Object expected
> //var b = new a.ToArray();
>
> var b = new a.ToArray();
>
> return a.getItem(1, 0);
>
> //return a.ubound(1);
>
> //return b.length;
>
> }
>
> Note that the VB array is declared like this in the UDF class:
>
> ReDim arrVariant(0 To lBytes - 1, 0 To 0) As Variant
>
> It seems it needs to be declared a variant.
>
>
> RBS
Ignore this, ToArray should be toArray.
JS being case-sensitive has tripped me up many times now.
Used to VB6 and VBA where the code is case-insensitive.
RBS
[toc] | [prev] | [next] | [standalone]
| From | Bart Smissaert <bart.smissaert@gmail.com> |
|---|---|
| Date | 2017-09-30 08:48 -0700 |
| Message-ID | <77cd3c51-e117-4717-8c4b-469441509931@googlegroups.com> |
| In reply to | #34080 |
Got nearly worked out now but having a problem with the syntax of a nested loop:
function JS_CountString(lParamCount, strParam1, lParam2, dParam3)
{
var arrSearchVB = new VBArray(UDF.GetVariantArray(1));
//no string to search so exit
if (arrSearchVB.getItem(0) == -1) {
return 0;
}
var arrFindVB = new VBArray(UDF.GetVariantArray(2));
//no string to search for, so exit
if (arrFindVB.getItem(0) == -1) {
return 0;
}
var arrSearchJS = arrSearchVB.toArray();
var arrFindJS = arrFindVB.toArray();
//note we do not use new here
var UBS = arrSearchJS.length;
var UBF = arrFindJS.length;
var lCount = 0;
//error in this code block
for (var i = 0; i < UBS; i++) {
for (var n = 0; n < UBF; n++) {
If arrSearch(i + n) != arrFind(n) {
break;
} Else {
If n == UBF {
lCount++;
}
}
}
}
return lCount;
}
Could anybody tell me what the problem is with this last code block?
I get automation error, but can't get any more specific message.
RBS
[toc] | [prev] | [next] | [standalone]
| From | Bart Smissaert <bart.smissaert@gmail.com> |
|---|---|
| Date | 2017-09-30 07:52 -0700 |
| Message-ID | <bf1dfb90-43cc-4bc9-9d17-85880a89680a@googlegroups.com> |
| In reply to | #34078 |
On Friday, 29 September 2017 23:34:29 UTC+1, Julio Di Egidio wrote:
> On Friday, September 29, 2017 at 10:18:38 PM UTC+2, Bart Smissaert wrote:
>
> > Tried with a fixed array, so this is the VB6 function in the UDF class:
> >
> > Public Function GetIntegerArray(ParamIdxOneBased As Long) As Integer()
> >
> > Dim i As Long
> > Dim a(0 To 10, 0 To 0) As Integer
> >
> > If bLog Then LogData strLogFile, "GetIntegerArray, start of Function"
> >
> > For i = 0 To 10
> > a(i, 0) = i
> > Next i
> >
> > GetIntegerArray = a()
>
> Shouldn't that be:
>
> GetIntegerArray = a
>
> Apart from that, I cannot see anything wrong with the code.
>
> Julio
Got this nearly worked out now, but having some problem with nested for loop.
This is the full JS code:
function JS_CountString(lParamCount, strParam1, lParam2, dParam3)
{
var arrSearchVB = new VBArray(UDF.GetVariantArray(1));
//no string to search so exit
if (arrSearchVB.getItem(0) == -1) {
return 0;
}
var arrFindVB = new VBArray(UDF.GetVariantArray(2));
//no string to search for, so exit
if (arrFindVB.getItem(0) == -1) {
return 0;
}
var arrSearchJS = arrSearchVB.toArray();
var arrFindJS = arrFindVB.toArray();
//note we do not use new here
var UBS = arrSearchJS.length;
var UBF = arrFindJS.length;
var lCount = 0;
//error in this code block
for (var i = 0; i < UBS; i++) {
for (var n = 0; n < UBF; n++) {
If arrSearch(i + n) != arrFind(n) {
break;
}
If n == UBF {
lCount++;
}
}
}
return lCount;
}
All is fine up to that nested loop, but can't see the problem.
Could somebody tell me what is wrong with it?
RBS
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2017-09-30 08:52 -0700 |
| Message-ID | <c8d1d365-7a2f-4527-802f-ec1076a17adb@googlegroups.com> |
| In reply to | #34076 |
Bart Smissaert wrote: > So, what is wrong with the array produced by GetIntegerArray? > For sure it is a VB SafeArray. A VBArray is a very iffy construct: <https://blogs.msdn.microsoft.com/ericlippert/2003/09/22/jscript-and-vbscript-arrays/> and that's just between VBScript and JScript that share the same runtime. With VB6 (VBA?) interoping with JScript? Sounds even worse... Why not pass the data through serialization instead?
[toc] | [prev] | [next] | [standalone]
| From | Bart Smissaert <bart.smissaert@gmail.com> |
|---|---|
| Date | 2017-09-30 09:12 -0700 |
| Message-ID | <1ee1334b-f012-4903-91fd-f1239d8cacbc@googlegroups.com> |
| In reply to | #34084 |
On Saturday, 30 September 2017 16:53:06 UTC+1, Michael Haufe (TNO) wrote: > Bart Smissaert wrote: > > > So, what is wrong with the array produced by GetIntegerArray? > > For sure it is a VB SafeArray. > > A VBArray is a very iffy construct: > > <https://blogs.msdn.microsoft.com/ericlippert/2003/09/22/jscript-and-vbscript-arrays/> > > and that's just between VBScript and JScript that share the same runtime. With VB6 (VBA?) interoping with JScript? Sounds even worse... > > Why not pass the data through serialization instead? I got this actually worked out now and it is working fine. Just a small problem with the syntax I presume of my JS code as posted. Not sure what you mean with serialization. RBS
[toc] | [prev] | [next] | [standalone]
| From | Bart Smissaert <bart.smissaert@gmail.com> |
|---|---|
| Date | 2017-09-30 10:10 -0700 |
| Message-ID | <3bf7a2d3-ca36-4a13-9c0d-eee68ed9d68c@googlegroups.com> |
| In reply to | #34085 |
Have fixed some error with the help of JSLint but still some problems:
function JS_CountString(lParamCount, strParam1, lParam2, dParam3)
{
var arrSearchVB = new VBArray(UDF.GetVariantArray(1));
//no string to search so exit
if (arrSearchVB.getItem(0) == -1) {
return 0;
}
var arrFindVB = new VBArray(UDF.GetVariantArray(2));
//no string to search for, so exit
if (arrFindVB.getItem(0) == -1) {
return 0;
}
var arrSearchJS = arrSearchVB.toArray();
var arrFindJS = arrFindVB.toArray();
//note we do not use new here
var UBS = arrSearchJS.length;
var UBF = arrFindJS.length;
var i = 0;
var n = 0;
var lCount = 0;
//error in this code block
for (i = 0; i < UBS; i++) {
for (n = 0; n < UBF; n++) {
If (arrSearch[i + n] != arrFind[n]); {
break;
} Else {
If (n == UBF) {
lCount++;
}
}
}
}
return lCount;
}
Problem at line 32 character 12: Missing 'new' prefix when invoking a constructor.
If (arrSearch[i + n] != arrFind[n]); {
Problem at line 33 character 15: Expected to see a statement and instead saw a block.
break;
Any idea how to alter it?
RBS
[toc] | [prev] | [next] | [standalone]
| From | Bart Smissaert <bart.smissaert@gmail.com> |
|---|---|
| Date | 2017-09-30 10:16 -0700 |
| Message-ID | <81bbdeaa-51ac-48fa-a0df-62c75a172aac@googlegroups.com> |
| In reply to | #34086 |
On Saturday, 30 September 2017 18:10:24 UTC+1, Bart Smissaert wrote:
> Have fixed some error with the help of JSLint but still some problems:
>
> function JS_CountString(lParamCount, strParam1, lParam2, dParam3)
>
> {
>
> var arrSearchVB = new VBArray(UDF.GetVariantArray(1));
>
> //no string to search so exit
> if (arrSearchVB.getItem(0) == -1) {
> return 0;
> }
>
> var arrFindVB = new VBArray(UDF.GetVariantArray(2));
>
> //no string to search for, so exit
> if (arrFindVB.getItem(0) == -1) {
> return 0;
> }
>
> var arrSearchJS = arrSearchVB.toArray();
> var arrFindJS = arrFindVB.toArray();
>
> //note we do not use new here
> var UBS = arrSearchJS.length;
> var UBF = arrFindJS.length;
> var i = 0;
> var n = 0;
> var lCount = 0;
>
> //error in this code block
> for (i = 0; i < UBS; i++) {
> for (n = 0; n < UBF; n++) {
> If (arrSearch[i + n] != arrFind[n]); {
> break;
> } Else {
> If (n == UBF) {
> lCount++;
> }
> }
> }
> }
>
> return lCount;
>
> }
>
>
> Problem at line 32 character 12: Missing 'new' prefix when invoking a constructor.
>
> If (arrSearch[i + n] != arrFind[n]); {
>
> Problem at line 33 character 15: Expected to see a statement and instead saw a block.
>
> break;
>
>
> Any idea how to alter it?
>
>
> RBS
>> If (arrSearch[i + n] != arrFind[n]); {
This should be:
If (arrSearchJS[i + n] != arrFindJS[n]); {
but get the same error.
RBS
[toc] | [prev] | [next] | [standalone]
| From | Bart Smissaert <bart.smissaert@gmail.com> |
|---|---|
| Date | 2017-09-29 14:20 -0700 |
| Message-ID | <650f63bc-1c2f-4e0c-a4a8-686018f07b82@googlegroups.com> |
| In reply to | #34074 |
On Friday, 29 September 2017 19:29:11 UTC+1, Julio Di Egidio wrote:
> On Friday, September 29, 2017 at 5:42:41 PM UTC+2, Bart Smissaert wrote:
> >
> > I have done away with the lBytes variable as JS can't pass arguments ByRef.
> > So my JS code is now like this:
> >
> > function JS_ArrayTest(lParamCount, strParam1, lParam2, dParam3)
> > {
> > var a = new VBArray(UDF.GetIntegerArray(1));
> >
> > var b = a.ToArray();
> >
> > return b.length;
> > }
> >
> > GetIntegerArray (function in the class UDF in my VB6 dll) is declared like this:
> >
> > Public Function GetIntegerArray(ParamIdxOneBased As Long) As Integer()
> >
> > and the produced array declared like this:
> >
> > ReDim arrInteger(0 To lBytes - 1, 0 To 1) As Integer
> >
> > With this I get this error:
> >
> > VBArray expected
> >
> > JS code line:
> > var a = new VBArray(UDF.GetIntegerArray(1));
> >
> > So, what exactly do I have to supply to VBArray( ?
>
> A VB safe array: <https://docs.microsoft.com/en-us/scripting/javascript/reference/vbarray-object-javascript>
>
> You just show little portion of the VB function so still impossible to tell
> what's going wrong: what you show, the JS and the VB, look fine now, except
> that VBArray does not have a length property, so your JS function would be
> returning undefined, i.e. if it weren't failing.
>
> Anyway, I won't be able to help further unless you show full code of what
> you are trying. Also, I'd suggest you try and start from reproducing the
> example that is on that documentation page, in fact make it even simpler,
> just return a fixed array and see if you can get that working.
>
> Julio
A fixed 2D array works with returning a variant array:
Dim b(0 To 10, 0 To 0) As Variant
For x = 0 To 10
b(x, 0) = x
Next x
GetVariantArray = b()
But that is not much use really. Will if I can make it work with dynamic arrays.
RBS
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.javascript
csiph-web