[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 288
  • Last Modified:

I got a question

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
gegou
Asked:
gegou
1 Solution
 
Richie_SimonettiIT OperationsCommented:
Shouldn't you use a database? it is better.
0
 
danmianCommented:
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
 
deepakshiCommented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
gegouAuthor Commented:
I can not use database
0
 
ashooooCommented:
Just append the line of text to the existing file.
0
 
stevereschCommented:
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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now