vbs
1. Applications on the client:
To understand the browser object model, it is a common mistake to think that alert, setTimeOut, etc. are contents of js, but in fact it is just a method of window object.
The client calls the vbs function to explicitly declare the language: onclick="vbs:function name"
Solve js-like
For the object.onclick=function(){} problem, you can use the GetRef function.
Set = GetRef(procname)
2. Do you think that vbs does not have functions such as eval, escape?
In fact, vbs not only has eval but also execute, execScript. Test: execute "a=1+1"
<SCRIPT language="vbs" >
execute "for i=1 to 10 : alert i :next"
</SCRIPT>
It can even be written in very short code "perverted": dynamically generated n-layer nested loops, which are difficult for other languages to do.
<SCRIPT LANGUAGE=vbs>
'More than 10 lines of code realize the full arrangement of n numbers
dim n:n=4
dim S
dim w:w=0
for i=1 to n
S=S & "for i" & i & " =1 to n" & chr(13)
next
S=S & " if not("
for i=1 to n
for j=i to n
if i<>j then S=S & "i" & i & "=i" & j & " or "
next
next
S=left(S,len(S)-4) & ") then " & chr(13)
for i=1 to n
S=S & " i" & i & chr(13)
next
S=S & " " & chr(34) & "<br/>" & chr(34) & chr(13) & "end if" & chr(13)
w=w+1
for i=1 to n
S=S & "Next" & chr(13)
next
execScript S,"vbs"
</SCRIPT>
3. Strange usage of case:
case 1 and 2 can represent two situations, and case can be followed by variables or expressions case a or case 1+1. This is very flexible. C# and js case statements are not allowed.
4. There are also the usage of colons and underscores, which I believe may not be used by many people. dim a:a=1
for y=0 to 9:for x=0 to 8
AllQiZi(x,y) =0
next:next
It's just fun to reduce the number of code editing lines, don't use it everywhere, but there is really a guy who writes all the code in one line.
5. Sawtooth array
dim Arr,arrX(),arrY():redim arrX(0):redim arrY(0)
Arr=Array(arrX,arrY)
This Arr is an array of arrays. The contents in it can be any variable, any mixture of length and short, and object can be used too!
Arr(0)(0) is actually arrX(0)
6. Add new items to the arrX array above, and you can directly add them in the js array and sort them, because js does not have a real array! A real array cannot add items without redefinition. VBS' array is closer to real arrays and runs much faster than js' array objects. But the closer to the lower layer, the more inconvenient it may be to use it.
addArr arrX ,1
addArr arrX ,2
sub addArr(byref Arr,newItem)'Add one-dimensional array
if IsEmpty(Arr(0)) then
Arr(0)=newItem
exit sub
else
dim bound:bound=ubound(Arr)
Redim Preserve Arr(bound+1)
Arr(bound+1)=newItem
end if
end sub
The following is a comparison of the execution speed of js and vbs arrays, which is just assignment, and the difference is huge!
<SCRIPT LANGUAGE=javascript>
var jstest = 10 * 10000 ;
var jsArr = new Array(jstest) ;
var jsBegin = new Date().getTime();
for(i=0;i<jstest;i++)
{
jsArr[i]="Anything";
}
var jsEnd = new Date().getTime();
("JS needs to finish this work" + (jsEnd - jsBegin) +"Haomiao<br/>");
</SCRIPT>
<SCRIPT LANGUAGE=vbscript>
dim vbstest : vbstest = 10 * 10000
dim vbsArr() : redim vbsArr(vbstest)
dim vbsBegin : vbsBegin = Timer()
for j =0 to vbstest
vbsArr(j) = "Anything"
next
dim vbsEnd : vbsEnd = Timer()
"VBS needs to finish this work" & (vbsEnd - vbsBegin) * 1000 & "Haosie<br/>"
</SCRIPT>
JS takes 2329 seconds to finish this
VBS needs 108.8867 seconds to complete this work
But js array has a sort method, which is very convenient. VBS can only write the sort by itself, bubble? Too rustic.
sub sortA(Arr)
'Input: Arr time result array array
'Heap sorting, complexity n*log(n)/log(2), if 8 numbers are 24 times, if bubbling is 8^2=64 times
dim n,i,L,ir,rArr,j
n = ubound(Arr)
L = int(n / 2)+1
ir = n
do
if L > 1 then
L = L - 1
rArr = Arr(L)
else
rArr = Arr(ir)
Arr(ir) = Arr(1)
ir = ir - 1
if ir = 1 then
Arr(1) = rArr
exit sub
end if
end if
i = L
j = 2 * L
while j <= ir
if j < ir then
if Arr(j) < Arr(j + 1) then j = j + 1
end if
if rArr < Arr(j) then
Arr(i) = Arr(j)
i = j
j = 2 * j
else
j = ir + 1
end if
wend
Arr(i) = rArr
loop
end sub
Previous page123456Next pageRead the full text