Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem assing parameter to ActiveX control 1

Status
Not open for further replies.

vaxman9

Programmer
Feb 26, 2002
80
US
Good morning all,

I have a third party ActiveX control that requires 2 parameters of type Variant to be passed to a certain function. I have sucessfully used the control for other function calls, but when I attempt to call the function that requires a variant type parameters, I receive the message ""OLE error code 0x80020005: Type mismatch."

The documentation for the control is targeted at VB and VC++, so unfortunatly, there is no help there.

Not sure how to get around this problem. Any suggestion would be greatly appriecated.

msc
 

Very difficult to help if you don't tell us what activex you rae trying to use, or even post the VB code that we could translate.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
ReFox XI (www.mcrgsoftware.com)
 
Sorry Mike,

It is an ActiveX control from Ingear ( for data acquisition from a PLC. I am using the Allen-Bradley Studio Edition.

The function I am trying to call is the WatchPointAdd Method

I have the VB and the Ingear constants defines in an include file.

This is this info from the documentation (sorry for the length):
Code:
[b]WatchPointAdd[/b]
Description:
	Adds or changes a data point in the controls internal list of alarm points to watch.

VB 6.0	[TRUE | FALSE ] = [form] ABCTL.WatchPointAdd ( [b]PtType[/b] as Integer, [b]PtIndex1[/b] as Integer, [b]PtIndex2[/b] as Integer, [b]evFlags[/b] as Integer, [b]LowLimit[/b] as Variant, [b]HighLimit[/b] As Variant, [b]fActive[/b] as Boolean )

Parameters:
[b]PtType[/b]
   The type of data point for the Watch Point.

   Data Type: 
   VB Constant
   VC Constant

   Discrete (BOOL)
   vbBoolean
   VT_BOOL

   Byte
   vbByte
   VT_UI1

   Short (16-Bit Integer)
   vbInteger
   VT_I2

   Long (32-Bit Integer)
   vbLong
   VT_I4

   Float (Single Precision)
   vbFloat
   VT_R4

[b]PtIndex1[/b]
   This is the index into the controls internal data for the point you want notification on if it changes.
   For example; if you want notification if WordVal(27) changes set PtType=vbInteger and PtIndex1 = 27

[b]PtIndex2[/b]
   This is a bit-level index into the controls data array. PtIndex2 is used when PtType = vbBoolean, otherwise it is ignored.  For example; if you want notification when BitVal(18, 5) changes, set PtType= vbBoolean, PtIndex=18 and PtIndex2=5.
  
[b]evFlags[/b]
   This is the type of event you want the control to fire.  If PtType = vbBoolean, this flag has no meaning.  The only event fired for vbBoolean is OnDiscreteChange()

   EV_ON_ANALOG_LOW
      This will cause the control to fire OnAnalogLow() when the data point crosses the LowLimit parameter
   EV_ON_ANALOG_HIGH
      This will cause the control to fire OnAnalogHigh() when the data point crosses the HighLimit parameter
   EV_ON_ANALOG_NORMAL
      This will cause the control to fire OnAnalogNormal() when the data point returns between LowLimit and HighLimit parameters
   EV_ON_ANALOG_ANY
      This will cause the control to fire OnAnalogAny() anytime the data point changes

   These flags can be OR'ed together to have the control generate multiple events for the same data point.  For example to create Hi/Low/Normal alarming you can set evFlags = EV_ON_ANALOG_LOW + EV_ON_ANALOG_HIGH + EV_ON_ANALOG_NORMAL

   For VB Users - these flags are defined in the INGEARAPI.TXT file and can added to you project using VBAPI Text Viewer
   For VC Users - these flags are defined in the INGEARAPI.H file

[b]LowLimit[/b]

   This is a Variant data type for the low limit threshold for EV_ON_ANALOG_LOW and must passed a variable.  

[b]HighLimit[/b]

   This is a Variant data type for the low limit threshold for EV_ON_ANALOG_HIGH and must passed a variable.  

[b]fActive[b]

   TRUE - The control will start generating events on the completion of the next read or unsolicited message event
   FALSE - Defers generating data change events until the WatchPointActive method is invoked
 
it seems to me, you need to provide the low and high values in the type you set via the ptType parameter.

Bye, Olaf.
 
Olaf,

That is where the problem is - no matter what type of value I attempt to pass, I receive the "type mismatch error"

From the doc, the control wants a variant type past in.

I am starting to think that VFP vars are not good enough for it and that I wil not be able to access this function of the control. I was hoping someone might have run across this issue using other 3rd party controls ..

thanks
msc
 
variant simply means it's not strongly typed and accepts different types of input, but you may still be right, thst this does not work with VFP.

But as you get an OLE error code, that error is thrown inside the control, so your call get's through, but you are calling with a wrong type.

PtType seems to be an enumeration, you need to pass in value between 0 and 5. for example, if you want to pass in 32 bit integers, PtType should be 4, and Low- and HighLimit should be integers.

As VFP is not strong typed, each variable holding numeric values is a double float, not integer. Maybe that could be the problem. If you want to pass in bool valuess, in VB 0 is false and 1 true, passing in .F. and .T. could fail.

VFP does some conversions behind the curtains, eg strings are converted between Unicode, UTF-8 and Ansi codepages. In VFP9 you can adjust this with Sys(3101). That does not help regarding Variant parameters though, just illustrates the fact, that there are things going on behind the curtain.

You may write a wrapper to that ActiveX with VB and define several variants of the method called with some concrete type.

You may try to convert VFP-Strings with Createbinary(),
eg passing integers may be done this way (untested, just a shoot in the dark):
Code:
local lnInteger, lcIntString
lnInteger = 300
lcIntString = bintoc(lnInteger,"4RS") &&VFP9 needed
oCom.method(..., Createbinary(lcIntString),...)

Bye, Olaf.
 
Olaf,

Thanks for the info. I will try your suggestions and report back - it may be a day or two (I have to test on site)

Cheers,
Msc
 
Olaf,

Following up.

Attempting to convert the variables did not work, so I decide to go with the VB wrapper.

I had never created a wrapper before, so I jumped in and created one for this control. Happy to report it is working beautifully.

Thanks much for you input,
Matt
 
Please, for us and future searchers, post the wrapper so we can see the VBscript solution to your problem.
 
dbMark,

Thanks for the reminder ...

As I mentioned, I had never done this before, so I am not sure if I can actually post the wrapper. However, I will try and explain exactly what steps I went though.

I started by googlng "VB to VFP wrapper". I found this link It shows how to build a wrapper for the Treeview ActiveX control, allowing it to be accessed via VFP. The article has a download that contains the VB project for creating the Wrapper and a VFP form the shows how the wrapper is used.

I examined and played with the examples for a bit to try and understand what was going on. I then created a new VB project - specifically a new ActiveX Control project. I used the ActiveX Control Interface Wizard (loading it from the Addins Menu using the Addin Manager). The Wizard stepped me through the process of which method/events/properties I wanted to expose to my new OCX control. It also allows you to create additional methods/properties/events for the new OCX.

After a couple of stumbles, I got the hang of what was going on.

To specifically address the issue I was having, I created a new method that I would called from VFP. From my original post, the 3rd party ActiveX Control wanted two parameters passed as variant type and would not accept any variable passed directly from VFP. My new method accepts the same number parameters when called from VFP, howver I pass all integers, which I then use to set the vars for passing to the native control. I have declared two variant vars to use when I call the native function:

Code:
Public Sub setwatch(pType As Integer, _
                                PtIndex1 As Integer, _
                                PtIndex2 As Integer, _
                                EvFlags As Integer, _
                                LowLimit As Integer, _
                                HighLimit As Integer, _
                                fActive As Integer)

    Dim vLow As Variant, _
        vHigh As Variant, _
        bolActive As Boolean

    If fActive = 0 Then
        bolActive = False
    Else
        bolActive = True
    End If
    vLow = LowLimit
    vHigh = HighLimit
    Me.Watch_Is_Active = ABCTL.WatchPointAdd(pType, PtIndex1, PtIndex2, EvFlags, vLow, vHigh, bolActive)

I basically told the Wizard to include all of the methods/properties/events of the native control in my new OCX. I built the control, registered it and dropped it on my VFP form. I called the method to set the watch point and then waited for the events to pop.

I apologize for the long winded post and I hope it makes sense. Again, this was my first shot at creating a wrapper, but I found it to be pretty straightforward.

Cheers,
Matt
 
Hi MAtt,

glad you found an example getting you on the right path to a solution by the wrapper keyword.

I could have said it means creating an ActiveX control project.

So it seems although the Variant type is a placeholder for anything, that has some special format and vfp isn't capable of handling it. A weak relation to the problem could be, VFP also can't define Variant Parameters in the DECLARE ... DLL command. So that should go on the VFP wishlist, including some other parameter Types unsupported by now.

Bye, Olaf.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top