Считайте строки из текстового файла, но пропустите первые две строки

То, что вы на самом деле делаете, это добавление строк. Чтобы обновить содержимое существующих строк, используйте оператор UPDATE:

UPDATE table SET table_column = 'test';
15
задан Kenny Bones 26 September 2013 в 11:49
поделиться

5 ответов

That whole Open For Input As thing is so 1990s. It's also slow and very error-prone.

In your VBA editor, Select References from the Tools menu and look for "Microsoft Scripting Runtime" (scrrun.dll) which should be available on pretty much any XP or Vista machine. It it's there, select it. Now you have access to a (to me at least) rather more robust solution:

With New Scripting.FileSystemObject
    With .OpenTextFile(sFilename, ForReading)

        If Not .AtEndOfStream Then .SkipLine
        If Not .AtEndOfStream Then .SkipLine

        Do Until .AtEndOfStream
            DoSomethingImportantTo .ReadLine
        Loop

    End With
End With
30
ответ дан 1 December 2019 в 00:50
поделиться

Вы можете использовать произвольный доступ.

Open "C:\docs\TESTFILE.txt" For Random As #1 

    Position = 3    ' Define record number.
    Get #1, Position, ARecord    ' Read record.

Close #1
6
ответ дан 1 December 2019 в 00:50
поделиться
Open sFileName For Input As iFileNum

Dim LineNum As Long
LineNum = 0

Do While Not EOF(iFileNum)
  LineNum = LineNum + 1
  Line Input #iFileNum, Fields
  If LineNum > 2 Then
    DoStuffWith(Fields)
  End If
Loop
3
ответ дан 1 December 2019 в 00:50
поделиться

Может быть, я слишком упрощаю?

Просто добавьте следующий код:

Open sFileName For Input as iFileNum
Line Input #iFileNum, dummy1
Line Input #iFileNum, dummy2
........

Сундар

2
ответ дан 1 December 2019 в 00:50
поделиться
Dim sFileName As String
Dim iFileNum As Integer
Dim sBuf As String
Dim Fields as String
Dim TempStr as String

sFileName = "c:\fields.ini"
''//Does the file exist?
If Len(Dir$(sFileName)) = 0 Then
    MsgBox ("Cannot find fields.ini")
End If

iFileNum = FreeFile()
Open sFileName For Input As iFileNum

''//This part skips the first two lines
if not(EOF(iFileNum)) Then Line Input #iFilenum, TempStr
if not(EOF(iFileNum)) Then Line Input #iFilenum, TempStr

Do While Not EOF(iFileNum)
    Line Input #iFileNum, Fields

    MsgBox (Fields)
Loop
1
ответ дан 1 December 2019 в 00:50
поделиться
Другие вопросы по тегам:

Похожие вопросы: