1 (изменено: arcnik, 2011-11-23 09:14:48)

Тема: VBS: Цикл

Доброго времени суток!
В VBAExcel есть Функция позволяющая сделать так чтоб при обработке цикла все не подвисало:

 
Do
DoEvents
Loop

Вопросик, Есть ли что-то подобное в VBS?
Кроме:

 
Do
WScript.Sleep 100
Loop

2

Re: VBS: Цикл

Нет. А Sleep не устраивает ?

Передумал переделывать мир. Пашет и так, ну и ладно. Сделаю лучше свой !

3

Re: VBS: Цикл

Xameleon пишет:

Нет. А Sleep не устраивает ?

Нет. принципиально не тот.

4

Re: VBS: Цикл

arcnik, поясните, чем именно не подходит. Желательно с демонстрацией кода.

5

Re: VBS: Цикл

alexii пишет:

arcnik, поясните, чем именно не подходит. Желательно с демонстрацией кода.

Пусть код будет такой:

Set Dict = CreateObject("Scripting.Dictionary")
With Dict
.Item(1) = "1"
.Item(2) = "2"
.Item(3) = "3"
.Item(4) = "4"
.Item(5) = "5"
.Item(6) = "6"
.Item(7) = "7"
.Item(8) = "8"
.Item(9) = "9"
.Item(10) = "0"
.Item(11) = "A"
.Item(12) = "B"
.Item(13) = "C"
.Item(14) = "D"
.Item(15) = "E"
.Item(16) = "F"
.Item(17) = "G"
.Item(18) = "H"
.Item(19) = "I"
.Item(20) = "J"
.Item(21) = "K"
.Item(22) = "L"
.Item(23) = "M"
.Item(24) = "N"
.Item(25) = "O"
.Item(26) = "P"
.Item(27) = "Q"
.Item(28) = "R"
.Item(29) = "S"
.Item(30) = "T"
.Item(31) = "U"
.Item(32) = "V"
.Item(33) = "W"
.Item(34) = "X"
.Item(35) = "Y"
.Item(36) = "Z"
.Item(37) = "a"
.Item(38) = "b"
.Item(39) = "c"
.Item(40) = "d"
.Item(41) = "e"
.Item(42) = "f"
.Item(43) = "g"
.Item(44) = "h"
.Item(45) = "i"
.Item(46) = "j"
.Item(47) = "k"
.Item(48) = "l"
.Item(49) = "m"
.Item(50) = "n"
.Item(51) = "o"
.Item(52) = "p"
.Item(53) = "q"
.Item(54) = "r"
.Item(55) = "s"
.Item(56) = "t"
.Item(57) = "u"
.Item(58) = "v"
.Item(59) = "w"
.Item(60) = "x"
.Item(61) = "y"
.Item(62) = "z"
.Item(63) = "А"
.Item(64) = "Б"
.Item(65) = "В"
.Item(66) = "Г"
.Item(67) = "Д"
.Item(68) = "Е"
.Item(69) = "Ё"
.Item(70) = "Ж"
.Item(71) = "З"
.Item(72) = "И"
.Item(73) = "Й"
.Item(74) = "К"
.Item(75) = "Л"
.Item(76) = "М"
.Item(77) = "Н"
.Item(78) = "О"
.Item(79) = "П"
.Item(80) = "Р"
.Item(81) = "С"
.Item(82) = "Т"
.Item(83) = "У"
.Item(84) = "Ф"
.Item(85) = "Х"
.Item(86) = "Ц"
.Item(87) = "Ч"
.Item(88) = "Ш"
.Item(89) = "Щ"
.Item(90) = "Ъ"
.Item(91) = "Ы"
.Item(92) = "Ь"
.Item(93) = "Э"
.Item(94) = "Ю"
.Item(95) = "Я"
.Item(96) = "а"
.Item(97) = "б"
.Item(98) = "в"
.Item(99) = "г"
.Item(100) = "д"
.Item(101) = "е"
.Item(102) = "ё"
.Item(103) = "ж"
.Item(104) = "з"
.Item(105) = "и"
.Item(106) = "й"
.Item(107) = "к"
.Item(108) = "л"
.Item(109) = "м"
.Item(110) = "н"
.Item(111) = "о"
.Item(112) = "п"
.Item(113) = "р"
.Item(114) = "с"
.Item(115) = "т"
.Item(116) = "у"
.Item(117) = "ф"
.Item(118) = "х"
.Item(119) = "ц"
.Item(120) = "ч"
.Item(121) = "ш"
.Item(122) = "щ"
.Item(123) = "ъ"
.Item(124) = "ы"
.Item(125) = "ь"
.Item(126) = "э"
.Item(127) = "ю"
.Item(128) = "я"
.Item(129) = " "
.Item(130) = """"
.Item(131) = "#"
.Item(132) = "$"
.Item(133) = "%"
.Item(134) = "^"
.Item(135) = "&"
.Item(136) = "*"
.Item(137) = "("
.Item(138) = ")"
.Item(139) = "_"
.Item(140) = "+"
.Item(141) = ","
.Item(142) = "."
.Item(143) = "-"
.Item(144) = "\"
.Item(145) = "|"
.Item(146) = "/"
.Item(147) = "="
.Item(148) = "@"
.Item(149) = "№"
.Item(150) = ":"
.Item(151) = ";"
.Item(152) = "`"
.Item(153) = "'"
.Item(154) = "~"
.Item(155) = ">"
.Item(156) = "<"
.Item(157) = "?"
.Item(158) = "!"
.Item(159) = "["
.Item(160) = "]"
.Item(161) = "{"
.Item(162) = "}"
End With

Nabor = InputBox("Введите число соответствующее" & vbLf & "набору символов:" & vbLf & "[1] - 0-9" & vbLf & "[2] - A-Z" & vbLf & "[3] - a-z" & vbLf & "[4] - А-Я" & vbLf & "[5] - а-я" & vbLf & "[6] - символы"& vbLf &"[12] - 1-9, A-Z"& vbLf &"[23] - A-Z, a-z"& vbLf &"[123] - 1-9, A-Z, a-z" & vbLf & "[123456] - все варианты", "Набор словаря", "0")

kolvo = InputBox("Введите количество используемых символов в пароле (не более 10):", "Кол-во символов", "1")

if Nabor = 1 then
n1="1"
n2="10"

elseif Nabor = 2 then
n1="11"
n2="36"

elseif Nabor = 3 then
n1="37"
n2="62"

elseif Nabor = 4 then
n1="63"
n2="95"

elseif Nabor = 5 then
n1="96"
n2="128"

elseif Nabor = 6 then
n1="129"
n2="162"

elseif Nabor = 12 then
n1="1"
n2="36"

elseif Nabor = 23 then
n1="11"
n2="62"

elseif Nabor = 123 then
n1="1"
n2="62"

elseif Nabor = 123456 then
n1="1"
n2="162"

end if


Set FSO = CreateObject("Scripting.FileSystemObject")
IIyTb = FSO.GetAbsolutePathName(".")
Set aa = FSO.CreateTextFile(IIyTb & "\Словарь из " & kolvo & " символов.txt")

if kolvo = 1 then
for a1=n1 to n2    'Перебор 1
a2=Dict.Item(a1)
aa.WriteLine(a2)
next
WScript.Quit

elseif kolvo = 2 then 
for a1=n1 to n2    'Перебор 2
for a2=n1 to n2
aa1=Dict.Item(a1)
aa2=Dict.Item(a2)
aa.WriteLine(aa1& aa2)
next
next
WScript.Quit


elseif kolvo = 3 then
for a1=n1 to n2    'Перебор 3
for a2=n1 to n2
for a3=n1 to n2
aa1=Dict.Item(a1)
aa2=Dict.Item(a2)
aa3=Dict.Item(a3)
aa.WriteLine(aa1 & aa2 & aa3)
next
next
next
WScript.Quit


elseif kolvo = 4 then 
for a1=n1 to n2    'Перебор 4
for a2=n1 to n2
for a3=n1 to n2
for a4=n1 to n2
aa1=Dict.Item(a1)
aa2=Dict.Item(a2)
aa3=Dict.Item(a3)
aa4=Dict.Item(a4)
aa.WriteLine(aa1 & aa2 & aa3 & aa4)
next
next
next
next
WScript.Quit


elseif kolvo = 5 then
for a1=n1 to n2    'Перебор 5
for a2=n1 to n2
for a3=n1 to n2
for a4=n1 to n2
for a5=n1 to n2
aa1=Dict.Item(a1)
aa2=Dict.Item(a2)
aa3=Dict.Item(a3)
aa4=Dict.Item(a4)
aa5=Dict.Item(a5)
aa.WriteLine(aa1 & aa2 & aa3 & aa4 & aa5)
next
next
next
next
next
WScript.Quit


elseif kolvo = 6 then 
for a1=n1 to n2    'Перебор 6
for a2=n1 to n2
for a3=n1 to n2
for a4=n1 to n2
for a5=n1 to n2
for a6=n1 to n2
aa1=Dict.Item(a1)
aa2=Dict.Item(a2)
aa3=Dict.Item(a3)
aa4=Dict.Item(a4)
aa5=Dict.Item(a5)
aa6=Dict.Item(a6)
aa.WriteLine(aa1 & aa2 & aa3 & aa4 & aa5 & aa6)
next
next
next
next
next
next
WScript.Quit


elseif kolvo = 7 then
for a1=n1 to n2    'Перебор 7
for a2=n1 to n2
for a3=n1 to n2
for a4=n1 to n2
for a5=n1 to n2
for a6=n1 to n2
for a7=n1 to n2
aa1=Dict.Item(a1)
aa2=Dict.Item(a2)
aa3=Dict.Item(a3)
aa4=Dict.Item(a4)
aa5=Dict.Item(a5)
aa6=Dict.Item(a6)
aa7=Dict.Item(a7)
aa.WriteLine(aa1 & aa2 & aa3 & aa4 & aa5 & aa6 & aa7)
next
next
next
next
next
next
next
WScript.Quit


elseif kolvo = 8 then 
for a1=n1 to n2    'Перебор 8
for a2=n1 to n2
for a3=n1 to n2
for a4=n1 to n2
for a5=n1 to n2
for a6=n1 to n2
for a7=n1 to n2
for a8=n1 to n2
aa1=Dict.Item(a1)
aa2=Dict.Item(a2)
aa3=Dict.Item(a3)
aa4=Dict.Item(a4)
aa5=Dict.Item(a5)
aa6=Dict.Item(a6)
aa7=Dict.Item(a7)
aa8=Dict.Item(a8)
aa.WriteLine(aa1 & aa2 & aa3 & aa4 & aa5 & aa6 & aa7 & aa8)
next
next
next
next
next
next
next
next
WScript.Quit


elseif kolvo = 9 then
for a1=n1 to n2    'Перебор 9
for a2=n1 to n2
for a3=n1 to n2
for a4=n1 to n2
for a5=n1 to n2
for a6=n1 to n2
for a7=n1 to n2
for a8=n1 to n2
for a9=n1 to n2
aa1=Dict.Item(a1)
aa2=Dict.Item(a2)
aa3=Dict.Item(a3)
aa4=Dict.Item(a4)
aa5=Dict.Item(a5)
aa6=Dict.Item(a6)
aa7=Dict.Item(a7)
aa8=Dict.Item(a8)
aa9=Dict.Item(a9)
aa.WriteLine(aa1 & aa2 & aa3 & aa4 & aa5 & aa6 & aa7 & aa8 & aa9)
next
next
next
next
next
next
next
next
next
WScript.Quit

elseif kolvo = 10 then
for a1=n1 to n2    'Перебор 10
for a2=n1 to n2
for a3=n1 to n2
for a4=n1 to n2
for a5=n1 to n2
for a6=n1 to n2
for a7=n1 to n2
for a8=n1 to n2
for a9=n1 to n2
for a10=n1 to n2
aa1=Dict.Item(a1)
aa2=Dict.Item(a2)
aa3=Dict.Item(a3)
aa4=Dict.Item(a4)
aa5=Dict.Item(a5)
aa6=Dict.Item(a6)
aa7=Dict.Item(a7)
aa8=Dict.Item(a8)
aa9=Dict.Item(a9)
aa10=Dict.Item(a10)
aa.WriteLine(aa1 & aa2 & aa3 & aa4 & aa5 & aa6 & aa7 & aa8 & aa9 & aa10)
next
next
next
next
next
next
next
next
next
next
WScript.Quit
end if

Пример условный
Так вот если ставить Sleep, то времени уйдет много, для того чтоб скрипт не тормозил процессы, так как Sleep  на N-ное время притормаживает работу скрипта. В то время как DoEvents в екселе не останавливает процесс обработки.

6

Re: VBS: Цикл

В то время как DoEvents в екселе не останавливает процесс обработки.

Останавливает. Но её назначение иное — заморозив на время обработку, передать управление операционной системе, дабы могла быть обработана очередь событий. В WSH же Sleep обычный — ибо там нет интерфейса и нужды реагировать на обработку внешних событий.

Как поступать: использовать запуск процесса скрипта с пониженным приоритетом, понижать приоритет скрипта после запуска из него самого, использовать систему с несколькими ядрами/псевдоядрами/процессорами.

7

Re: VBS: Цикл

Ясно, спасибо всем.
Жаль конечно