Results 1 to 9 of 9

Thread: [RESOLVED] VB6 - Unsigned data type (Can I trick?)

Threaded View

  1. #1

    Thread Starter
    PowerPoster Dave Sell's Avatar
    Join Date
    Mar 2004
    Location
    /dev/null
    Posts
    2,961

    Resolved [RESOLVED] VB6 - Unsigned data type (Can I trick?)

    OK I'm not very hopeful of a resolution but I thought I'd give it a shot here.

    I have an OPC Simulator that I can create "in-memory arrays". These arrays can be of various data types. For example they can be VT_I2, VT_I4, VT_UI2, etc...

    If these look familiar to you then keep reading... AFAIK I2 = Signed Integer, I4 = Singed Long (both native VB6 data types). Ergo, UI2 = Unsigned Integer, however VB6 cannot declare a variable as an Unsigned Int or Long (a known limitation to VB6).

    As you may have guessed, I have successfully Read data from and Written data to the VT_I2 and the VT_I4 arrays, but am unable to Write to the VT_UI2 array (although strangely I can read from it).

    I will try to condense all the code as small as possible.

    VB Code:
    1. Public Enum CanonicalDataTypes
    2.     CanonDtShort = 2 ' VT_I2
    3.     CanonDtLong = 3 ' VT_I4
    4.     CanonDtFloat = 4
    5.     CanonDtDouble = 5
    6.     CanonDtString = 8
    7.     CanonDtBool = 11
    8.     CanonDtChar = 16
    9.     CanonDtByte = 17
    10.     CanonDtWord = 18 ' VT_UI2
    11.     CanonDtDword = 19 ' VT_UI4
    12.     CanonDtArray = 8192 ' VT_Array
    13. End Enum

    The following code works for Longs (VT_I4):

    VB Code:
    1. Sub AddOPCItem
    2.     '
    3.     Dim Types(1) As Integer
    4.     '
    5.     ' Works:
    6.     '
    7.     ' VT_I4
    8.     OPCItemIDs(1) = "Device_1.aLong"
    9.     Types(1) = CanonDtLong + CanonDtArray
    10.     '
    11.     ' ...
    12.     '
    13.     Dim RequestedDataType As Variant
    14.     RequestedDataType = CVar(Types)
    15.     '
    16.     OPCItemCollection.AddItems ItemCount, OPCItemIDs, ClientHandles, ItemServerHandles, ItemServerErrors, RequestedDataType
    17.     '
    18. End Sub
    19.  
    20. Sub WriteOPC
    21.     '
    22.     Dim Vals(4) As Long ' DHS good for LONGs (VT_I4)
    23.     '
    24.     For i = 1 To 4
    25.         Vals(i) = CLng("SomeNumericValue")
    26.     Next
    27.     '
    28.     ' ...
    29.     '
    30.     ASyncItemValues(1) = CVar(Vals)
    31.     ConnectedGroup.AsyncWrite ItemCount, ASyncItemServerHandles, ASyncItemValues, ASyncItemServerErrors, TransactionID, CancelID
    32.     '
    33. End Sub

    The following code works for Integers (VT_I2):

    VB Code:
    1. Sub AddOPCItem
    2.     '
    3.     Dim Types(1) As Integer
    4.     '
    5.     ' Works:
    6.     '
    7.      VT_I2
    8.     OPCItemIDs(1) = "Device_1.aShort"
    9.     Types(1) = CanonDtShort + CanonDtArray
    10.     '
    11.     ' ...
    12.     '
    13.     Dim RequestedDataType As Variant
    14.     RequestedDataType = CVar(Types)
    15.     '
    16.     OPCItemCollection.AddItems ItemCount, OPCItemIDs, ClientHandles, ItemServerHandles, ItemServerErrors, RequestedDataType
    17.     '
    18. End Sub
    19.  
    20. Sub WriteOPC
    21.     '
    22.     Dim Vals(4) As Integer ' DHS - good for SHORTs (VT_I2)
    23.     '
    24.     For i = 1 To 4
    25.         Vals(i) = CInt("SomeNumericValue")
    26.     Next
    27.     '
    28.     ' ...
    29.     '
    30.     ASyncItemValues(1) = CVar(Vals)
    31.     ConnectedGroup.AsyncWrite ItemCount, ASyncItemServerHandles, ASyncItemValues, ASyncItemServerErrors, TransactionID, CancelID
    32.     '
    33. End Sub

    As you can see I can define a VB array of Integers to Write data down to VT_I2's and I can define a VB array of Longs to Write data down to VT_I4's.

    However I am unable to create a VB array such that I can Write down to VT_UI2's or VT_UI4's.

    I have tried using VB arrays of Integers and VB arrays of Longs in an attempt to Write data down to the VT_UI2 and VT_UI4 OPC arrays, but no data gets written down. No error is reported on either end. Its just like nothing happens.

    Question: Can I create a VB Array of "Somethings" to trick the transport layer into accepting something as an Unsigned data type?

    I have seen some blurbs about SAFEARRAYs but am unsure how that fits into the equation...

    Thanks!

    Dave
    Last edited by Dave Sell; May 13th, 2009 at 02:48 PM.
    Nobody knows what software they want until after you've delivered what they originally asked for.

    Don't solve problems which don't exist.

    "If I had eight hours to cut down a tree, I'd spend six hours sharpening my axe." --- Abraham Lincoln (1809-1865)

    2 idiots don't make a genius.

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