Results 1 to 7 of 7

Thread: User-defined Type.

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 1999
    Posts
    8

    Question

    Hi all,

    I defined a new type in a regular module, say:
    Type Ack_Msg
    Token as String*3
    Status as string
    End Type

    Then in one of the forms in the project I declared:

    Private Sub Contact_Server()
    Dim strData As Ack_Msg_T
    ....

    but as the program reaches that sub I get an error
    message:

    "Compile error:

    Only user-defined types defined in public object modules can be coerced to or from a variant or passed to late-bound function."

    What went worng?

    I tried to change the sub type to public, and the declaration of the var, without any success.

    According to MSDN I did what I suppose to do (to my understanding...)

    Please help.

    Thanks.

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    You could try making the type public
    In the bas module
    Public Type Ack_Msg

    Also, it may be a typo, but you have
    Type ACk_Msg in the declare
    and then you declare it as ACK_MSG_T
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 1999
    Posts
    8
    I tried already the public type, and it did not work.
    And it is not a typing mistake either...

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    You could also declare the type private, for use only inside that class. Use dim to declare procedure scope variables and private for module, omiting private will automatically declare it public.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    You have declared a user defined data type in Ack_Msg and yet you say that Ack_Msg_T is not a typo. Where is Ack_Msg_T declared? How is it declared?

    Is your error occurring on the statement
    Dim strData As Ack_Msg_T ?

    I use user defined data types such as yours to create records and have seen this error before. It occurred when I tried to pass my record in a Winsock SendData call. I had to move the record into a byte array before passing it to SendData. But this is not the same as your problem.

    Humour us and try declaring strData as Ack_Msg.

  6. #6

    Thread Starter
    New Member
    Join Date
    Jul 1999
    Posts
    8
    Hi CCoder.

    Yes. This is the same error. It occurs on a SendData sub
    of winsock control. I just remarked that line and it
    works. What is taht byte array that you use to avoid it?

    Thanks.

  7. #7
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    See my reply (sent yesterday morning) to "Needing to gather variables through Winsock".

    BTW, you will have to make Status a fixed length string or else you will have problems in your DataArrival routine. Specifically, the CopyMemory call (to move the byte array to your Ack_Msg structure will cause an error "Instruction at <some address> referenced memory at <some other address>. The memory could not be read." and VB will abend.

    What is happening is that CopyMemory is moving X number of bytes (where X = 3 + Some number of bytes for Status) into an area of memory occupied by a 3 byte string (Token) and a null string (Status).

    You may be able to get around it by initializing Status to a string of spaces large enough accomodate the longest string that the program could ever assign to it. I haven't tried this, so I don't know if it will work.

    IMHO, record structures (and the fields therein) should always have fixed lengths. This will eliminate a lot of problems, especially with regards to VB.

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