CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2012
    Posts
    2

    Question SafeArray problem

    New to VB.Net. Trying to port old code from VB6.

    Public CHandles() As Long
    Public SHandles() As Long
    Public rerrors() As Long
    Public itemvalues() As Object
    Dim Str() As String

    Once number of items is known:

    ReDim SHandles(0 To itemcount)
    ReDim rerrors(0 To itemcount)
    ReDim CHandles(0 To itemcount)
    ReDim Str(0 To itemcount)

    In VB6, these were 1 to itemcount but VB.Net doesn't like this.

    Now the following line:

    g.OPCItems.AddItems(itemcount, Str, SHandles, CHandles, rerrors)

    Generates a SafeArrayTypeMismatchException was unhandled.

    Specified Array was not of the expected type error.

    I assume it means the SHandles, rerrors, and CHandles arrays but not sure.

    Tried to review and understand previous posts related to this problem but I cannot see my way through.

    I am a EE with some programming experience. I am not an expert so please respond speaking slowly and using small words.

    Thanks for any help you can provide.
    Tom

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: SafeArray problem

    what is itemcount? I do not see where it is assigned.

    You may want to use an arraylist instead which will allow you to add or remove items on the fly without needing redim.
    Last edited by DataMiser; May 9th, 2012 at 10:30 AM.
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    May 2012
    Posts
    2

    Re: SafeArray problem

    Itemcount is determined at runtime.

    For the problem at hand, it is 32.

    At runtime,
    Itemcount is 32
    Str[0] is nothing.
    Str[1] to Str[32] have text in them that represent names of registers in a PLC.
    Shandles[0] to Shandles[32] have 0 to 32 in them respectively.
    CHandles[0] to Chandles[32] have 0 to 32 in them as well.
    Rerrors[0] ... are all 0

    I feel like the dll (OPCDauto.dll) is not expecting a safearray or doesn't like the fact that the array is 0 to 32 instead of 1 to 32.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured