Hi, Folks!

I am trying to use a to use a COM object written in VB6.

Set oSCNTool2 = CreateObject("SomeCompanyName.Tool2")

This COM object has a property called "xml" where it expects, you
guessed it, an XML string. Well, it turns out it's just expecting a
plain string and not any special XML node or what-have-you. The
problem is when I try to assign a string to this property I get a Type
Mismatch error.

oSCNTool2.xml = szXMLdata 'type mismatch error

The problem is VBScript deals in Variants and VBS strings are of the
Variant String subtype. This "xml" property is expecting the VB6
String variable type and not a Variant subtype. I do not have access
to the source code of the COM object to change it.

Does anyone know how to work around this issue?

TIA...

Re: VBScript and VB6 COM object type mismatch... by Blue

Blue
Tue Feb 27 12:38:45 CST 2007

On Feb 27, 12:11 pm, Alexander Mueller <mille...@hotmail.com> wrote:
> 27.02.2007 17:43, Blue Streak schrieb:
>
>
>
>
>
> > Hi, Folks!
>
> > I am trying to use a to use a COM object written in VB6.
>
> > Set oSCNTool2 = CreateObject("SomeCompanyName.Tool2")
>
> > This COM object has a property called "xml" where it expects, you
> > guessed it, an XML string. Well, it turns out it's just expecting a
> > plain string and not any special XML node or what-have-you. The
> > problem is when I try to assign a string to this property I get a Type
> > Mismatch error.
>
> > oSCNTool2.xml = szXMLdata 'type mismatch error
>
> > The problem is VBScript deals in Variants and VBS strings are of the
> > Variant String subtype. This "xml" property is expecting the VB6
> > String variable type and not a Variant subtype. I do not have access
> > to the source code of the COM object to change it.
>
> > Does anyone know how to work around this issue?
>
> afaik conversion functions do the trick in cases like
> this where a variant isn't accepted, try:
>
> oSCNTool2.xml = CStr(szXMLdata)
>
> Alex- Hide quoted text -
>
> - Show quoted text -

I already tried that.

It donnea work, Capt'n!!


Re: VBScript and VB6 COM object type mismatch... by mayayana

mayayana
Tue Feb 27 13:28:40 CST 2007


I just tested it with the following samples.
The sub doit just shows a msgbox that
contains an incoming string parameter.

Dim ob, s
Set ob = CreateObject("Project1.Class1")

ob.doit "okay" '-- # 1

s = "okay"

ob.doit s '-- # 2

ob.doit CStr(s) '-- # 3

Results: 1 and 3 work. 2 causes a type mismatch
error. You have to pass it while converting. It
doesn't work to do:

s = cstr(s)
ob.doit s

> >
> > > I am trying to use a to use a COM object written in VB6.
> >
> > > Set oSCNTool2 = CreateObject("SomeCompanyName.Tool2")
> >
> > > This COM object has a property called "xml" where it expects, you
> > > guessed it, an XML string. Well, it turns out it's just expecting a
> > > plain string and not any special XML node or what-have-you. The
> > > problem is when I try to assign a string to this property I get a Type
> > > Mismatch error.
> >
> > > oSCNTool2.xml = szXMLdata 'type mismatch error
> >
> > > The problem is VBScript deals in Variants and VBS strings are of the
> > > Variant String subtype. This "xml" property is expecting the VB6
> > > String variable type and not a Variant subtype. I do not have access
> > > to the source code of the COM object to change it.
> >
> > > Does anyone know how to work around this issue?
> >
> > afaik conversion functions do the trick in cases like
> > this where a variant isn't accepted, try:
> >
> > oSCNTool2.xml = CStr(szXMLdata)
> >
> > Alex- Hide quoted text -
> >
> > - Show quoted text -
>
> I already tried that.
>
> It donnea work, Capt'n!!
>



Re: VBScript and VB6 COM object type mismatch... by Blue

Blue
Tue Feb 27 17:03:50 CST 2007

On Feb 27, 2:28 pm, "mayayana" <mayayan...@mindspring.com> wrote:
> I just tested it with the following samples.
> The sub doit just shows a msgbox that
> contains an incoming string parameter.
>
> Dim ob, s
> Set ob = CreateObject("Project1.Class1")
>
> ob.doit "okay" '-- # 1
>
> s = "okay"
>
> ob.doit s '-- # 2
>
> ob.doit CStr(s) '-- # 3
>
> Results: 1 and 3 work. 2 causes a type mismatch
> error. You have to pass it while converting. It
> doesn't work to do:
>
> s = cstr(s)
> ob.doit s
>
>
>
>
>
> > > > I am trying to use a to use a COM object written in VB6.
>
> > > > Set oSCNTool2 = CreateObject("SomeCompanyName.Tool2")
>
> > > > This COM object has a property called "xml" where it expects, you
> > > > guessed it, an XML string. Well, it turns out it's just expecting a
> > > > plain string and not any special XML node or what-have-you. The
> > > > problem is when I try to assign a string to this property I get a Type
> > > > Mismatch error.
>
> > > > oSCNTool2.xml = szXMLdata 'type mismatch error
>
> > > > The problem is VBScript deals in Variants and VBS strings are of the
> > > > Variant String subtype. This "xml" property is expecting the VB6
> > > > String variable type and not a Variant subtype. I do not have access
> > > > to the source code of the COM object to change it.
>
> > > > Does anyone know how to work around this issue?
>
> > > afaik conversion functions do the trick in cases like
> > > this where a variant isn't accepted, try:
>
> > > oSCNTool2.xml = CStr(szXMLdata)
>
> > > Alex- Hide quoted text -
>
> > > - Show quoted text -
>
> > I already tried that.
>
> > It donnea work, Capt'n!!- Hide quoted text -
>
> - Show quoted text -

Thanks. It turns out that this object was internal checking on the
XML string I was supplying it. You'd think it would have displayed
something other than "Type Mismatch"


Re: VBScript and VB6 COM object type mismatch... by Anthony

Anthony
Wed Feb 28 04:29:19 CST 2007


"mayayana" <mayayana1a@mindspring.com> wrote in message
news:ID%Eh.4623$PL.1442@newsread4.news.pas.earthlink.net...
>
> I just tested it with the following samples.
> The sub doit just shows a msgbox that
> contains an incoming string parameter.
>
> Dim ob, s
> Set ob = CreateObject("Project1.Class1")

You're Class1 contains code like this:-

Public Sub doit(s as String)
End Sub

A key point is that this procedure is expecting to be passed a reference to
a string, which it may modify.

>
> ob.doit "okay" '-- # 1

Passing a string literal works.

>
> s = "okay"
>
> ob.doit s '-- # 2

s is a variant. You can only pass a variant byref if the procedure is
explicitly expecting a ByRef Variant.


>
> ob.doit CStr(s) '-- # 3

CStr returns a string so this works also.

Another variation that would work:-

ob.doit (s)

The () turn the argument into an expression.

If the doit procedure is defined:-

Public Sub doit(ByVal s as String)

then

ob.doit s

will work.


A Property setter such as is shown in the OP will always accept the assigned
value as if passed ByVal.



>
> Results: 1 and 3 work. 2 causes a type mismatch
> error. You have to pass it while converting. It
> doesn't work to do:
>
> s = cstr(s)
> ob.doit s
>