Results 1 to 4 of 4

Thread: How do you convert this C++ function to vb declaration?

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    2
    Hi all,

    Any idea on how to convert this c++ function header to vb declaration ?

    UINT CmdDownLoadIULabel(myStructures theArray[500]);

    I am more concerned on how I am to declare the Array part (theArray[500]).

    Thanks

  2. #2
    Member
    Join Date
    Oct 2000
    Posts
    35
    It should be enough to pass the first entries addres.

    Declare Function CmdDownLoadIULabel Lib "..." (ByVal myStructures as Any)as integer

    ret = CmdDownLoadIULabel (myStructure(1))

    you need to make sure the procedure knows how many entries are in the array.
    rfo

  3. #3
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    Hmm, let's take a closer look.

    UINT CmdDownLoadIULabel(myStructures theArray[500]);

    UINT means that the return value is an unsigned integer. In VB you have to use a Long, since bit 15 can't be 1 in an Integer.

    CmdDownLoadIULabel is the name of the function. No problem.

    The parameter theArray[500] is an array with 500 elements [0..499] of a type called myStructures and has to be defined with the Type statement in VB.

    I should redeclare this function in VB like:

    Code:
    Function CmdDownLoadIULabel (theArray() As myStructures) As Long
    But VB gives me an error when using the user-defined type myStructures. By now, I don't know how to pass a user-defined type to a function.
    I'll keep in touch...


  4. #4
    Fanatic Member Mad Compie's Avatar
    Join Date
    Aug 2000
    Location
    Kuurne (Belgium)
    Posts
    553
    Here we are again...

    If you want to pass a user-defined type to a function, then this function has to be declared as Private, otherwise you get an error (like I did)!
    So, here's the solution:
    Code:
    'In a form...
    Option Explicit
    
    Private Type myStructures
      a   As Integer
      b   As Byte
      c() As Long
      '...
    End Type
    Dim theArray(500) As myStructures
    
    Private Sub Form_Load()
      CmdDownLoadIULabel theArray
    End Sub
    
    Private Function CmdDownLoadIULabel (ByRef theArray() As myStructures) As Long
      Debug.Print UBound(theArray) 'Should also be 500!!!
    End Sub

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