Results 1 to 21 of 21

Thread: [Resolved] Pause Loop??

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2004
    Location
    Texas
    Posts
    32

    [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.

  2. #2

    Thread Starter
    Member
    Join Date
    Jun 2004
    Location
    Texas
    Posts
    32
    Can someone tell me if there is a way of using the sleep command in an html page?

  3. #3
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    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 :

  4. #4

    Thread Starter
    Member
    Join Date
    Jun 2004
    Location
    Texas
    Posts
    32
    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

  5. #5
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    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 :

  6. #6

    Thread Starter
    Member
    Join Date
    Jun 2004
    Location
    Texas
    Posts
    32
    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.

  7. #7
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    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 :

  8. #8

    Thread Starter
    Member
    Join Date
    Jun 2004
    Location
    Texas
    Posts
    32
    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!

  9. #9

    Thread Starter
    Member
    Join Date
    Jun 2004
    Location
    Texas
    Posts
    32
    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.

  10. #10

    Thread Starter
    Member
    Join Date
    Jun 2004
    Location
    Texas
    Posts
    32
    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>

  11. #11
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    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 :

  12. #12

    Thread Starter
    Member
    Join Date
    Jun 2004
    Location
    Texas
    Posts
    32
    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.

  13. #13

    Thread Starter
    Member
    Join Date
    Jun 2004
    Location
    Texas
    Posts
    32

    Unhappy

    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:
    1. <script language="VBScript">
    2. Dim i, iCount
    3. Sub Add_Item
    4.     Dim aiForm
    5.     Set aiForm = Document.Forms("addItem")
    6.     If (aiForm.SKU_Prefix.value = "") Then
    7.         MsgBox("Enter Valid Vendor Prefix")
    8.     Else
    9.         Dim rs, SQLText, conn, connStr
    10.         Set conn = CreateObject("ADODB.Connection")
    11.         SQLText = "SELECT * FROM schoolItems WHERE MfgPre = '" & aiForm.SKU_Prefix.value & "'"
    12.         connStr = "c:\Data\test.mdb"
    13.        
    14.         With conn
    15.             .Provider = "Microsoft.Jet.OLEDB.4.0"
    16.             .ConnectionString = connStr
    17.             .open
    18.         End With
    19.        
    20.         Set rs = CreateObject("ADODB.RecordSet")
    21.         rs.open SQLText, conn, 0, 1
    22.        
    23.         If Not rs.EOF Then
    24.             Do Until rs.EOF
    25.                 iCount = iCount + 1
    26.                 rs.MoveNext
    27.             Loop
    28.         End If
    29.         rs.MoveFirst
    30.    
    31.         iCount = iCount - 1
    32.         i = 0
    33.         ReDim iNum(iCount), iPfx(iCount)
    34.         If Not rs.EOF Then
    35.             Do Until rs.EOF
    36.                 iNum(i) = rs("ItemNum")
    37.                 iPfx(i) = rs("MfgPre")
    38.                 i = i + 1
    39.                 rs.MoveNext
    40.             Loop
    41.         End If
    42.         rs.close
    43.         conn.close
    44.         i = 0
    45.         startAdd i,iCount,iNum,iPfx
    46.     End If
    47. End Sub
    48.  
    49. Function startAdd(i,iCount,iNum,iPfx)
    50.     Do Until i = iCount
    51.         Add_Now i,iCount,iNum,iPfx
    52.         Exit Do
    53.     Loop
    54. End Function
    55.  
    56. Function Add_Now(i,iCount,iNum,iPfx)
    57.     Dim iPass, x
    58.     ReDim xNum(iCount),xPfx(iCount)
    59.     For Each x In iNum
    60.     xNum(iCount)=iNum(iCount)
    61.     xPfx(iCount)=xPfx(iCount)
    62.     Next
    63.     'Set MyForm = window.parent.topFrame.document.addItem
    64.     If i <= iCount Then
    65.         'MyForm.SKU_Prefix.value = xPfx
    66.         'MyForm.SKU_ItemNumber.value = xNum
    67.         'MyForm.method = "Post"
    68.         'MyForm.target = window.parent.mainFrame
    69.         'MyForm.Submit()
    70.         MsgBox(iPfx(i) + iNum(i))
    71.         i = i + 1
    72.         'iPass = i & "," & iCount & "," & xNum & "," & xPfx
    73.         'window.setTimeout "startAdd " & iPass & " ", 2000, "VBScript"
    74.         startAdd i,iCount,iNum,iPfx
    75.     End If
    76. End Function
    77. </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:
    1. window.setTimeout "'startAdd " & i & "," & iCount & "," & iNum & "," & iPfx & " ' ", 2000
    2.  
    3. window.setTimeout "'startAdd " & i & "," & iCount & "," & iNum & "," & iPfx & "'", 2000
    4.  
    5. window.setTimeout "'startAdd " & i & "," & iCount & "," & iNum & "," & iPfx & "'" , 2000
    6.  
    7. window.setTimeout "startAdd " & i & "," & iCount & "," & iNum & "," & iPfx , 2000
    8.  
    9. window.setTimeout "startAdd " & i & "," & iCount & "," & iNum & "," & iPfx, 2000
    10.  
    11. window.setTimeout "'startAdd " + i + "," + iCount + "," + iNum + "," + iPfx + "'" , 2000
    12.  
    13. window.setTimeout "'startAdd( " + i + "," + iCount + "," + iNum + "," + iPfx + "' )" , 2000
    14.  
    15. window.setTimeout "'startAdd(" + i + "," + iCount + "," + iNum + "," + iPfx + "')" , 2000
    16.  
    17. window.setTimeout "startAdd " + i + "," + iCount + "," + iNum + "," + iPfx + " ", 3000
    18.  
    19. window.setTimeout "startAdd " & i & "," & iCount & "," & iNum & "," & iPfx & " ", 3000
    20.  
    21. 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.

  14. #14
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    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 :

  15. #15
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    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 :

  16. #16

    Thread Starter
    Member
    Join Date
    Jun 2004
    Location
    Texas
    Posts
    32
    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:
    1. <script language="VBScript">
    2. Dim x(5), y(10), i, iCount
    3. iCount = 0
    4. For Each i In x
    5.     x(iCount) = "Item# " & iCount
    6.     document.write(x(iCount) & "<br/>")
    7.     iCount = iCount + 1
    8. Next
    9. startAdd i,iCount,x,y
    10.  
    11. Function startAdd(i,iCount,x,y)
    12.     Do Until i = iCount
    13.         Add_Now i,iCount,x,y
    14.         Exit Do
    15.     Loop
    16. End Function
    17.  
    18. Function Add_Now(i,iCount,x,y)
    19.     If i <= iCount Then
    20.         MsgBox(x(i))
    21.         i = i + 1
    22.         setTimeout "startAdd " & i & "," & iCount & "," & x & "," & y, 2000
    23.     End If
    24. End Function
    25. </script>
    Last edited by japshire; Aug 26th, 2004 at 08:53 AM.

  17. #17
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    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 :

  18. #18

    Thread Starter
    Member
    Join Date
    Jun 2004
    Location
    Texas
    Posts
    32
    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.

  19. #19
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    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 :

  20. #20

    Thread Starter
    Member
    Join Date
    Jun 2004
    Location
    Texas
    Posts
    32
    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

  21. #21
    Big D Danial's Avatar
    Join Date
    Jul 2000
    Location
    ASP.Net Forum
    Posts
    2,877
    Originally posted by japshire
    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
    Glad to know you resolved your problem at last. If you posted your code earlier then it would have been much easier.

    Good luck. Happy coding.

    [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 :

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width