извлечь из файла VB

zxxx

Постоялец
Регистрация
9 Окт 2009
Сообщения
148
Реакции
4
Не знаю какой точно язык используется в automate 7, просто не всегда получается запустить, а так там вроде VB

на этом языке нужен код для того чтобы из указанного текстового файла извлечь все содержимое
 
  • Заблокирован
  • #2
Это на vb.net
PHP:
Dim file = My.Computer.FileSystem.ReadAllText("file.txt", System.Text.Encoding.GetEncoding(1251))
Это на vb6
PHP:
Dim MyFile 
Dim S As String
MyFile = FreeFile
Open ("C:TEST.txt") For Input As #MyFile
S = Input$(LOG(1), 1)
Close #MyFile
или
PHP:
Open "c:\temp.txt" For Input As #1
Do Until EOF(1)
Line Input #1, txt
alltxt = alltxt + txt + vbCrLf
Loop
Close #1
txtText.Text = alltxt
 
  • Нравится
Реакции: zxxx
Line Input #1, txt
alltxt = alltxt + txt + vbCrLf
Dim MyFile
Dim S As String
MyFile = FreeFile
Close #1
 
Для VBA работает такое, значит и для простого VB подойдет:
Код:
Function ReadAllText(ByVal filename As String) As String
    Set FSOObj = CreateObject("scripting.filesystemobject")
    Set ts = FSOObj.OpenTextFile(filename, 1, True): ReadAllText = ts.ReadAll: ts.Close
    Set ts = Nothing: Set FSOObj = Nothing
End Function

Function WriteAllText(ByVal filename As String, ByVal txt As String) As Boolean
    On Error Resume Next: Err.Clear
    Set FSOObj = CreateObject("scripting.filesystemobject")
    Set ts = FSOObj.CreateTextFile(filename, True)
    ts.Write txt: ts.Close
    WriteAllText = Err = 0
    Set ts = Nothing: Set FSOObj = Nothing
End Function
 
Назад
Сверху