|
-
Aug 4th, 2004, 10:29 AM
#1
Thread Starter
Member
[Resolved] Pause Loop??
Sorry if this is a simple question, but can some tell me if it is possible to pause a Do While Loop?
The loop is connected to an Access database, and is cycling through each record. With each pass it is submitting a form, so I need it to pause long enough for the form to be accepted.
Thanks in advance!!
Last edited by japshire; Aug 27th, 2004 at 10:38 AM.
-
Aug 4th, 2004, 12:08 PM
#2
Thread Starter
Member
Can someone tell me if there is a way of using the sleep command in an html page?
-
Aug 4th, 2004, 12:30 PM
#3
Originally posted by japshire
Can someone tell me if there is a way of using the sleep command in an html page?
Look up on JavaScript function SetTimeOut function
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
Aug 4th, 2004, 12:55 PM
#4
Thread Starter
Member
I have tried using the setTimeout Function but I can't seem to make it work properly with my Do Until loop.
I end up with an endless loop because the script doesn't seem to wait for the Function to return its value before it continues on.
example
****************************************************
If NOT rs.EOF Then
Do Until rs.EOF
iPass = window.setTimeout("MyFunction",15000)
If iPass = True Then
'Place code to submit form
rs.MoveNext
End If
Loop
End If
-
Aug 4th, 2004, 01:29 PM
#5
Originally posted by japshire
I have tried using the setTimeout Function but I can't seem to make it work properly with my Do Until loop.
I end up with an endless loop because the script doesn't seem to wait for the Function to return its value before it continues on.
example
****************************************************
If NOT rs.EOF Then
Do Until rs.EOF
iPass = window.setTimeout("MyFunction",15000)
If iPass = True Then
'Place code to submit form
rs.MoveNext
End If
Loop
End If
Your approach is wrong! You are mixing up Client side Script with ServerSide script.
SetTimeOut is ClientSide script not serverSide. You need to embed SetTimeOut function in client side.
What exactly are you trying to do?Explain in details, i will try to give you a solution.
Danial
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
Aug 4th, 2004, 02:40 PM
#6
Thread Starter
Member
This is what I need.
I have a page split into two frames. The top frame controls all the processing. The bottom frame is used for submitting the forms.
I have an Access database that has several records that need to be submitted to this form.
I'm looping through the database but I thought I had all the code set at the client level. (I don't use vbscript often though, and I'm not completely sure.)
Example..
****************************************************
<script language="VBScript" >
'Perform loop
</script>
****************************************************
I need for the loop to pause and give the bottom frame enough time to make its submission during each pass.
What you said makes since about the client and Server side. I just assumed since everything was marked in script tags that is was being process client side.
-
Aug 4th, 2004, 04:02 PM
#7
Why are you using Loop to submit Form? Can you explain a bit more what you are trying to do. It dont make sense to put use Loop to submit the form. Post the code if possible...
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
Aug 4th, 2004, 04:16 PM
#8
Thread Starter
Member
I'm using a Loop so that I don't have to manually submit each item to the form. All I have to do is load the database and hit the submit button once and away it will go. That way if I have 1,000 items, which I do, I won't have to hit submit 1,000 times.
Here is some of my code.
*****************************************************
<script language="VBScript">
Sub Add_Item
Dim aiForm
Set aiForm = Document.Forms("addItem")
If (aiForm.SKU_Prefix.value = "") Then
MsgBox("Enter Valid Vendor Prefix")
Else
Dim rs, SQLText, conn, connStr, i, iCount
Set conn = CreateObject("ADODB.Connection")
SQLText = "SELECT * FROM schoolItems WHERE MfgPre = '" & aiForm.SKU_Prefix.value & "'"
connStr = "c:\Data\test.mdb"
With conn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = connStr
.open
End With
Set rs = CreateObject("ADODB.RecordSet")
rs.open SQLText, conn, 0, 1
*****************************************************
Here is where my code would need to loop through all the records and then pause to submit each one to the remote form.
****************************************************
The reason I'm being forced to do this is I have a third party that is hosting my eCatalog and the only method they provided to update items is through a web form.
It would take forever to enter each item one at a time so I'm trying to automate it.
Hope this helps.
Thanks for your input!
-
Aug 5th, 2004, 09:29 AM
#9
Thread Starter
Member
Is there anyone who can help me with this?
I feel like I'm so close.
I tried originally doing this in vb.net using webrequest/response, but something in the remote form keeps breaking my application.
-
Aug 5th, 2004, 10:44 AM
#10
Thread Starter
Member
Ok here is my code as it stands so far. I figured that since may recordset was happening server side I would store the items in an array. I'm not sure how well this will work though, because like I said I have a lot of items.
I still can not get the setTimeout to work properly though.
Can someone maybe point out what I'm over looking, because I have looked at it so long that I think I'm simply jumping over it?
Thanks Again!! 
*******************************************************
<script language="VBScript">
Sub Add_Item
Dim aiForm
Set aiForm = Document.Forms("addItem")
If (aiForm.SKU_Prefix.value = "") Then
MsgBox("Enter Valid Vendor Prefix")
Else
Dim rs, SQLText, conn, connStr, i, iCount
Set conn = CreateObject("ADODB.Connection")
SQLText = "SELECT * FROM schoolItems WHERE MfgPre = '" & aiForm.SKU_Prefix.value & "'"
connStr = "c:\Data\test.mdb"
With conn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = connStr
.open
End With
Set rs = CreateObject("ADODB.RecordSet")
rs.open SQLText, conn, 0, 1
If Not rs.EOF Then
Do Until rs.EOF
iCount = iCount + 1
rs.MoveNext
Loop
End If
rs.MoveFirst
iCount = iCount - 1
i = 0
ReDim iNum(iCount), iPfx(iCount)
If Not rs.EOF Then
Do Until rs.EOF
iNum(i) = rs("ItemNum")
iPfx(i) = rs("MfgPre")
i = i + 1
rs.MoveNext
Loop
End If
rs.close
conn.close
i = 0
startAdd i,iCount
End If
End Sub
Function startAdd(i,iCount)
Do Until i = iCount + 1
Add_Now i,iCount
Exit Do
Loop
End Function
Function Add_Now(i,iCount)
Dim iPass
If i <= iCount Then
window.parent.mainFrame.document.write("Pass " & i & "<br/>")
i = i + 1
window.setTimeout "startAdd " & i & "," & iCount , 1000
End If
End Function
</script>
-
Aug 5th, 2004, 11:25 AM
#11
Where are you placing this code?ASP file, VBS file?
The architecture of your utility seems to be wrong to me.
I assume your are submiting the data to a remote host using Get or Post method. Looks like you are mixing serverside and client side script. I am slightly confused.
Here is how i would do it. (in ASP, should work in VBS too)
1. Load all data to a Recordset Object (like you have done)
2. Loop through the recordset and use XMLHTTP to Post data to remote host.
Or
1. Design a page which will take 1 parameter. Lets say the parameter is CurrentRow. So this page will return Select Row [CurrentRow] From [YourTable]
2. Have a loop which will call page one with a parameter(CurrentRow), and fill the data and then submit the form. The loop will continue until you have reached the end.
Hope this helps.
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
Aug 5th, 2004, 02:25 PM
#12
Thread Starter
Member
I don't really know much about vbscript or classic asp.
I have only used vbscript to automate some of my network administration task.
As for your question, "Where are you placing this code".
I'm placing it in an plain html file.
example
*****************************************************
<html>
<head>
<script language="vbscript">
Sub Something
End Sub
</script>
</head>
<body>
<form>
<input type=button onClick="Something" value="Submit" name="Submit">
</form>
</body>
</html>
*****************************************************
Everything seems to run fine except I just can't seem to figure out how to pause the loop or make the setTimeout work properly.
The code I posted above makes it to the first pass through function Add_Now but stops there.
If I remove the window.setTimeout it makes it all the way through.
Last edited by japshire; Aug 5th, 2004 at 03:08 PM.
-
Aug 25th, 2004, 06:41 PM
#13
Thread Starter
Member
I still have not found a solution for this problem. Can some one please help me? 
The code I have so far will work except, I still can not pause the loop. I have to be able to pause it, because the receiving form takes 6 to 8 seconds to process each request. If I don't pause my loop it moves to fast, and the only item that actually gets submitted is the last one.
Here is my code to this point.
It doesn't actually do any submitting at this point because I'm still trying to get the loop/pause situation worked out.
*****************************************************
VB Code:
<script language="VBScript">
Dim i, iCount
Sub Add_Item
Dim aiForm
Set aiForm = Document.Forms("addItem")
If (aiForm.SKU_Prefix.value = "") Then
MsgBox("Enter Valid Vendor Prefix")
Else
Dim rs, SQLText, conn, connStr
Set conn = CreateObject("ADODB.Connection")
SQLText = "SELECT * FROM schoolItems WHERE MfgPre = '" & aiForm.SKU_Prefix.value & "'"
connStr = "c:\Data\test.mdb"
With conn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = connStr
.open
End With
Set rs = CreateObject("ADODB.RecordSet")
rs.open SQLText, conn, 0, 1
If Not rs.EOF Then
Do Until rs.EOF
iCount = iCount + 1
rs.MoveNext
Loop
End If
rs.MoveFirst
iCount = iCount - 1
i = 0
ReDim iNum(iCount), iPfx(iCount)
If Not rs.EOF Then
Do Until rs.EOF
iNum(i) = rs("ItemNum")
iPfx(i) = rs("MfgPre")
i = i + 1
rs.MoveNext
Loop
End If
rs.close
conn.close
i = 0
startAdd i,iCount,iNum,iPfx
End If
End Sub
Function startAdd(i,iCount,iNum,iPfx)
Do Until i = iCount
Add_Now i,iCount,iNum,iPfx
Exit Do
Loop
End Function
Function Add_Now(i,iCount,iNum,iPfx)
Dim iPass, x
ReDim xNum(iCount),xPfx(iCount)
For Each x In iNum
xNum(iCount)=iNum(iCount)
xPfx(iCount)=xPfx(iCount)
Next
'Set MyForm = window.parent.topFrame.document.addItem
If i <= iCount Then
'MyForm.SKU_Prefix.value = xPfx
'MyForm.SKU_ItemNumber.value = xNum
'MyForm.method = "Post"
'MyForm.target = window.parent.mainFrame
'MyForm.Submit()
MsgBox(iPfx(i) + iNum(i))
i = i + 1
'iPass = i & "," & iCount & "," & xNum & "," & xPfx
'window.setTimeout "startAdd " & iPass & " ", 2000, "VBScript"
startAdd i,iCount,iNum,iPfx
End If
End Function
</script>
*****************************************************
Again this is placed in just a plain html file, but it works. I just need to be able to pause it. I have tried using vbscripts settimeout function, but it doesn't seem to be able to pass an array through it.
When I try, I receive a Type Mismatch error.
I have tried all of these combinations as well.
*****************************************************
VB Code:
window.setTimeout "'startAdd " & i & "," & iCount & "," & iNum & "," & iPfx & " ' ", 2000
window.setTimeout "'startAdd " & i & "," & iCount & "," & iNum & "," & iPfx & "'", 2000
window.setTimeout "'startAdd " & i & "," & iCount & "," & iNum & "," & iPfx & "'" , 2000
window.setTimeout "startAdd " & i & "," & iCount & "," & iNum & "," & iPfx , 2000
window.setTimeout "startAdd " & i & "," & iCount & "," & iNum & "," & iPfx, 2000
window.setTimeout "'startAdd " + i + "," + iCount + "," + iNum + "," + iPfx + "'" , 2000
window.setTimeout "'startAdd( " + i + "," + iCount + "," + iNum + "," + iPfx + "' )" , 2000
window.setTimeout "'startAdd(" + i + "," + iCount + "," + iNum + "," + iPfx + "')" , 2000
window.setTimeout "startAdd " + i + "," + iCount + "," + iNum + "," + iPfx + " ", 3000
window.setTimeout "startAdd " & i & "," & iCount & "," & iNum & "," & iPfx & " ", 3000
window.setTimeout "startAdd(" & i & "," & iCount & "," & iNum & "," & iPfx & ")", 3000
*****************************************************
Thanks to anyone who can assist me.
Last edited by japshire; Aug 25th, 2004 at 07:02 PM.
-
Aug 25th, 2004, 06:53 PM
#14
Please use [vbcode] your code [/vbcode] tag to format your code, it is extremely hard to read unformated code like this. I will have a look at it when i get a chance. I will post when i find a solution
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
Aug 26th, 2004, 08:01 AM
#15
You are using the SetTimeOut function incorrectly. Here is how you should use it. Take out the single quote.
I have tested the call and it works. So try it out.
Code:
setTimeout "startAdd " & i & "," & iCount & "," & iNum & "," & iPfx, 2000
setTimeout "startAdd " & 1 & "," & 10 & "," & 5 & "," & 5, 2000
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
Aug 26th, 2004, 08:27 AM
#16
Thread Starter
Member
Thanks as always Danial for the reply, but I have actually already tried that. Look at #'s 4 & 5 on my list of tried setTimeout strings.
When I use any of these combinations I get the Type Mismatch error. I can call the setTimeout function just fine as long as I'm not trying to pass the two arrays (iNum & iPfx).
I have added this code in order to try and simplify this discussion.
VB Code:
<script language="VBScript">
Dim x(5), y(10), i, iCount
iCount = 0
For Each i In x
x(iCount) = "Item# " & iCount
document.write(x(iCount) & "<br/>")
iCount = iCount + 1
Next
startAdd i,iCount,x,y
Function startAdd(i,iCount,x,y)
Do Until i = iCount
Add_Now i,iCount,x,y
Exit Do
Loop
End Function
Function Add_Now(i,iCount,x,y)
If i <= iCount Then
MsgBox(x(i))
i = i + 1
setTimeout "startAdd " & i & "," & iCount & "," & x & "," & y, 2000
End If
End Function
</script>
Last edited by japshire; Aug 26th, 2004 at 08:53 AM.
-
Aug 26th, 2004, 09:03 AM
#17
Originally posted by japshire
Thanks as always Danial for the reply, but I have actually already tried that. Look at #'s 4 & 5 on my list of tried setTimeout strings.
When I use any of these combinations I get the Type Mismatch error. I can call the setTimeout function just fine as long as I'm not trying to pass the two arrays (iNum & iPfx).
Yes i can see the problem now, it seems like when you pass array with settimeout it flags it as type mismatch error.
Can you not declare iNum & iPix as Global variable instead of passing it as parameters?
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
Aug 26th, 2004, 09:20 AM
#18
Thread Starter
Member
Originally posted by Danial
Can you not declare iNum & iPix as Global variable instead of passing it as parameters?
I'm not sure I understand what you ment here??
I also added some code to the post above. I'm not sure rather I added it before your last post or not?
This is an edit...
I have reread your last post and I think I understand what you are telling me, but the only problem with it is that my array is being loaded on a button click. Also the size of the array depends on how many items there is in the database.
Example..
ReDim iNum(NumberOfItemsInDatabase)
If I declare it globaly and thin redim it in the sub will the script still see it as the same variable?
Last edited by japshire; Aug 26th, 2004 at 09:28 AM.
-
Aug 26th, 2004, 09:36 AM
#19
Originally posted by japshire
Example..
ReDim iNum(NumberOfItemsInDatabase)
If I declare it globaly and thin redim it in the sub will the script still see it as the same variable?
Yes it will, declare those two variable in the same place you have declared "iCount".
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
Aug 27th, 2004, 10:37 AM
#20
Thread Starter
Member
Thanks so much Danial!!
I tried it last night and everything worked fine.
I knew it would probably end up being something simple.
Thanks Again!
Jackie
-
Aug 27th, 2004, 11:13 AM
#21
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|