Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




How To Read And Write To File....Urgent


Hi,
Kindly can anybody have a solution for this....
I have a file. I need to make changes in some places of the file and write to the same file using file system object...


Example...

# That is how it is called from the "run_all" script.
#
# When developing a test, you may specify the test here so that
# you can just type "make" or "make run". The value can still
# be set (overridden) from the command line. So go ahead and
# change it as necessary.

TEST = csu02_03_05_t0001



In the above file the name after "TEST = "will be changing according to user inputs.I will have similar updations in the file. The keyword TEST will remain constant.
I need to read upto TEST = and update the necessary file name in the same file.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Read/write Problems.. Pretty Urgent!
I am trying to make an application that changes into a configfile.

Now most of the configfile will stay the same and just want to change a few rows in the middle.

My thoughts was that I could use the Input# command to first read the configfile into an array of strings, then change the array where I need to change and then use Print# to overwrite the old config file.

Problem is that the configfile uses ',' here and there so whenever the configfiles looks like this at start:




Code:
[RunningUser]
UserName=Admin

[WindowPositions]
GameLog=(X=110,Y=145,XL=512,YL=256)
ScriptLog=(X=88,Y=116,XL=512,YL=256)

It becomes this when putting the strings back


Code:
[RunningUser]
UserName=

[WindowPositions]
GameLog=(X=110
Y=145
XL=512
YL=256)
ScriptLog=(X=88
Y=116
XL=512
YL=256)



Cannot use Directfiles either.. How do I get the ',' within the strings?????? It's really urgent due to a betatest tomorrow.

Urgent!! Open (read/write) Binary .... Sharks (Solved)
Guys!!

i am intending to read the content of a jpg file... can you show me how or what is the appropriate way to open and read the jpg content out and chuck away the first 2 bytes........... and re-save them into the same jpg file(in other words, overwrite)........

]
can this be done?? below is my sample code that i tried but its not working and so far (3 weeks time) i am not able to get an understandable example to help me proceed........ i dont understand how reading a file in binary works........
Poor thing ....... please help

Dim currfile As File
Dim size As Long
Set currfile = fso.GetFile(originallocation)

size = currfile.size
ReDim a(size - 2) As Byte


Open "c: empaby.jpg" For Binary As #1
Seek #1, 3
Get #1, size - 2, a
Close (1)



Open "c: empaby.jpg" For Output As #2
Put #1, size - 2, a
Close (2)

Stop

Path/File Access Error. Unable To Read Or Write The Specified File
Hi,


I am getting the following error

"Path/File Access Error. Unable to Read or write the specified file.

Unable to Display the Image"


Following is the Code i am using .
With ImgEdit1
.Image = gStrFilePath & "" & pImagefile
.Page = 1
.Display
.FitTo 1
End With


The OS is windows 2000 and i am using ImageEdit control

the variable gStrFilePath contains the Path of the file
PImagefile contains the Image Name . Image is Tiff image.


If i click OK on the error messages the application closes. If i run the application again i am able to display the same Image.


Pls Help me

Using ADO Recordset, Read From An Access Database File And Write To A Text File
Using the ADO data control and the recordset property I am reading records from an Access data base file, selecting and manipulating records, and then trying to write to a text file. I know how to get the records from the database file, but I need sample code for how to write out to a text file.
Thanks

cruella69

Read/Write To File
Can anyone help me read and write to a file? (Source Code, Link, Anything)
Thanks

Help With Read And Write To File
here is the code for a vb project, please can someone tell me why it does not work. it highlights the lines:

write #1 name, age
and
Print #1 name, age

thank you for your help.


the code:


Option Explicit
Dim namesandages As String

Private Sub cmdaddtofileprint_Click()
Dim name As String
Dim age As String
name = txtname.Text
age = txtage.Text
Open "namesandages.txt" For Append As #1
Print #1 name, age
Close #1
txtname.Text = ""
txtage.Text = ""
txtname.SetFocus

End Sub

Private Sub cmdaddtofilewrite_Click()
Dim name As String
Dim age As String
name = txtname.Text
age = txtage.Text
Open "namesandages.txt" For Append As #1
write #1 name, age
Close #1
txtname.Text = ""
txtage.Text = ""
txtname.SetFocus

End Sub


Private Sub cmddisplayfile_Click()
Dim datatodisplay As String
Open "namesandages.txt" For Input As #1
1 stdisplayfile.Clear
Do While Not EOF(1)
Line Input #1, datatodisplay
1 stdisplayfile.AddItem datatodisplay
Loop
Close #1

End Sub

Private Sub Form_Load()
namesandages = App.Path & "
amesandages.txt"
End Sub

File Write/read
how can i add new text in text.txt every time i press command1???
i need to text be added in newline not in the old text place!!!

Code:
Private Sub Command1_Click()
Open "c: ext.txt" For Output As #1
Print #1, Text1.Text & vbCrLf
Close #1
End Sub

And my second question is about File reading! In text.txt is 3 lines of text:
first line
second line
third line

How can i make my textbox display seccond line text???
Thanx!!

Best Way To Read/write A File
Is there any other way that tends to be faster, more efficient in reading and writing from a file, else than the Open "blabla.exe" for binary as #1?

I need to use the least resources, and the fastest. Currently, i managed to get only around 100 Kb/sec or less.

I need to include a doevents when writing and reading though, to let the screen refresh.

I need this for transferring large files (through FTP), through a network (very fast connection - 100 Mbits+). Now im not utilising even 10% of my available badnwith.

I saw other ftp clients doing 4-6 Mb/sec, which is very good!

To Read And Write To Ini File
Hi All,
I am very much new to VB.Could any one of you please tell me how to read and write from ini file. It would be of great help if anyone can send me the code also.
thanks,
Shajil

File Read Write
i would like to read a raw(unformatted) textfile and output the same in
a formatted textfile.

Read Write To Same File
Can someone show me an example script on how to open a text file and write back to that same text file?

Read/write The Same File
It's possible to read and write in the same file? I have to read and maybe add some information to the file. The file is sequential (text). I don't know in what mode I have to open the file: input or output. And is the access keyword "read write"?
Some code example will help me.
Thanks.

Read/write To A File
I'm stuck with something that looks so simple from the docs....

Basicly i need 2 'commands'
a] Read a file without 'structure' Without VB6 assuming/altering things.
b] Write a file without 'structure' Without VB6 assuming/altering things.

So just a byte by byte copy.

I tried all the combinations I can find in the manual print/write/input/get/etc.
But VB6 always keeps adding a few bytes.

I searched this forum on this topic but couldnt find the answer there.
Anyone that wants to help me out on this one plz?

Kind regards.

How To Read And Write Into A File
hi,
I would like to know how to read and write into a file using vb.I am using txt files for now
thanks and regards
-sri

Read And Write To An Ini File
Hi all im very new to visual basic and am having trouble reading and writting to an ini file from a listbox i can do it with a textbox i am using the same code for a listbox and textbox but the listbox just doesnt want to save what can i do?
Thankyou in advance

File Read/write
My question is how to read and display a value of 00000. what I am doing is, to read a txt file that has a value of 00000 on the first line. Then I increment the value by 1 and write back to the same file. I am expecting to see 00001, instead, I see 1.

Does anybody how to correct this problem?

Read Write To File
i have a got some code that writes to a file below:

Open filename For Random As #fileNumber Len = recordLength

'write the record to file
Put #fileNumber, 1, myrec

'Close file
Close #fileNumber

how can i add records to the file without it erasing the records already in the file?

also how can i display this whole file in a sort of table?

Write/Read In A RES File
Hy.
I try to make an Resource editor, something that help me to manage a res file received from a client.
I was able to retrive the informations from the file and put them into two arrays id and data and after add, modify, delete elements from those arrays I try to put the two arrays id and data back to res file, but it won't work.It make me a res file but it skip some lines and I can't figure out why.
Do anyone make something like this?
How can I save the two arrays into a res file?
Please help
Thanks

How I Can Read && Write In Sam File ??
peace be with you

