powered by simpleCommunicator - 2.0.59     © 2025 Programmizd 02
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Форумы / Visual Basic [игнор отключен] [закрыт для гостей] / прервать/остановить выполнение функции
2 сообщений из 2, страница 1 из 1
прервать/остановить выполнение функции
    #36536347
prog133
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
помогите остановить выполнение функции
вот код
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
Option Explicit 

Dim fso As New FileSystemObject 
Dim fld As Folder 

Private Sub Command1_Click() 
   Dim nDirs As Long, nFiles As Long, lSize As Currency 
   Dim sDir As String, sSrchString As String 
   sDir = InputBox("Type the directory that you want to search for", _ 
                   "FileSystemObjects example", "C:\") 
   sSrchString = InputBox("Type the file name that you want to search for", _ 
                   "FileSystemObjects example", "vb.ini") 
   MousePointer = vbHourglass 
   Label1.Caption = "Searching " & vbCrLf & UCase(sDir) & "..." 
   lSize = FindFile(sDir, sSrchString, nDirs, nFiles) 
   MousePointer = vbDefault 
   MsgBox Str(nFiles) & " files found in" & Str(nDirs) & _ 
          " directories", vbInformation 
   MsgBox "Total Size = " & lSize & " bytes" 
End Sub
Код: plaintext
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
Private Function FindFile(ByVal sFol As String, sFile As String, _ 
   nDirs As Long, nFiles As Long) As Currency 
   Dim tFld As Folder, tFil As File, FileName As String 
    
   On Error GoTo Catch 
   Set fld = fso.GetFolder(sFol) 
   FileName = Dir(fso.BuildPath(fld.Path, sFile), vbNormal Or _ 
                  vbHidden Or vbSystem Or vbReadOnly) 
   While Len(FileName) <>  0  
      FindFile = FindFile + FileLen(fso.BuildPath(fld.Path, _ 
      FileName)) 
      nFiles = nFiles +  1  
      List1.AddItem fso.BuildPath(fld.Path, FileName)  ' Load ListBox 
      FileName = Dir()  ' Get next file 
      DoEvents 
   Wend 
   Label1 = "Searching " & vbCrLf & fld.Path & "..." 
   nDirs = nDirs +  1  
   If fld.SubFolders.Count >  0  Then 
      For Each tFld In fld.SubFolders 
         DoEvents 
         FindFile = FindFile + FindFile(tFld.Path, sFile, nDirs, nFiles) 
      Next 
   End If 
   Exit Function 
Catch:  FileName = "" 
       Resume Next 
End Function
нашел здесь
вот это Код:
Код: plaintext
1.
2.
Private Sub Form_KeyPress(KeyAscii As Integer) 
If KeyAscii = vbKeyCancel Then End Sub 
End Sub

не помагает, вылетает ошибка "Syntax error"

помогите плиз..
...
Рейтинг: 0 / 0
прервать/остановить выполнение функции
    #36536423
Фотография Konst_One
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Код: plaintext
1.
2.
3.
4.
Private Sub Form_KeyPress(KeyAscii As Integer) 
If KeyAscii = vbKeyCancel Then 
  End  
end if
End Sub


но это очень плохой вариант, т.к. является аварийным завершением вашей программы. сделайте public переменную и назначайте ей значение , а в длинном своём цикле проверяйте это значение.
...
Рейтинг: 0 / 0
2 сообщений из 2, страница 1 из 1
Форумы / Visual Basic [игнор отключен] [закрыт для гостей] / прервать/остановить выполнение функции
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]