Solved

VB6 UDT to text output

Posted on 2010-11-24
8
777 Views
Last Modified: 2012-05-10
I am using an array of UDT to build a record, I also have a class that will write textfiles (not using put) I cannot seem to pass the UDT in, what am I missing?
Type PatientInfo
    ci As ClaimInfo 'another udt
    ID As String * 20
    AccountNo As String * 15
    FromDate As String * 10
    ThruDate As String * 10
End Type
Dim pi as patientinfo
after i fill this type in i want to write it out as simply as possible, I will actually create an array of the type then I will want to dump it to a text file.
0
Comment
Question by:cmrobertson
8 Comments
 
LVL 9

Expert Comment

by:Orcbighter
ID: 34211994
can you show the code where you pass in the udf?
0
 
LVL 17

Accepted Solution

by:
inthedark earned 500 total points
ID: 34212563
You have 3 choices how to dump your UDT record into a file.

1) A hard way using CopyMemory to copy the data from the address of PI for Len(PI) characters into a string that you already filled with blank spaces.

2) An easy way using Put.  You can use PUT to create text files.

' File Open

Dim lFile as long
lfile=FreeFile

Open "C:\MyFile.txt" for Binary Access Read Write Shared As #lFile


Dim lPos as Long

' Write Data to File loop through PI array

For lC = 0 To Ubound(PILIst)


    lPos = LOF(lFile) ' Get the current length of the file

    Put lFile, lPos, PIList(LC)

Next

Close lFile

3) Another way to use Put is to use fixed length records.

lFile = FreeFile
Open filename For Random Access Write As #lFile Len = Len(PI)

You need to keep a count of records in the file or use Lof to calculate records.

lNextRecord =1+ ( Lof(lFile)/Len(PI))

Put lFile, lNextRecord, PI


You can also read the data in the same way:

Get lFile, RecordNeeded, PI

TIP for using UDT files:

When you define your UDT give it a version number.

' new record
Type PatientInfoVNew
    ci As ClaimInfo 'another udt
    ID As String * 20
    AccountNo As String * 15
    FromDate As String * 10
    ThruDate As String * 10
End Type

' old record
Type PatientInfoVOld
    ci As ClaimInfo 'another udt
    ID As String * 20
    AccountNo As String * 15
    FromDate As String * 10
    ThruDate As String * 10
End Type

Because one day you will want to add new fields into the UDT when you do you wile have to write some code that copies the data to a new file in the new format data from VNew to VOld




0
 
LVL 45

Expert Comment

by:aikimark
ID: 34212714
A very old memory of VB had to do with the limitations in passing UDTs as routine parameter types.

What does your method definition look like?
What does your method invocation statement look like?
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 7

Author Comment

by:cmrobertson
ID: 34213717
the problem with my parameter in passing is it does not use put it uses print which will not allow the udt as its type. I was hoping for something in the way of conversion to string to flatten it out. Otherwise I will use the put method as described above. SO the passing isn't really my issue I want strvar = udtvar with whatever type converting would be needed. I suspect I cannot do it but looking to see if anyone has an idea
0
 
LVL 17

Expert Comment

by:inthedark
ID: 34213751
As I said in item 1 it can be done but it is very hard.

Put will do what you want with the need to use copymemory.
0
 
LVL 17

Expert Comment

by:inthedark
ID: 34213843
Sorry for poor English:

Put will do what you want without  the need to use copymemory.
0
 
LVL 14

Expert Comment

by:VBClassicGuy
ID: 34214804
I have been using the put and get method to write typed variables out to a binary file for years and it works great and is fast. Use inthedark's answer.

To find out how many records are in the file, I do a LOF and divide it by the record length. To add a new record, I again use LOF, and add the new record to LOF/RecordLength + 1.

Be sure to open the fie as:

Open filename For Random Access Write As #lFile Len = Len(PI)

For examples, go here and scroll down about 3/4 of the page:

http://trixar.com/~makai/minidb1.htm

0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now