|
-
Dec 5th, 2000, 08:23 AM
#1
Thread Starter
Hyperactive Member
If i'm opening a text file for editing and i want to take
text line by line and edit it, how do i put the text back
into the file line by line after I have edited it?
Bababooey
Tatatoothy
Mamamonkey
-
Dec 5th, 2000, 08:31 AM
#2
_______
<?>
didn't test this code but it should be all you
need to get you going.
Load your file into an array
Edit your lines
then load the array into the file
Open myfile for input as #1
dim i as integer
dim myArray()
Do while not eof(1)
redim preserver myArray(i)
line Input #1,myArr(i)
i = i + 1
loop
close #1
You now have all your lines in an array
to edit line three
text1 = myarr(2)
edit the line then some button
myArr(2) = text1
when done playing
open yourfile for output as #1
for i = lbound(myarr) to ubound(myarr)
print #1, myarr(i)
next
close #1
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Dec 5th, 2000, 09:26 AM
#3
_______
<?>
Code:
' Sorry, it's monthend and just because they pay me to work
' they expect me to work...really...lol
'here is a basic version of edit
'need 1 listbox and 1 command button
'List1 Command1
'one file called myFile.txt stored in C:\My Documents
'need one bas module with this code in it
Public myArr()
'******************this is your form code
Option Explicit
Public myNum 'used to store array number based on list1 index
Private Sub Form_Load()
Dim myFile As String
myFile = "C:\my documents\myfile.txt"
Open myFile For Input As #1
Dim i As Integer
Do While Not EOF(1)
ReDim Preserve myArr(i)
Line Input #1, myArr(i)
List1.AddItem myArr(i)
i = i + 1
Loop
Close #1
End Sub
Private Sub Command1_Click()
List1.Clear
Dim i As Integer
Dim myFile As String
myFile = "C:\my documents\myfile.txt"
myArr(myNum) = Text1.Text
Open myFile For Output As #1
For i = LBound(myArr) To UBound(myArr)
Print #1, myArr(i)
Next
Close #1
List1.Clear
'Refresh
Call Form_Load
End Sub
Private Sub List1_Click()
Text1 = List1.Text
myNum = List1.ListIndex
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Dec 5th, 2000, 09:40 AM
#4
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Dec 5th, 2000, 10:36 AM
#5
Thread Starter
Hyperactive Member
hmmm
All this seems really helpful, unfortunately, I forsee a few problems......
This program needs to parse each line in the text file
and see if a certain string exists in it from a database.
If it does, it is edited accordingly based on other info
from the database.
The database is huge and the text file is about a meg of raw text.
The text file must retain it's structure.
So.......
I'm trying to make it as fast as possible, while retaining
the original structure (line for line) of the text file,
make all this totally automated (no user interaction), and
of course maintain data integrity. Therefore, I'm shakey
about using a listbox as it will automatically alphabetize
the strings and I don't want the user to have to update and
edit anything.
Thank you in advance for your help
P.S. Bababooey
Bababooey
Tatatoothy
Mamamonkey
-
Dec 5th, 2000, 01:09 PM
#6
Thread Starter
Hyperactive Member
thx
Thank you for all your help.
When I originally encountered this endeavor, I realized
that it would probably be a slow process. I thought that I
would use a method similar HeSaidJoe's method except it
would parse the data line for line without using arrays.
I was just wondering if there was an alternate and faster way.
Since this part of the program is completely automated and
no user input is necessary, I guess I can sacrifice speed at
the expense of accuracy. Thanks again for the help though 
Bababooey
Tatatoothy
Mamamonkey
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|