how i can read and write in the sam file

thanks

File Read-Write
Hello there
I want to creat an Address Book using VB 6.0. I am new to VB and I have made the application almost but I don't know the code how to Write and the Read from the File.
Can anybody help me out.

I want ot eneter the Datas as
Sr. No. | Name | Father's Name | Date of Birth | Address
thsi is how to write the file
and I want to customize while reading like if i wan to view by Serial nos then it shgould come by serial nos. if by Date of Birth then so.

File Read Write
This program opens a file .doc or .txt splits the contents on fullstops then searches each split for a word if found writes word to "results.doc
The program works reading txt files but when i open a word doc
i get an error message "input past end of file" has any one any idea why?
_______________________________________________
vb code
______________________________________________
Open "D:Datawordsearch
esults.doc" For Output As #2
Open a For Input As #1
lFileLen = LOF(1)
sText = Input(lFileLen, 1)
sSplitrec = Split(sText, ".")
For i = i To UBound(sSplitrec)
If InStr(1, sSplitrec(i), Text1.Text) Then
Print #2, sSplitrec(i)
End If
Next i
Close #1
Close #2
_________________________________________________

How To Write A File In VB6.0 And Read It In VB.net
Hello.

I need to write a list of Longs to a file in an application written in VB6.0, and then read the same file through an application written in VB.net.

Writing the file in VB6.0 I can do as follows:


VB Code:
Dim fs As Integer                        fs = FreeFile    ' Get unused filenumber.            Open strFile For Binary Access Write As #fs                                                                                    Put #fs, , lng_Data                        Close #fs


..where lng_Data is an array of longs

But how do I read this array back into memory in VB.net?
Using a binary streamreader.. I am only allowed to read byte-arrays.

In VB.net, I could serialize/deserialize the array, but that is not compatible with VB6.0.

Ideas?

best reg.
BIW

Big File Read And Write
look this code

Open "aaaa" For Binary As #1
CGW.FuJian = String(LOF(1), " ")
Get #1, , CGW.FuJian
Close #1
Open "bbbb" For Binary As #1
Put #1, , CGW.FuJian
Close #1

when file "aaaa" is a small file(i test a file size with 3K) ,code runs correct.but when file "aaa" is big(i test a file with size 300K),code run incorrect ---- file "bbbb" is bigger then file "aaaa" about 15%

why?

Write / Read From File Help Req
Hi.
I am transfering my skills from SQL to VB and need some urgent help with a very simple problem. So if anyone can help I would be very greatfull.

I need to design a simple form that collects input from the user with the following

Name age address etc. And write this to a txt file

Then read it back and display it on the form so the user can scroll though the records.

Also design a simple report from the txt file

Please note that there will be a max of 15 records in the file.


Thanks

Kevin

File Write N Read
What I need to do is accept a password and store the password at the end of a file already having some data. Later on the user should be able to retrieve the password. What I want to know is how to store the password at the end of the file. The password size would vary, so would it be necessary to store the length of the password too? How do I read the password back from the file.

I need to know this urgently

Read And Write To A File
O.K. the subject sounds like a newbie question....?
What I want to do is to have file "a" to have several lines of text with places for a variable. When file "a" is copied
into file "b" the change will happen.

example

name = "Bob"

file "a"
%name% jumped over the mountain.

output to file "b"
Bob jumped over the mountain.

I plan to have much more text and it might change so I do not want to hard code it in.

Help

Read && Write A File
hi
i want to open a file and save all of it to a variable and then to write it to a new file.
how can i do it?

File Read && Write
i am having the byte array
i have to store this byte array into the file(create file in the local machine)

send some sample code to
how to open a file in the binary mode
how to read from & write to

need help, urgent
 bala

How Do I Read && Write A CSV File In VB6
I have some CSV file with mulitple sizes I would like to Read into my VB project. This is an Example of one format.

F564,25,.00157,2000
J-00876-001,78,98,65.3

All of these are different Variables what is the best way to Read these into the Variable's that hold these Items values?

And would Writing them be much different?

Thanks
Bill

 

