Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
OPEN <path to file> FOR RANDOM LOCK WRITE AS <file handle>
This is first line
of text
[blue]change this[/blue]
last line
Dim strTextLine As String
Open App.Path & "\TextFile.txt" For Input As #1
Open App.Path & "\TextFileOut.txt" For Output As #2
Do While Not EOF(1)
Line Input #1, strTextLine
If strTextLine = [blue]"change this"[/blue] Then
Print #2, [blue]"to that"[/blue]
Else
Print #2, strTextLine
End If
Loop
Close #2
Close #1
Dim FirstTenStr as string
FileNo = FreeFile
sFile = "c:\BANK OF AMERICA DIRECT DEPOSIT FILE FOR TRANSMISSION\HTTP ACH PAYRLR CAFR1031"
Open sFile For Input As FileNo
FirstTenStr = Input(10, FileNo)
Close FileNo
Option Explicit
Public Sub ChangeFileText()
Dim FirstLineStr As String
Dim strTextLine As String
Dim sFile As String
Dim TempFile As String
Dim NewFirstString As String
Dim NewLineEntered As Boolean
sFile = App.Path & "\my.txt"
TempFile = App.Path & "\temp.txt"
NewLineEntered = False
Open sFile For Input As #1
Line Input #1, FirstLineStr
Close #1
'comment this out for real thing this is
'just to quickly display string changes
Text1.Text = ChangeString(FirstLineStr, " ", "1")
NewFirstString = ChangeString(FirstLineStr, " ", "1")
'now using Andrzejek method rewrite the file
Open sFile For Input As #1
Open TempFile For Append As #2
Do While Not EOF(1)
Line Input #1, strTextLine
If NewLineEntered = False Then
Print #2, NewFirstString
NewLineEntered = True
Else
Print #2, strTextLine
End If
Loop
Close #1
Close #2
'and lastly rename and remove temp file
Kill sFile
Name TempFile As sFile
End Sub
Private Sub Command1_Click()
ChangeFileText
End Sub
Public Function ChangeString(StrToChange As String, ChartoFind As String, ReplacementChar As String) As String
'the instr function will find the first occurance of ChartoFind
'if u need to replace all occurances use the commented out replace method
Dim foundLoc As Long
foundLoc = InStr(StrToChange, ChartoFind)
If foundLoc >= 0 Then
ChangeString = Mid(StrToChange, 1, foundLoc - 1) & ReplacementChar & Mid(StrToChange, foundLoc + 1, Len(StrToChange) - foundLoc + 1)
Else
End If
'method to replace all spaces with ones
'ChangeString = Replace(StrToChange, ChartoFind, ReplacementChar)
End Function
Private Sub Form_Load()
Command1.Caption = "Change File"
Text1.Text = ""
End Sub