Solved

TypeToString Function in VB5

Posted on 1998-04-02
4
206 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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

726 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