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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to print data from a file on a listbox(using sequential file proce 1

Status
Not open for further replies.

JPirate

Programmer
Aug 11, 2003
44
0
0
PR
I want to know how to print on a form (listbox) some data i have stored using "sequential file procesing" in a file with a .dat extention... i would like to take that data and print it in my aplication form listbox , any code example would help... , its all text.. so i think i need a loop to do it ....
 
What have you so far ?
Where are you stuck ? reading the file or populate the listbox ?
Here an example for reading sequential file:
Code:
Open "\path\to\file.dat" For Input As #1
Do While Not EOF(1)
    Line Input #1, TextLine
    MsgBox TextLine
Close #1
To "print" data in your listbox, take a look at the AddItem method.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
this is what i have so far:
'Writing to a sequential text file
Option Explicit
Dim mFileSysObj As New FileSystemObject
Dim mFile As File
Dim mTxtStream As TextStream

Private Sub cmdWrite_Click()
'Write the data to the file
Call mTxtStream.WriteLine(mskSegSocial.Text & " " & _
txtNombre.Text & " " & _
txtCalle.Text & " " & _
txtPueblo.Text & " " & _
txtCodigoPostal.Text & " " & _
txtTelefono.Text & " " & _
txtEdad.Text)

'Clear MaskEdit and TextBoxes
txtNombre.Text = " "
txtCalle.Text = " "
txtPueblo.Text = " "
txtCodigoPostal.Text = " "
txtTelefono.Text = " "
txtEdad.Text = " "
'Set several properties for mskAccount
'using With Statement
With mskSegSocial
.Text = "000000000" 'Display all zeros in MaskEdit
.SelStart = 0 'Start highlighting at position 0
.SelLength = 9 'Highlight 9 characters
.SetFocus 'Transfer focus
End With
End Sub
Private Sub Form_Terminate()
Call mTxtStream.Close 'Close the text stream
End Sub

Private Sub Form_Load()
'Create a text file
Call mFileSysObj.CreateTextFile("c:\pacientes.dat")

'Once file is created, reference the file
Set mFile = mFileSysObj.GetFile("c:\clients.dat")

'Open a text stream for writing to the file
Set mTxtStream = mFile.OpenAsTextStream(ForWriting)

'Display path in lblFileName
lblFileName.Caption = mFile.Path

End Sub

:)

NOW: what i want to do is... to create a listbox or a text box... which prints all the Records from this clients.dat file .... I need a loop wich reads all of theese and prints them in my aplication form or (box).

Later I will want to know how to print an especific record :)

 
There are some errors on that code... dont mind them.. i already fixed them... ... but you get the idea of what i want to do.... dont you?
 
To read the file:
Code:
Set mFile = mFileSysObj.GetFile("c:\clients.dat")
Set mTxtStream = mFile.OpenAsTextStream(ForReading)
Do While Not mTxtStream.AtEndOfStream
   myRecord = mTxtStream.ReadLine
   MsgBox myRecord
Loop
mTxtStream.Close
To "print" data in your listbox, take a look at the AddItem method.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884
 
what reference library do you need to include in the project to access the object types of FileSystemObject, TextStream, and File.

I want to open a file, append text and save it to a new location. My problem is I cannot declare my vairables with the proper objects.

Jason Meckley
Database Analyst
WITF
 
You have to reference Microsoft Scripting Runtime.

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top