Solved

I got a question

Posted on 2003-11-17
6
278 Views
Last Modified: 2010-05-01
How to accept  data from a user and add the the information to a plain text file?

data should be like this :

                         FirstName LastName Major Phone GPA

And user can search information by FirstName,LastName or Major

The most confused point for me is add the information to a text file.
Is it use IO.StreamReader.------------- ?

0
Comment
Question by:gegou
6 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9766852
Shouldn't you use a database? it is better.
0
 
LVL 1

Accepted Solution

by:
danmian earned 125 total points
ID: 9766996
that's easy. tell me: how is this user sending the data?

I can write an example code, but I wonder how do you recive the data.

any way here is some code to text file operation.

add a command button, called Command1 to a form. and write this:

Private Sub Command1_Click()
Dim NumFile As Integer
NumFile = FreeFile()
Open "C:\TEST.TXT" For Output As #NumFile  ' open the file for input operations.
  Write #NumFile, "Hola mundo", 234 ' taex values use " " numeric don't.
  Write #NumFile, ' blank line.
 
  Dim MyDate
  MyDate = #2/12/1969#
  Write #NumFile, MyDate; "this is a date value"
Close #NumFile  ' Close the open file.
End Sub


this would give you an Idea.


bye :o)

0
 

Expert Comment

by:deepakshi
ID: 9768898
See, it's simple. Suppose the filename is "mydata.txt"

Add a reference to Microsoft Scripting Runtime library in your project. Now write the following code


Dim FSO as FileSystemObject
Dim TS as TextStream

Set FSO = new FilleSystemObject
Set TS = FSO.OpenTextStream("c:\myfile.txt")

now you can start writing data as

TS.WriteLine "This is my data"

Writeline automatically shifts the focus to next line. To put the first name, etc,

You can give each field a specified max length. and then write then in same line using writeline. Alternativelly, you can use Write function of TS to write the values in same line but do not forget to write the last field value using Writeline to bring cursor on next line after writing data.

When you need to search information, use readLine or read function.

If you have specified a max length for each field, say 80 characters for first name, you can take first 80 characters of the line read and check if it matches with what u r searching for.

If you are working on a new file, use the following code to close and save the file.

     TS.Close
      Set Ts = nothing
      Set FSo = nothing

Hope this helps.

With regards
Deepakshi


0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:gegou
ID: 9772379
I can not use database
0
 
LVL 3

Expert Comment

by:ashoooo
ID: 9782335
Just append the line of text to the existing file.
0
 

Expert Comment

by:steveresch
ID: 10538315
How does one do this:

"Add a reference to Microsoft Scripting Runtime library in your project"
 
 as deepakshi suggests?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
add text to end of existing text in file 16 69
Updates not working for MS Windows 7 12 153
Add and format columns in vb6 7 47
vb6 - Transfer from MSHFlexgrid1 to xls issue 8 47
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

867 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

21 Experts available now in Live!

Get 1:1 Help Now