Solved

I got a question

Posted on 2003-11-17
6
277 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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 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 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…

762 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