Write And Read To File
I am sure this has been asked before but I can't seem to find it.
I need to write multiple text, list, and multiple line text boxes to a file.
Then be able to read it back in on file open.
I can use the ini approach but it only reads single line values.

example:
name: bob
phone: smith
interests: biking
    swimming

Where interest would be from a multiline text box.
When opening file it needs to populate the boxes.
Any help would be great. Thanks

Read && Write File In Evb 3.0
Hello!
How I can read & write a file in evb 3.0?

I've try:

Private Sub Command1_Click()
Dim file1, FsModeAppend
 file1.Open "Append", FsModeAppend
 file1.lineprint "Appending..."
 MsgBox file1.LOF, , "The length is ..."
 file1.Close
End Sub

but I've received this error:

"An error was encountered while running this program: object required: file1.

Please help me as soon as possible ...
Thank you very much in advance

File Read/write
Hi I have a problem when it comes to files. The problem is as follow, I have a tekst file called "mangler.tab" in this file there is many registered barcodes whith additional information. When the user scans a barcode and the barcode is in this file i have to delete the specific line. The original text file look's something like this.
Code:60310001103 12 Ikke Ok 23.06.2003
60310001104 12 Ikke Ok 23.06.2003
60310001105 12 Ikke Ok 23.06.2003
60310001106 12 Ikke Ok 23.06.2003

and I wont to change it so it look like this
Code:60310001103 12 Ikke Ok 23.06.2003
60310001105 12 Ikke Ok 23.06.2003
60310001106 12 Ikke Ok 23.06.2003

Does anybody have a suggestion ????



Edited by - Dag on 6/24/2003 5:15:39 AM

Read And Write To File
Hi all... can any one help me on how to solve this...i need to read some data from database(MS Access)...sort the data base on one of the field and save it in text file.

Really appreciate your help...thanks.

How - INI File Read&&write?
Hi
I need to read & write ini files.
Is there is any easy way to do this with VB6 ?

Read/write File Properties
Hi everybody.
Similar to read MP3-ID-Tags, I want to read/write "tags" (file properties) from JPEG files. I want to read the properties set in the windows explorer like "title", "theme", "comment" as well as the extended information from e.g. digital cams such as "pixel-size" etc....
I don't know how to code? Is there a standard API-function?
Can anyone provide sample code?
Thx.

File Read/Write Problem
need help please:

i have a file read/write sychronization problem is VB: two VB applications (think one is client; another is server). the server is writing data into a text file every second (or as real time as possible); the client is to read data from that same text file every second (or as real time as possible).

i repeatedly run into the synchronization problem here between the VB applications. can someone help me on this??? my email is zip10021nyc@yahoo.com.

THANKS!

george.

File Read Write Problem
Hello

I am trying to write a simple program using VB's menu system to import
player files from my game to edit. I can access the file..kind of horrid like
but I cannot display the data line per line to textboxes.

Dim PrgFile As String

Private Sub mnuOpen_Click()

PrgFile = InputBox("Enter Valid File Name To Open", "Filename")

If (PrgFile = "") Then

MsgBox ("Error! Must Enter File Name!")

PrgFile = InputBox("Enter Valid File Name To Open", "Filename")

Else

Open PrgFile For Input As #1

While Not EOF(1)

Line Input #1, temp$

alltext$ = temp$

Wend


Text1(i).Text = alltext$



Close #1

End If
End Sub


any help would be great!

Thanks

Help On How To Read Certain Line From File And Write Them After
Ok here is my problem :
I got a loggin script running and it writes all the information about a computer to a text file. Now I wanna be able to retrieve informations from that text file. To do so I know that the information will be on lines that begin with some specific word. So I wanna be able to find that word after that to check after all the white space what is wirtten there, or if possible to write down that line to another text file.

Here is an example :

The text file in question look like this :
PC information for Windows 9x/NT/2000/Me version 1.30
----------------------------------------------------------------
Computer: PKB4657623E
Processor: Pentium II 450MHz (L1 cash: 32.0 Kb, L2 cash: 512.0 Kb)
Bios:
Motherboard:
Memory: 256 Mb (261 688 Kb)
User: john.doe
Domain: IT
Workgroup:
Shares: t:
v:
Mapping: p: (\NCCM01cm)

