Solved

I got a question

Posted on 2003-11-17
6
283 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
[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
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

726 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