(urgent - please help) reading and writing in a text file using VB

(urgent - please help) reading and writing in a text file using VB

Post by mike » Tue, 27 Apr 1999 04:00:00



Hi,

I need to write 5 words in a text file without owerwriting the existing
words.
each word must be separated by a coma.

a file contains :

mike;mikie;22;france;student
flora;florie;19;spain;employee

i need to insert : name;surname;age;country;job

then it will be like this  :

name;surname;age;country;job
mike;mikie;22;france;student
flora;florie;19;spain;employee

but the program has to detect if the first line
(name;surname;age;country;job) is already inserted. If it is, vd does
nothing. if not, then vb inserts this line without overwriting the other
lines.

please help. very important for me. thanks. mike

 
 
 

(urgent - please help) reading and writing in a text file using VB

Post by Andrew Merisan » Tue, 27 Apr 1999 04:00:00


Hi  Mike,

There are a couple of ways to do this.

here is one way

Private Sub CheckFile(ByVal FilePath As String)
    Dim iFnum as Integer
    Dim iPos    as Integer
    Dim strFileText As String

    iFnum = FreeFile

    Open FilePath For Input As iFnum
    strFileText = Input(LOF(iFnum),#iFnum)
    Close #iFnum

    If Len(strFileText ) <> 0 then
        iPos = Instr(1,strFileText,"name;surname;age;country;job")
        If iPos = 0 then
            strFileText = "name;surname;age;country;job" & vbCrLf &
strFileText
        End If
        iFnum = FreeFile
        Open FilePath For Output As iFnum
        Print #iFnum, strFileText
        Close #iFnum
    End If
End Sub

Regards,

Andrew

 
 
 

(urgent - please help) reading and writing in a text file using VB

Post by Donny McCo » Wed, 28 Apr 1999 04:00:00


open the file for append.

>Hi,

>I need to write 5 words in a text file without owerwriting the existing
>words.
>each word must be separated by a coma.

>a file contains :

>mike;mikie;22;france;student
>flora;florie;19;spain;employee

>i need to insert : name;surname;age;country;job

>then it will be like this  :

>name;surname;age;country;job
>mike;mikie;22;france;student
>flora;florie;19;spain;employee

>but the program has to detect if the first line
>(name;surname;age;country;job) is already inserted. If it is, vd does
>nothing. if not, then vb inserts this line without overwriting the other
>lines.

>please help. very important for me. thanks. mike

 
 
 

1. Reading from a text file and writing toa text file from Vis Bas 6.0

Hi guys,
I am using Visual Basic 6.0
I would like a routine to read one line at a time from a text file.
It might be the first line or 5th line or what ever line.

I would also like to know how to write back to a particular line in the same
way.
Say the 2nd line or the 6th line or whatever.

Am I asking too much?

From a Vis Bas 6 beginner

Kevin Rea


2. sum of fields within multiple records by specific field

3. reading & writing to text files using java

4. KS-Overland Park-43532--Mainframe-Programming Skills-MVS-COBOL-CICS-JCL-DB2-QMF-

5. Reading/Writing to text file using ADO

6. ADO and Excel HELP

7. Write Text File to XBASE database using VB

8. HELP on open text file in read/write mode

9. text file processing - read/write comma delimited text

10. URGENT HELP PLEASE--Tool to parese and read Flat Dat file

11. Help me with reading/writing records to a file (vb newbie)