Script timeout (Long loop process)

R

Rajani

Hello,

First of all sorry for the long code. But i want to explain clearly what i
am doing.

For i = 0 To UBound(arrResSizes) - 1
For j = 0 To UBound(arrqty) - 1
For k = 1 To totopr Step 8
tempjob = right(jc,5)
tempsize = left(arrResSizes(i) & " ", 3)
headsize = left(arrResSizes(i) & " ", 6)
tempqty = Right(" " & CStr(arrqty(j)), 2)
templay = Right(" " & CStr(lno), 3)
tempbdl = Right(" " & bdlno, 5)
tempopr = Right("00" & k, 2)
'tempcolor = Left(getColorName(arrColorCodes(j)) & "
", 6)
tempcolor=left(dict.Item(cstr(arrColorCodes(j))) & "
",6)
strop = strop & tempjob & " " & tempsize & " " &
tempqty & " " & templay & " " & tempbdl & " " & tempopr & " " & tempopr
& " " & headsize & " "
If (k + 1) <= totopr Then
tempopr = Right("00" & k + 1, 2)
strop = strop & tempopr & " " & tempjob & " " &
tempsize & " " & tempqty & " " & templay & " " & tempbdl & " " & tempopr &
vbcrlf & vbcrlf & vbcrlf
Else
strop = strop & vbcrlf & vbcrlf & vbcrlf
End If
If (k + 2) <= totopr Then
tempopr = Right("00" & k + 2, 2)
strop = strop & tempjob & " " & tempsize & " " &
tempqty & " " & templay & " " & tempbdl & " " & tempopr & " " & tempopr
& " " & tempqty & " PCS" & " "
Else
strop = strop & "
" & tempqty & " PCS "
End If

If (k + 3) <= totopr Then
tempopr = Right("00" & k + 3, 2)
strop = strop & tempopr & " " & tempjob & " " &
tempsize & " " & tempqty & " " & templay & " " & tempbdl & " " & tempopr &
vbcrlf & vbcrlf & vbcrlf
Else
strop = strop & vbcrlf & vbcrlf & vbcrlf
End If
If (k + 4) <= totopr Then
tempopr = Right("00" & k + 4, 2)
strop = strop & tempjob & " " & tempsize & " " &
tempqty & " " & templay & " " & tempbdl & " " & tempopr & " " & tempopr
& " " & tempcolor & " "
Else
strop = strop & "
" & tempcolor
End If

If (k + 5) <= totopr Then
tempopr = Right("00" & k + 5, 2)
strop = strop & tempopr & " " & tempjob & " " &
tempsize & " " & tempqty & " " & templay & " " & tempbdl & " " & tempopr &
vbcrlf & vbcrlf & vbcrlf
Else
strop = strop & vbcrlf & vbcrlf & vbcrlf
End If

If (k + 6) <= totopr Then
tempopr = Right("00" & k + 6, 2)
strop = strop & tempjob & " " & tempsize & " " &
tempqty & " " & templay & " " & tempbdl & " " & tempopr & " " & tempopr
& " " & tempjob & " "
Else
strop = strop & "
" & tempjob
End If

If (k + 7) <= totopr Then
tempopr = Right("00" & k + 7, 2)
strop = strop & tempopr & " " & tempjob & " " &
tempsize & " " & tempqty & " " & templay & " " & tempbdl & " " & tempopr &
vbcrlf & vbcrlf & vbcrlf
Else
strop = strop & vbcrlf & vbcrlf & vbcrlf
End If
Next
bdlno = bdlno + 1
rowcounter = 1
Next
Next


The first loop may be having 5 iterations(0 to 5)
Second - (0 to 20)
third may be (1 to 52)

Its taking so much time to produce the final output(nearly 5 mts). I got an
error initially "Script timeout". I have set the value to 180
"server.scripttimeout=180" Now its ok. But taking some long time to display
output. Even in the server itself.

Some times the first loop may be 0 to 12

Is my coding is wrong? or any other sollution is there to get the fast
output for this?

Pls help me. After executing i am saving the output(strop) in a text file
using FSO(that my need).

Thanks in advance.

The output could be liek this

http://m.1asphost.com/tsimsha/tickets.txt
 
I

io

G'day Rajani,

There is nothing wrong with your code. The killer most likely is string
management routines, namely, memory allocation routines that manage string
concatenations. I suggest you modify your code so that you accumulate the
output into array(s) and then use JOIN() to produce the final output string.
Have a look at the very basic code below - it should give you an idea what I
mean:

dim i, sTemp, aOut(), sOut

for i = 0 to 1000000
sTemp = <your code>
ReDim Preserve aOut(i)
aOut(i) = sTemp
next

sOut = Join(aOut, <delimeter>)

Cheers
 
R

Rajani

Hello,

Many thanx for u r reply. I didnt get you clearly. Can u guide me with my
code? what i have to delete and modify?

Thanx again
 
I

io

It just occured to me that you may be better off writing directly to a
file - eliminates concatatenation and you need file output anyway.
Try the following:


dim fs, a

Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("c:\testfile.txt", True)

For i = 0 To UBound(arrResSizes) - 1
For j = 0 To UBound(arrqty) - 1
For k = 1 To totopr Step 8
tempjob = right(jc,5)
tempsize = left(arrResSizes(i) & " ", 3)
headsize = left(arrResSizes(i) & " ", 6)
tempqty = Right(" " & CStr(arrqty(j)), 2)
templay = Right(" " & CStr(lno), 3)
tempbdl = Right(" " & bdlno, 5)
tempopr = Right("00" & k, 2)
'tempcolor = Left(getColorName(arrColorCodes(j)) & " ", 6)
tempcolor=left(dict.Item(cstr(arrColorCodes(j))) & " ",6)
a.Write(tempjob & " " & tempsize & " " & tempqty & " " &
templay & " " & tempbdl & " " & tempopr & " " & tempopr & " " &
headsize & " ")
If (k + 1) <= totopr Then
tempopr = Right("00" & k + 1, 2)
a.Write(tempopr & " " & tempjob & " " & tempsize & " "
& tempqty & " " & templay & " " & tempbdl & " " & tempopr & vbcrlf & vbcrlf
& vbcrlf)
Else
a.Write(vbcrlf & vbcrlf & vbcrlf)
End If
If (k + 2) <= totopr Then
tempopr = Right("00" & k + 2, 2)
a.Write(tempjob & " " & tempsize & " " & tempqty & " " &
templay & " " & tempbdl & " " & tempopr & " " & tempopr & " " &
tempqty & " PCS" & " ")
Else
a.Write(" " & tempqty &
" PCS ")
End If

If (k + 3) <= totopr Then
tempopr = Right("00" & k + 3, 2)
a.Write(tempopr & " " & tempjob & " " & tempsize & " "
& tempqty & " " & templay & " " & tempbdl & " " & tempopr & vbcrlf & vbcrlf
& vbcrlf)
Else
a.Write(vbcrlf & vbcrlf & vbcrlf)
End If
If (k + 4) <= totopr Then
tempopr = Right("00" & k + 4, 2)
a.Write(tempjob & " " & tempsize & " " & tempqty & " " &
templay & " " & tempbdl & " " & tempopr & " " & tempopr & " " &
tempcolor & " ")
Else
a.Write(" " &
tempcolor)
End If

If (k + 5) <= totopr Then
tempopr = Right("00" & k + 5, 2)
a.Write(tempopr & " " & tempjob & " " & tempsize & " "
& tempqty & " " & templay & " " & tempbdl & " " & tempopr & vbcrlf & vbcrlf
& vbcrlf)
Else
a.Write(vbcrlf & vbcrlf & vbcrlf)
End If

If (k + 6) <= totopr Then
tempopr = Right("00" & k + 6, 2)
a.Write(tempjob & " " & tempsize & " " & tempqty & " " &
templay & " " & tempbdl & " " & tempopr & " " & tempopr & " " &
tempjob & " ")
Else
a.Write(" " & tempjob)
End If

If (k + 7) <= totopr Then
tempopr = Right("00" & k + 7, 2)
a.Write(tempopr & " " & tempjob & " " & tempsize & " "
& tempqty & " " & templay & " " & tempbdl & " " & tempopr & vbcrlf & vbcrlf
& vbcrlf)
Else
a.Write(vbcrlf & vbcrlf & vbcrlf)
End If
Next
bdlno = bdlno + 1
rowcounter = 1
Next
Next

a.Close

Cheers
 
B

Ben Strackany

One possibility for performance is to put all that logic into a compiled
object (e.g. VB6 COM DLL). It may perform much faster.

One possibility to give feedback to your users is to set Reponse.Buffer =
False and Server.ScriptTimeout = 0.

Then in various places in your code, write out status messages so that users
know it's still working, like

Response.Write "Still processing..." & string(1000, " ")
Response.Flush

I added the string(1000, " ") b/c I've had issues w/ the response not
getting flushed if not enough new data was added. *shrug*
 
I

io

How did you go with this?
Try the following:


dim fs, a

Set fs = CreateObject("Scripting.FileSystemObject")
Set a = fs.CreateTextFile("c:\testfile.txt", True)

For i = 0 To UBound(arrResSizes) - 1
For j = 0 To UBound(arrqty) - 1
For k = 1 To totopr Step 8
tempjob = right(jc,5)
tempsize = left(arrResSizes(i) & " ", 3)
headsize = left(arrResSizes(i) & " ", 6)
tempqty = Right(" " & CStr(arrqty(j)), 2)
templay = Right(" " & CStr(lno), 3)
tempbdl = Right(" " & bdlno, 5)
tempopr = Right("00" & k, 2)
'tempcolor = Left(getColorName(arrColorCodes(j)) & " ", 6)
tempcolor=left(dict.Item(cstr(arrColorCodes(j))) & " ",6)
a.Write(tempjob & " " & tempsize & " " & tempqty & " " &
templay & " " & tempbdl & " " & tempopr & " " & tempopr & " " &
headsize & " ")
If (k + 1) <= totopr Then
tempopr = Right("00" & k + 1, 2)
a.Write(tempopr & " " & tempjob & " " & tempsize & " "
& tempqty & " " & templay & " " & tempbdl & " " & tempopr & vbcrlf & vbcrlf
& vbcrlf)
Else
a.Write(vbcrlf & vbcrlf & vbcrlf)
End If
If (k + 2) <= totopr Then
tempopr = Right("00" & k + 2, 2)
a.Write(tempjob & " " & tempsize & " " & tempqty & " " &
templay & " " & tempbdl & " " & tempopr & " " & tempopr & " " &
tempqty & " PCS" & " ")
Else
a.Write(" " & tempqty &
" PCS ")
End If

If (k + 3) <= totopr Then
tempopr = Right("00" & k + 3, 2)
a.Write(tempopr & " " & tempjob & " " & tempsize & " "
& tempqty & " " & templay & " " & tempbdl & " " & tempopr & vbcrlf & vbcrlf
& vbcrlf)
Else
a.Write(vbcrlf & vbcrlf & vbcrlf)
End If
If (k + 4) <= totopr Then
tempopr = Right("00" & k + 4, 2)
a.Write(tempjob & " " & tempsize & " " & tempqty & " " &
templay & " " & tempbdl & " " & tempopr & " " & tempopr & " " &
tempcolor & " ")
Else
a.Write(" " &
tempcolor)
End If

If (k + 5) <= totopr Then
tempopr = Right("00" & k + 5, 2)
a.Write(tempopr & " " & tempjob & " " & tempsize & " "
& tempqty & " " & templay & " " & tempbdl & " " & tempopr & vbcrlf & vbcrlf
& vbcrlf)
Else
a.Write(vbcrlf & vbcrlf & vbcrlf)
End If

If (k + 6) <= totopr Then
tempopr = Right("00" & k + 6, 2)
a.Write(tempjob & " " & tempsize & " " & tempqty & " " &
templay & " " & tempbdl & " " & tempopr & " " & tempopr & " " &
tempjob & " ")
Else
a.Write(" " & tempjob)
End If

If (k + 7) <= totopr Then
tempopr = Right("00" & k + 7, 2)
a.Write(tempopr & " " & tempjob & " " & tempsize & " "
& tempqty & " " & templay & " " & tempbdl & " " & tempopr & vbcrlf & vbcrlf
& vbcrlf)
Else
a.Write(vbcrlf & vbcrlf & vbcrlf)
End If
Next
bdlno = bdlno + 1
rowcounter = 1
Next
Next

a.Close

Cheers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,229
Latest member
GloryAngul

Latest Threads

Top