Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB6 UDT to text output

Posted on 2010-11-24
8
Medium Priority
?
824 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
[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
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 2000 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 46

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
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This collection of functions covers all the normal rounding methods of just about any numeric value.
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

604 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