View Full Version : I need help with VB (visual basic)
I'm making a tool but I need to a few things in VB before I can do it. I know a little bit in VB but I can't figure out how to do this:
1. Open a text file and scan it for one line of code. When this code is found I want to put two lines of information into the next available blank line.
2. Open a text file and scan it for one line of code. When this code is found I want to go up one line and put in two lines of information.
Anyone know how to do this? I would REALLY appreciate any help. Thank you http://www.totalwar.org/forum/non-cgi/emoticons/gc-smile.gif
Lord Xelous
03-01-2004, 16:30
I've got to go out in a a moment, but when I come back I'll write you this code.
Lord "Programmer" Xelous.
Lord Xelous
03-01-2004, 18:34
*This code is MS-Visual Basic 6 compliant* (I hope)
Function FindLineAndAddTwoAfter (FileName As String, NewFilename As String, FindMe As String, AddLine1 As String, AddLine2 As String)
Open Filename For Input As #1
Open NewFilename For Output As #2
Do Until EOF (#1)
Line Input #1, A$
Print #2, A$
If A$ = FindMe Then
Print #2, AddLine1
Print #2, AddLine2
EndIf
Loop
Close #1
Close #2
End Function
After this you will have 2 files.. the original and a new one with your 2 add lines added in after the fineme string.
You can use the Change function to change the names of the orignal file to somethign else then rename your new one for
use to replace into the MTW engine.
The second function you want is similar we just defer the Print #2, A$ until after we've compared the current read line
Function FindLineAndAddTwoBefore (FileName As String, NewFilename As String, FindMe As String, AddLine1 As String, AddLine2 As String)
Open Filename For Input As #1
Open NewFilename For Output As #2
Do Until EOF (#1)
Line Input #1, A$
If A$ = FindMe Then
Print #2, AddLine1
Print #2, AddLine2
EndIf
Print #2, A$
Loop
Close #1
Close #2
End Function
I think these should work for you, but I've not tried them.... any troubles give me a shout.
Lord Xelous
Thanks I'll give that a go after dinner. http://www.totalwar.org/forum/non-cgi/emoticons/cheers.gif
vBulletin® v3.7.1, Copyright ©2000-2025, Jelsoft Enterprises Ltd.