|
-
Jul 21st, 2001, 06:57 PM
#1
Thread Starter
Lively Member
Text file manipulation
Ok guys, I'm sure this isn't a tough one either...
I need to open a text file, search for a version number, increment the version number, then close that file. Is there an easy way to do this. The version number could be anywhere in the file and the text file is fairly large, so I'm not sure if I can fit it all in one large string. Let me know what you guys think. Thanks a ton!!
Jacob
-
Jul 21st, 2001, 07:07 PM
#2
Thread Starter
Lively Member
...one more thing
I forgot to add that my program has a log file so it knows the old version number to search for. Thankk you, any help will be appreciated!!
Jacob
-
Jul 21st, 2001, 08:07 PM
#3
PowerPoster
do until EOF
Open file1 for input as #1
Open file2 for output as #2
Line Input #1, some_string_variable
if left(some_string_var, 7)="version" then
print #2, "Version =" & new_version_number
else
print #2, some_string_var
end if
Loop
Close #1
Close #2
kill file1
rename file2 file1
This is an algorithm (not real code) and assumes the word Version precedes the version number and is the first word of whatever line it is on.
If the version id can occurr anywhere on the line (not just the first word), then you have a different provblem. In this case you might have to read in one word at a time till you find the version #.
Hope this helps
Last edited by Muddy; Jul 21st, 2001 at 08:14 PM.
-
Jul 21st, 2001, 08:40 PM
#4
PowerPoster
btw be careful with the kill statement.
It might be smarter to rename file1.whatever to file1.bak instead just in case things don't go smooth (you will have a copy of the original file)
-
Jul 21st, 2001, 09:00 PM
#5
PowerPoster
just thought of something easier
add the richtextbox control to your project
VB Code:
richtextbox1.loadfile ("C:\filename")
richtextbox1.find ("version")
richtextbox1.sellength=x 'make sure x is just enough to
'cover the number of characters you
'want to change
richtextbox1.seltext = "Version xxx" 'xxx is the new version
'number
now the richtext box contains the updated filetext which you can use to write a new file. Doesnt matter where Version Number is. You might run into a problem is the version numbers can have different nyumbers of characters (1, 10, 100, etc)
anyway another option for you. hope it helps!
-
Jul 23rd, 2001, 01:44 PM
#6
Thread Starter
Lively Member
Thank you
I really liked the way that the richtextbox control worked, however, when I save the file and open it again with notepad, it has all kinds of "junk" characters that I cannot allow to be in the file, for the file I'm modifing is the batch file that I plan on running once I update the version number. Any ideas on how to prevent VB from writing the extra crap to the file, or any other ideas?
I really appreciate your help,
thank you,
Jacob
-
Jul 23rd, 2001, 01:59 PM
#7
PowerPoster
are you using something like this to save the updated file:
Print #1 richtextbox1.text
??
-
Jul 23rd, 2001, 02:35 PM
#8
Thread Starter
Lively Member
Well, should I be using the print statement?
What I did was this:
RichTextBox1.SaveFile (sFile1)
When I tried the print statement, it just printed to the screen and not the file.
Thank you,
Jacob
-
Jul 23rd, 2001, 02:39 PM
#9
PowerPoster
try this
filename = "C\:whatever.txt"
open filename for output as #1
print #1, richtextbox1.text
close
this is off the top of my head so there may be syntax errors.
let me know if it works.
-
Jul 23rd, 2001, 02:51 PM
#10
Thread Starter
Lively Member
Success
Great, thanks a lot, that did the trick. Thank you!
Jacob
-
Jul 23rd, 2001, 02:55 PM
#11
PowerPoster
glad to help!
I guess you noticed that the last line of code should have been
Close #1
instead of
Close
-
Jul 23rd, 2001, 02:58 PM
#12
Thread Starter
Lively Member
yeah, i got that, thank you!
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
|