I am not a vb programmer but I am attempting to code something that will read in a spool file, change a couple of words and then write it out again. It works fine when I'm not changing the length of the file but if I need to change the length of the file I'm running into problems because I'm reading it in as a chunk of data. Obviously specifying the length will not work. Is there any other way I can read this file in? See snippet of code below. Any help much appreciated.

Open Filename For Random Access Read Write As #1 Len = 30000

noDuplex = True
recordNumber = 1

Get #1, recordNumber, inputRecord

dupPosition = InStr(1, inputRecord, dupNone)
If dupPosition <> 0 Then
noDuplex = False
dupPosition = dupPosition + Len(dupNone) + 1
outputRecord = Left(inputRecord, dupPosition - 1) _
& dupSome _
& Mid(inputRecord, dupPosition + 1)
Put #1, recordNumber, outputRecord1
End If

Close #1

What exactly do you mean by a 'spool file'?

this looks all incorrect to me:

Open Filename For Random [I][B]Access Read Write[/B][/I] As #1 Len = 30000

I think 'Access Read Write' is not needed, and every time you open it you're stating that the file length is 30000.

If the file is not too large, you could read all of it in (Open For Input) and
edit it, then open the file For Output and write back the new version.
Or you may be able to store your data as records, in which case writing
back a longer chunk of text would not be a problem.
Please post back if you need any more info on this subject.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.