Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

I got a question

Posted on 2003-11-17
6
Medium Priority
?
286 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 500 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

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.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

618 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