PDA

View Full Version : vbScript newbie needs a pause/wait


epiphany
05-06-2004, 11:05 PM
To Life Immortal

Hello. Glad to be here; I found you via Yahoo search. I just started learning vbScript
this week. I want to do fancy stuff on my website with DHTML. The script that I'm
working on is supposed to change background colour of webpage. It will gradually
fade to black.

Option Explicit
Dim kolor(6)
kolor(0)="ffffff"
kolor(1)="cccccc"
kolor(2)="999999"
kolor(3)="666666"
kolor(4)="333333"
kolor(5)="000000"

function fademe(x)
document.bgcolor=kolor(x)
end function

for w=0 to 5
call fademe(w)
next

The program works, but it is really fast. I need some way to place a 5 second timer in
the for....next loop. I tried the following, but it didn't work.

Option Explicit
Dim kolor(6)
kolor(0)="ffffff"
kolor(1)="cccccc"
kolor(2)="999999"
kolor(3)="666666"
kolor(4)="333333"
kolor(5)="000000"

function fademe(x)
document.bgcolor=kolor(x)
end function

for w=0 to 5
timer1=setTimer("fademe(w)", 5000)
timer1=clearTimer
next

Can someone tell me where I went wrong? Or is there another way to place a
5 second pause/wait between function calls? Thanks in advance for your help.

epiphany
05-07-2004, 03:34 PM
To Life Immortal

FatherMind, a friend I met on IRC gave me a clue. I worked on the script last night and finally came up with this:

<script type="text/vbscript">
option explicit
dim sKolor(5), nST, nTT, nX
sKolor(0)="ffffff"
sKolor(1)="cccccc"
sKolor(2)="999999"
sKolor(3)="666666"
sKolor(4)="333333"
sKolor(5)="000000"

for each nX in sKolor
document.bgcolor=nX
nST=Second(Now)
nTT=nST+5
if nTT>=60 then nTT=nTT-60
do
nST=Second(Now)
loop until nST>=nTT
next
</script>

I tested it and it works. I didn't need setTimeOut nor setInterval.

Thanks again, FatherMind; you're cool :)