Visual Basic, .NET, ASP, VBScript
 

   
   
     

Форум - Общий форум

Страница: 1 | 2 |

 

  Вопрос: Большие текстовые файлы Добавлено: 02.04.09 16:47  

Автор вопроса:  Sergey

Ответить

  Ответы Всего ответов: 17  

Номер ответа: 16
Автор ответа:
 VβÐUηìt



Вопросов: 246
Ответов: 3333
 Web-сайт: смекаешь.рф
 Профиль | | #16
Добавлено: 19.04.09 16:55
Ты сам отвечаешь на свой вопрос:
Точнее сказать, поиск проходит только в первых (около 15) строках, а в следующих уже не находит.

Если в файле есть строки, значит надо последовательно считывать строки и искать в каждой из них текст по отдельности. Примерно это выглядит так:
  1.  
  2. dim s as string
  3. open filename for input as #1
  4. do until eof(1)
  5. line input #1, s
  6. if instr(1, s, "еда") > 0 then msgbox (("Жрааать!")),vbExclamation: exit do
  7. loop
  8. close #1


Ответить

Номер ответа: 17
Автор ответа:
 Arvitaly



ICQ: 301746136 

Вопросов: 28
Ответов: 549
 Web-сайт: okazani.ru
 Профиль | | #17
