"Identical" VBA Calls to Perl ActiveX control provide different results

D

david.f.jenkins

I have a bit of PowerPoint VBA code (listed below) that's giving me a
headache. Depending on the form of the calls to the control, I get
different results. I'm wondering if VBA is handling the pass of a
string literal different than the pass of a String variable, and if so
- what do I do about it?

Here's the VBA:

Sub TestPerlMatch()

Dim matches As Variant
Dim pl As Object
Set PerlMatch = CreateObject("reftest.match")

' note that chr(150) is an en dash ...
Dim str As String
str = "abc " & Chr(150) & " def"

Dim pattern As String
pattern = "(\s)(-{1,2}|" & Chr(150) & ")(\s)"

'matches = PerlMatch.test(str, pattern)
' #1
matches = PerlMatch.test(str, "(\s)(-{1,2}|" & Chr(150) & ")(\s)")
' #2
For i = 0 To UBound(matches)
Debug.Print matches(i)
Next i

'matches = PerlMatch.test(str, "(\s)(-{1,2}|" & Chr(150) & ")(\s)")
' #3
matches = PerlMatch.test(str, pattern)
' #4
For i = 0 To UBound(matches)
Debug.Print matches(i)
Next i

End Sub

Here's the output from the ActiveX control:

Test 1, using calls #1 and 3:
INPUT: string = abc â€" def, pattern = (\s)(-{1,2}|â€")(\s)
matched string = â€" position = 3 length = 5
INPUT: string = abc â?? def, pattern = (\s)(-{1,2}|-)(\s)
matched string = â€" position = 3 length = 5

Test 2, using calls #2 and 4
INPUT: string = abc â?? def, pattern = (\s)(-{1,2}|-)(\s)
matched string = - position = 3 length = 3
INPUT: string = abc â€" def, pattern = (\s)(-{1,2}|â€")(\s)
matched string = - position = 3 length = 3


Note that in all of the calls, variable str is passed as the first
argument, and yet the control renders the dash character differently.
Not sure what's going on there, though ...

The second difference I note, however, is that I get different results
depending on the form of the call. The salient difference (I'm
guessing) in the test cases is whether I pass a variable or whether I
pass a string literal.

Since the variable "pattern" and the literal "(\s)(-{1,2}|" & Chr(150)
& ")(\s)" are ostensibly the same, why should I see any differences in
the way the control handles the passed data?

Any help/education would be greatly appreciated - thanks!
 
D

david.f.jenkins

I have a bit of PowerPoint VBA code (listed below) that's giving me a
headache. Depending on the form of the calls to the control, I get
different results. I'm wondering if VBA is handling the pass of a
string literal different than the pass of a String variable, and if so
- what do I do about it?

Here's the VBA:

Sub TestPerlMatch()

Dim matches As Variant
Dim pl As Object
Set PerlMatch = CreateObject("reftest.match")

' note that chr(150) is an en dash ...
Dim str As String
str = "abc " & Chr(150) & " def"

Dim pattern As String
pattern = "(\s)(-{1,2}|" & Chr(150) & ")(\s)"

'matches = PerlMatch.test(str, pattern)
' #1
matches = PerlMatch.test(str, "(\s)(-{1,2}|" & Chr(150) & ")(\s)")
' #2
For i = 0 To UBound(matches)
Debug.Print matches(i)
Next i

'matches = PerlMatch.test(str, "(\s)(-{1,2}|" & Chr(150) & ")(\s)")
' #3
matches = PerlMatch.test(str, pattern)
' #4
For i = 0 To UBound(matches)
Debug.Print matches(i)
Next i

End Sub

Here's the output from the ActiveX control:

Test 1, using calls #1 and 3:
INPUT: string = abc â€" def, pattern = (\s)(-{1,2}|â€")(\s)
matched string = â€" position = 3 length = 5
INPUT: string = abc â?? def, pattern = (\s)(-{1,2}|-)(\s)
matched string = â€" position = 3 length = 5

Test 2, using calls #2 and 4
INPUT: string = abc â?? def, pattern = (\s)(-{1,2}|-)(\s)
matched string = - position = 3 length = 3
INPUT: string = abc â€" def, pattern = (\s)(-{1,2}|â€")(\s)
matched string = - position = 3 length = 3


Note that in all of the calls, variable str is passed as the first
argument, and yet the control renders the dash character differently.
Not sure what's going on there, though ...

The second difference I note, however, is that I get different results
depending on the form of the call. The salient difference (I'm
guessing) in the test cases is whether I pass a variable or whether I
pass a string literal.

Since the variable "pattern" and the literal "(\s)(-{1,2}|" & Chr(150)
& ")(\s)" are ostensibly the same, why should I see any differences in
the way the control handles the passed data?

Any help/education would be greatly appreciated - thanks!

I *think* I may have found my problem: I generated the control using
the --byref option; once I removed that, it seems to be working now as
expected. But: never say "never" ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top