What I'm trying to do is look for a string in a file. If it's not there, add it. It it is there, replace it with a new one. I seem to be doing something wrong....
Dim Autobat As Long
Dim aryByt() As Byte
Dim strFile As String
Autobat = FreeFile
Open "C:\Autoexec.bat" For Binary As #Autobat
ReDim aryByt(LOF(Autobat))
Get #Autobat, , aryByt
strFile = StrConv(aryByt, vbUnicode)
Close #Autobat
If InStr(1, strFile, Left("SET %INST=", 11), vbTextCompare) = 0 Then
Autobat = FreeFile
Open "C:\Autoexec.bat" For Append As #Autobat
Print #Autobat, "SET %INST=" + Left(drvInstall.Drive, 1)
Close #Autobat
Else
If InStr(1, strFile, Left("SET %INST=", 11), vbTextCompare) = 1 Then
Autobat = FreeFile
Replace(Left("SET %INST=", 11), Autobat, "SET %INST=" + Left(drvInstall.Drive, 1))
Print #Autobat, "SET %INST=" + Left(drvInstall.Drive, 1)
Close #Autobat
End If
End If
Dim Autobat As Long
Dim aryByt() As Byte
Dim strFile As String
Autobat = FreeFile
Open "C:\Autoexec.bat" For Binary As #Autobat
ReDim aryByt(LOF(Autobat))
Get #Autobat, , aryByt
strFile = StrConv(aryByt, vbUnicode)
Close #Autobat
If InStr(1, strFile, Left("SET %INST=", 11), vbTextCompare) = 0 Then
Autobat = FreeFile
Open "C:\Autoexec.bat" For Append As #Autobat
Print #Autobat, "SET %INST=" + Left(drvInstall.Drive, 1)
Close #Autobat
Else
If InStr(1, strFile, Left("SET %INST=", 11), vbTextCompare) = 1 Then
Autobat = FreeFile
Replace(Left("SET %INST=", 11), Autobat, "SET %INST=" + Left(drvInstall.Drive, 1))
Print #Autobat, "SET %INST=" + Left(drvInstall.Drive, 1)
Close #Autobat
End If
End If