Solved

TypeToString Function in VB5

Posted on 1998-04-02
4
203 Views
Last Modified: 2006-11-17
The TypeToString function uses the copytype.dll with the following parameters:  address of the type, return string, bytes to return.  For instance, I create a user-defined type that contains 3 variables, each of which are strings of 10 bytes.  When I call the TypeToString function, I will pass this type (automatically by reference), a string variable name, and 30 (number of bytes to return).  While I can use this function without issue in VB 3.0 and 4.0, I cannot in VB 5.0.  I would guess that the copytype.dll is only 16-bit and incompatible.  Regardless, I would like to know if VB 5.0 offers the equivalent functionality.

I appreciate your time and attention to this matter.
-David
0
Comment
Question by:dfhaines
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Accepted Solution

by:
mirk earned 100 total points
ID: 1460265
Ok, the *easiest* way to do this in VB5, is to use
the LSET function, but this means you have to create
another User Defined Type to "copy" the strings into, like
this: Lset TypeWith1StringOf30Chars = TypeWith3StringsOf10Chars

Another way to do it would be to write the type to a file,
then read it back into your string.

Hope this is helpful - Mirk.
0
 
LVL 8

Expert Comment

by:mrmick
ID: 1460266
Mirk, LSet would only work in this manner when copying fixed length strings because strings variables not of a fixed length contain pointers to string data.  LSet can be used to copy a  structure (a number of bytes beginning at the offset of the first element) to another structure; however, VB won't copy data referred to by pointers.

dfhaines, you might find it easiest to write a VB function for each different structure (type) that packs its data into a string and perhaps a complementary UnPack function to re-populate the structure from the data packed into a string).

0
 

Author Comment

by:dfhaines
ID: 1460267
Mirk,
Thank you for your quick response.  The LSET function was sufficient and your advice helped automate a previously manually-intensive production task.  I do wonder, though, if the TypeToString function will be written for VB 5.0.  Perhaps you would agree that it would be a more efficient way to copy types to strings and would require less overhead.
Thanks again,
David
0
 

Expert Comment

by:mirk
ID: 1460268
Yes, David, I agree... but thinking about it, another answer
could be to use a memory-copy function from the KERNEL...
My feelings are that this would be dangerous though.

Glad to have helped - Mirk


0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question