Добавлено: 20.04.09 00:18
Разница во времени при файлах больше 1 мегабайта уже ощутима, да и крякозябры пофигу

  1.    Private Const GMEM_MOVEABLE As Long = 0
  2.    Private Const GMEM_FIXED = &H0
  3.    Private Declare Function GlobalFree Lib "kernel32.dll" (ByVal hMem As Long) As Long
  4.     Private Declare Function GlobalAlloc Lib "kernel32.dll" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long
  5.     Private Const FILE_BEGIN = 0
  6.     Private Const GENERIC_READ As Long = &H80000000
  7.     Private Const GENERIC_WRITE As Long = &H40000000
  8.     Private Const CREATE_ALWAYS As Long = 2
  9.     Private Const open_existing As Long = 3
  10.     Private Const FILE_FLAG_SEQUENTIAL_SCAN As Long = &H8000000
  11.     Private Declare Function CreateFile Lib "kernel32.dll" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, ByRef lpSecurityAttributes As Long, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long
  12.     Private Declare Function SetFilePointer Lib "kernel32.dll" (ByVal hFile As Long, ByVal lDistanceToMove As Long, ByVal lpDistanceToMoveHigh As Long, ByVal dwMoveMethod As Long) As Long
  13.     Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToWrite As Long, lpNumberOfBytesWritten As Long, ByVal lpOverlapped As Long) As Long
  14.     Private Declare Function ReadFile Lib "kernel32.dll" (ByVal hFile As Long, ByRef lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, ByRef lpNumberOfBytesRead As Long, ByVal lpOverlapped As Long) As Long
  15.     Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) As Long
  16. Private Declare Function CreateStreamOnHGlobal Lib "ole32" (ByVal hMem&, ByVal DeleteOnRelease&, pStream As IUnknown) As Long
  17. Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
  18. Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
  19. Private Declare Function OleLoadPicture Lib "olepro32" (pStream As Any, ByVal lSize As Long, ByVal fRunmode As Long, riid As Any, ppvObj As Any) As Long
  20. Private Declare Function CLSIDFromString Lib "ole32" (ByVal lpsz As Any, pclsid As Any) As Long
  21. Private Declare Function GetTickCount Lib "kernel32" () As Long
  22. Private Declare Function GetFileSizeEx Lib "kernel32" (ByVal hFile As Long, lpFileSize As Currency) As Boolean
  23.  
  24.     Const IID_IPicture = "{7BF80980-BF32-101A-8BBB-00AA00300CAB}"
  25. Const file_share_read = &H1
  26. Const file_share_write = &H2
  27. Dim filename As String, findString As String
  28.  
  29. Private Sub Form_Load()
  30.     filename = "d:\123.txt"
  31.     findString = "Arvitaly"
  32. End Sub
  33.  
  34. Private Sub command1_Click()
  35.  Dim s As String
  36.  Dim t As Long
  37.     t = GetTickCount
  38.  Open filename For Input As #1
  39.  Do Until EOF(1)
  40.  Line Input #1, s
  41.  If InStr(1, s, findString) > 0 Then Print (("Àäðåñ íàéäåí!")), vbExclamation: Exit Do
  42.  Loop
  43.  Close #1
  44.  MsgBox "Ïðîøëî " & (GetTickCount - t) & "ìèëëèñåêóíä"
  45. End Sub
  46.  
  47. Private Sub command2_Click()
  48. Dim nSize As Currency, hget As Double, mAdress As Long, str As String * 64000, ar As Long, pos As Currency, iff As Long
  49. Dim t As Long
  50.     t = GetTickCount
  51.     hget = CreateFile(filename, GENERIC_READ, file_share_read Or file_share_write, ByVal 0&, open_existing, 0, 0)
  52.     If hget < 1 Then MsgBox "&#205;&#229; &#243;&#228;&#224;&#235;&#238;&#241;&#252; &#239;&#238;&#235;&#243;&#247;&#232;&#242;&#252; &#228;&#238;&#241;&#242;&#243;&#239; &#234; &#244;&#224;&#233;&#235;&#243;": Exit Sub
  53.     GetFileSizeEx hget, nSize
  54.     If nSize < 1 Then MsgBox "&#212;&#224;&#233;&#235; &#237;&#243;&#235;&#229;&#226;&#238;&#227;&#238; &#240;&#224;&#231;&#236;&#229;&#240;&#224;, &#247;&#229; &#242;&#224;&#236; &#232;&#241;&#234;&#224;&#242;&#252; &#242;&#238;": Exit Sub
  55.             mAdress = GlobalAlloc(GMEM_FIXED, 64001)
  56.         If mAdress < 1 Then MsgBox "&#205;&#229; &#243;&#228;&#224;&#235;&#238;&#241;&#252; &#226;&#251;&#228;&#229;&#235;&#232;&#242;&#252; &#239;&#224;&#236;&#255;&#242;&#252;": Exit Sub
  57.         str = mAdress
  58.     Do While pos < (nSize * 10000) + 64000
  59.         ar = SetFilePointer(hget, pos, 0, FILE_BEGIN)
  60.         If ar <> pos Then MsgBox "&#205;&#229; &#237;&#224;&#233;&#228;&#229;&#237;&#224; &#239;&#238;&#231;&#232;&#246;&#232;&#255; &#226; &#244;&#224;&#233;&#235;&#229;": Exit Sub
  61.         ar = ReadFile(hget, ByVal str, 64000, 0, 0)
  62.         If ar <> 1 Then MsgBox "&#205;&#229; &#243;&#228;&#224;&#235;&#238;&#241;&#252; &#239;&#240;&#238;&#247;&#232;&#242;&#224;&#242;&#252; &#232;&#231; &#244;&#224;&#233;&#235;&#224;": Exit Sub
  63.         iff = InStr(1, str, findString)
  64.         If iff > 0 Then Print (("&#192;&#228;&#240;&#229;&#241; &#237;&#224;&#233;&#228;&#229;&#237; &#237;&#224; &#239;&#238;&#231;&#232;&#246;&#232;&#232; " & iff + pos)), vbExclamation: Exit Do
  65.         pos = pos + 64000
  66.     Loop
  67.     CloseHandle (hget)
  68.     MsgBox "&#207;&#240;&#238;&#248;&#235;&#238; " & (GetTickCount - t) & "&#236;&#232;&#235;&#235;&#232;&#241;&#229;&#234;&#243;&#237;&#228;"
  69. End Sub

Ответить

Страница: 1 | 2 |

Поиск по форуму



© Copyright 2002-2011 VBNet.RU | Пишите нам