So I would like to do a search on this file so that I can write the line with the computer name, the line with the user. the line withe the user, the two lines with the shares and the mapping line, all those line I want them to be written to another text file. Also if that would be possible to do in VBScript or in .Net if you don't think so.

VB6 File Read Write Problem
Hi !

I am learning VB for a class and trying to design a simple address book for one of midterm projects.... unfortunately the program has to be in VB6 so here Iam using it ..... The program uses two forms and a file to read and write simple data for a contact in the addressbook file (.dat file)

The file seems to work fine when I and read and write data to it ..... but if I try to edit a contact from the address book and re-write it to the file the data gets jumbled up and overwritten .......

I use a .bas module which has all the data defined in a Type and two global variables used to track pointers to the these Type's in the file ... Here is the code for the .bas module ...


Code:
Type Info

strFirstName As String * 20
strLastName As String * 20
strAddress As String * 20
strCity As String * 10
strState As String * 10
strCountry As String * 10
strZip As String * 10
strPhone As String * 10
strFax As String * 10
strEmail As String * 50
strGender As String * 1
strDeleted As String * 1

End Type

Public contact As Info
Dim mIntIndex As Long
Public mIntIndex2 As Long
Here is the code which I use when the first form loads up


Code:
Private Sub Form_Load()

Open App.Path & "List.dat" For Random As #1 Len = Len(contact)
If (LOF(1) / Len(contact)) > 0 Then 'If File not Empty
For mIntIndex = 1 To (LOF(1) / Len(contact))
Get #1, mIntIndex, contact
If contact.strDeleted <> "Y" Then
Call AddtoList
End If
Next

End If
End Sub
mIntIndex is a global long variable defined a .bas module

I have another form which displays a list box with the first and last name concantenated and when I click on the member his data is displayed in the form .... here is the code when u click on name of a contact in the list box


Code:
Public Sub lst1_Click()
If (LOF(1) / Len(contact)) > 0 Then 'If File not Empty
For mIntIndex2 = 1 To (LOF(1) / Len(contact))
Get #1, mIntIndex2, contact
' Match the fist and last name and if found then exit the for loop
If InStr(lst1.Text, Trim(contact.strFirstName)) <> 0 And InStr(lst1.Text, Trim(contact.strLastName)) <> 0 Then
Exit For
End If
Next
End If
Call DisplayData
Call txtLocked
End Sub
mIntIndex2 is another global long variable in .bas module .... and subroutines Display Data Display the data in the required txt fields ... the data is locked untill u click the edit button which unlocks the data for edit .... and then u can click on "SAVE" button to write the data back to the file but when I do that it jumbles the file up ...... here is the code for editing and writing the data back to the file .....


Code:
Private Sub cmdSave_Click()
Call Form1.AddData ' This subroutine writes all the data from the textfields
' to the the contact type defined in the .bas module
Put #1, mIntIndex2, contact ' mIntIndex2 is the pointer to the record
' you want to save
Call txtLocked
End Sub

Struct File Read/write
I have a struct in vb.net like:

structure test
dim element1 as string
dim element2 as integer
dim element3 as bool
end structure

dim varTest as test


I want to write and read the whole struct variable varTest
in a file.

I already try with fileput command like

fileput(freefile,binarymodeRead,varTest)
and it looks like it work

but when I try to read de struct with fileget
fileget(freefile,binarymodeWrite, varTest)
the app give me this error

Is there another way to read/write the whole struct into or from
a file.

File/text Read/write HELP!!!
This is what I am trying to do and I think I am going about it all wrong.

I am trying to read a log file (ascii) and only want to read in certain pieces of information (e.g. a failed request for a web page) and then I want that information written to a new file.

I wont even attempt to post thw code I have trying to work with, if someone can give me some pointers of post some example, I would really appreciate it.

Text File; Read/Write, HELP
Hi,
Sorry, this is not an answer but can you elaborate on how to use text files in VB to read or write to them? I know how to to interact with word or excel files;by inculding reference to excel object.But in case of text files what do reference we include?
Thanks.

Edit: Please dont hijack other member's threads

Read/Write INI File In VBScript?
Help..
I'm wanting to read (and possibly write) ini files in VBScript.
I've used the GetPrivateProfileString in VB 6.0 but this doesn't work in VBScript.
Is there an easier way than just opening as a text file and parsing all the lines??

Text File; Read/Write, HELP
Hey
I need some help writing/reading text files in my program. I have this code, but it works only for writing and reading 1 time. I want this to be able to write and read like 10 text boxes. Please help. Thanks
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Private fso As New FileSystemObject
Private strName As String
Private Sub Form_Load()
On Error GoTo a
With fso
strName = Text2.Text & "" & Text3.Text
Set strm = .OpenTextFile(strName, ForReading)
With strm
Do Until .AtEndOfStream
Text1.Text = Text1.Text & .ReadLine & vbCrLf
Loop
End With
End With
Exit Sub
a:
MsgBox "error occured"
End Sub
Private Sub Command1_Click()
With fso
strName = .BuildPath(Text2.Text, Text3.Text)
Set strm = .CreateTextFile(strName, True)
strm.Write (Text1.Text)
End With
MsgBox "Text Saved"
Exit Sub
a:
MsgBox "error occured"
End Sub

File Read Write Wait
I have my part of application that reads a file to wait for other part of application that writes so that i have valid data to be retrieved how could i wait for something like that
-srikant

Read/Write A File Probleam?
Code:
'to write
Open "C:lol.ini" For Output As #1
Print #1, "1338" 'I can use "Write" too.
Close #1

Code:
'to read
Open "C:lol.ini" For Input As #1 LOLFILE.COOL
Line Input #1, domainname 'domainname is a varible
Close #1
Now I have tried "Print #2" to print/write on line 2 on lol.ini but it won't work.
So how do I read that where I can read a Line number and put what ever that line has on it into a varable? And how to write & overwrite to a Line number?
All help is welcomed thanks.

File Read And Write Manuplating Help
Hi all Im new to visual basic well I havent done much with it. I have VB 6 and Im having trouble writing out data that I have read in.

1.Im trying to open a text file.
2. I want to remove all lines that start with the letter H
3.Then I want to make a new file Exactly as the original spaces, new lines and all except for the lines with the H's

Here is some code Ive tried but it writes the new file in long lines(completely different) and when I use mid it only writes 1 line of the file.
note the p190 is a text file.

Private Sub Command1_Click()
Open "c:ANAV28230361057C.0.p190" For Input As #1
Open "c:ANAVMaster.txt" For Output As #2
While Not EOF(1)
Line Input #1, temp$
Print #2, temp$
Rem x$ = Mid$(temp$, 1, 1)
Rem If x$ <> "H" Then Print #2, Mid$(temp$, 1, 80)
Rem Print #2, temp$
Rem Write #2, Mid$(temp$, 1, 80)
Rem Print #2, Mid$(temp$, times, 80)
Wend
Close #2
Close #1
End Sub

Eventually I want to read in 25 different files strip the lines with H and put them all into a single text file.
Any help is greatly appreciated. Im just stuck here. Im not new to programming just new to VB.
Thanks in advance.

Can You Read/write To A Packed File?
Ok, I'm working on a client/server program. The client is suppose to be able to read the server and edit it, then copy the changed server. I want to include and automatic pack when the server is copied.

My Question is can the client read that server and edit it after it has been packed ?

Simultaneous File Read And Write
I would like to explore the possibility of writing code that would allow a file to be written by a graphics card say an avi and by another card simultaneously read from the same file, in a continous loop, much like a cache.
I expect to use a count to indicate when and where the file should be read at the tail end of the file as well as when the write should start to overwrite old data to be constantly updated.

If writing a cache pgm is ideal then can this be done with a ram disk ? All help appreciated - Jim

Copyright © 2005-08 www.BigResource.com, All rights reserved