Public Sub ModifyCustomList(ByVal CustomList As String, ByVal StringToMofify As String, ByVal CLText As String, CLDescription As String, CLImg As String) Const ForReading 1: Const ForWriting 2 Dim objFSO, objFile, allLines, arrLines, x GiveLineNumberForString CustomList, StringToMofify 'RRSDK.SetUserVar "StringToMofify", StringToMofify & " --> " & ReturnedLineNumberForString Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(CustomList, ForReading, True, -1) 'http://forums.aspfree.com/code-bank-54/classic-asp-vbscript-write-into-specific-line-text-file-92390.html allLines = objFile.ReadAll arrLines = Split(allLines, vbCrLf) arrLines(ReturnedLineNumberForString) = "LST" & CLText & "||" & CLDescription & vbCrLf arrLines(ReturnedLineNumberForString + 1) = "ICO" & CLImg & vbCrLf Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(CustomList, ForWriting, True, -1) For x = 1 To UBound(arrLines) If x = ReturnedLineNumberForString Then objFile.Write (arrLines(ReturnedLineNumberForString)) End If If x = ReturnedLineNumberForString + 1 Then objFile.Write (arrLines(ReturnedLineNumberForString + 1)) End If If x < ReturnedLineNumberForString Or x > ReturnedLineNumberForString + 1 Then objFile.Write (arrLines(x) & vbCrLf) End If Next objFile.Close End Sub
Private Sub DeleteCustomList(ByVal CustomList As String, ByVal StringToDelete As String) Dim lines As New List(Of String)(IO.File.ReadAllLines(CustomList)) 'Remove the line to delete, e.g. lines.RemoveAt(GiveLineNumberForString(CustomList, StringToDelete)) lines.RemoveAt(GiveLineNumberForString(CustomList, StringToDelete)) IO.File.WriteAllLines(CustomList, lines.ToArray(), Encoding.Unicode) End Sub Private Sub ModifyCustomList(ByVal CustomList As String, ByVal StringToMofify As String, ByVal CLText As String, CLDescription As String, CLImg As String) 'SDK.SetUserVar("StringToMofify", StringToMofify & " --> " & GiveLineNumberForString(CustomList, StringToMofify)) Dim allLines = File.ReadAllLines(CustomList) allLines(GiveLineNumberForString(CustomList, StringToMofify)) = "LST" & CLText & "||" & CLDescription allLines(GiveLineNumberForString(CustomList, StringToMofify) + 1) = "ICO" & CLImg File.WriteAllLines(CustomList, allLines, Encoding.Unicode) End Sub Public Function GiveLineNumberForString(ByVal FileName As String, ByVal someString As String) As Integer Dim lines As String() = File.ReadAllLines(FileName) Dim found As Integer '= -1 For i As Integer = 1 To lines.Length If lines(i).Contains(someString) Then found = i Exit For End If Next Return found End Function
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPublic Sub ModifyCustomList(ByVal CustomList As String, ByVal StringToMofify As String, ByVal CLText As String, CLDescription As String, CLImg As String) Dim strPath() As String Dim lngIndex As Long strPath() = Split(CLImg, "") lngIndex = UBound(strPath) CLImg = "$SKINPATH$include\Contacts\userpics" & strPath(lngIndex) Const ForReading 1: Const ForWriting 2 Dim objFSO, objFile, allLines, arrLines, x, strLine, strNewContents Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(CustomList, ForReading, True, -1) allLines = objFile.ReadAll arrLines = Split(allLines, vbCrLf) arrLines(3) = "LST" & CLText & "||" & CLDescription arrLines(3 + 1) = "ICO" & CLImg objFile.Close Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile(CustomList, ForWriting, True, -1) RRSDK.SetUserVar "LN", UBound(arrLines) For x = 0 To UBound(arrLines) objFile.Write (arrLines(x) & vbCrLf) Next objFile.Close End Sub