Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exporting (fixed-width) to text file 2

Status
Not open for further replies.

zyrag

IS-IT--Management
Dec 4, 2002
252
PH
Hi,

I been trying to export records to a text file. I have tried the techniques presented in the MSDN "Using Random Access File" - Using the combination user-defined type with fixed size fields, the Open statement for random access and the Put command to write the contents of the user-defined type variable. My problem with this approach is that i dont get how to write the next record to the next line on the file. I tried to insert chr(13)+chr(10) after each Put statement
Code:
Type DTR
Period as String * 10
Emp_ID as String * 6
:
:
end Type
Code:
Open Filename For Random As #FileHandle Len=Len(My_DTR)
Code:
Put #FileHandle,,My_DTR
Put #FileHandle,,chr(13)+chr(10)

but could not work it out.

I resorted to trying the Export feature of the DataReport but my problem is i don't know how much twips is equivalent to 1 character. Does anyone knows how much twips? Do you have some tips for this method of exporting fixed-width record to a text file?

OR,

Can anyone share code snippets to for this purpose?

I would highly appreciate if you could share some tips and techniques.

TIA

 
1. With fixed length strings there are no delimiters required so you don't need the chr(13) etc.

2. Make sure your Type declaration is in a code module (Project|Add Module)

3. Use the Freefile function to get a new file handle

4. I just tested this snippet to make sure it works. This goes in a new module:
Code:
Type DTR
Period As String * 10
Emp_ID As String * 6
End Type

This goes in a form with two command buttons and a textbox with its Multiline set to True:
Code:
Private Sub Command2_Click()
Dim my_dtr As DTR
Dim FileHandle As Long
FileHandle = FreeFile
Dim intA As Integer
Open "c:\test\myfile.x" For Random As #FileHandle Len = Len(my_dtr)


For intA = 1 To 5
my_dtr.Period = String(10, Chr(65 + intA))
my_dtr.Emp_ID = String(6, Chr(48 + intA))
Put #FileHandle, , my_dtr
Next intA
Close #FileHandle
End Sub

Private Sub Command1_Click()
Dim FileHandle As Long
FileHandle = FreeFile
Dim strAdd As String
Dim my_dtr As DTR
Dim intA As Integer
Open "c:\test\myfile.x" For Random As #FileHandle Len = Len(my_dtr)
For intA = 1 To 5
Get #FileHandle, , my_dtr
strAdd = strAdd & my_dtr.Period & vbTab & my_dtr.Emp_ID & vbCrLf
Next
txtmyType.Text = strAdd
Close #FileHandle

End Sub

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'If we're supposed to work in Hex, why have we only got A fingers?'

for steam enthusiasts
 
You can always add a 2-char "filler" field at the end of your Type declaration. Then set this field to vbNewLine wherever you DIMension an instance of the UDT.
 
zyrag - 2 questions:
a) Had you considered the TransferTextmethod?
b) What have twips got to do with things?
 
The combination of johnwm's and dilettante's techniques seems to me could be the working solution to my problem. I shall continue experimenting with.

DrSimon, TransferText is a method of what object?
Twips is the unit of measure used with DataReport. 1 inch=1440 twips and I need to know how much twips is equivalent to a character, see a space char, so I could calculate how much should be the width (plus a space char, being the delimiter, after each RptTextBox control) of the RptTextBox in a report.

Thanks to you guys, I really appreciate your help.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top