Results 1 to 14 of 14

Thread: [RESOLVED] How to infinite loops?

Hybrid View

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2010
    Posts
    7

    Resolved [RESOLVED] How to infinite loops?

    I have vb form with some text boxes. These boxes updated when I pressed a command button. The values are taken from wsdl service. I want it automate so that when I press button it should continue updating until I press the stop button. I try to use Do While Loop but it stop working. So how can I code the application that the boxes should keep refreshing itself until I stop.

  2. #2
    Freelancer akhileshbc's Avatar
    Join Date
    Jun 2008
    Location
    Trivandrum, Kerala, India
    Posts
    7,652

    Re: How to infinite loops?

    What's the code that you are using ?

    If my post was helpful to you, then express your gratitude using Rate this Post.
    And if your problem is SOLVED, then please Mark the Thread as RESOLVED (see it in action - video)
    My system: AMD FX 6100, Gigabyte Motherboard, 8 GB Crossair Vengance, Cooler Master 450W Thunder PSU, 1.4 TB HDD, 18.5" TFT(Wide), Antec V1 Cabinet

    Social Group: VBForums - Developers from India


    Skills: PHP, MySQL, jQuery, VB.Net, Photoshop, CodeIgniter, Bootstrap,...

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2010
    Posts
    7

    Re: How to infinite loops?

    Quote Originally Posted by akhileshbc View Post
    What's the code that you are using ?
    This Code, it should continue until I wish.

    Code:
    Private Sub cmdStart_Click()
    
    ' To package SOAP request.
     Dim objSerial As MSSOAPLib.SoapSerializer
    
     ' To read SOAP response.
     Dim objRead As MSSOAPLib.SoapReader
    
     ' To connect to Web service using SOAP.
     Dim objConn As MSSOAPLib.SoapConnector
    
     ' To parse the SOAP response.
     Dim objResults As MSXML2.IXMLDOMNodeList
     Dim objNode As MSXML2.IXMLDOMNode
    
     ' Set up the SOAP connector.
     Set objConn = New MSSOAPLib.HttpConnector
     objConn.Property("EndPointURL") = "http://127.0.0.1:8018/endpoint"
    
     ' Define the SOAP action. You can find it in the WSDL's
     ' <soap:operation> tag's soapAction attribute for the matching
     ' <operation> tag.
     
     objConn.Property("SoapAction") = "GetQuote"
    
     ' Begin the SOAP message.
     objConn.BeginMessage
    
     Set objSerial = New MSSOAPLib.SoapSerializer
    
     ' Initialize the serializer to the connector's input stream.
     objSerial.Init objConn.InputStream
    
     ' Build the SOAP message.
     With objSerial
     .startEnvelope ' <SOAP-ENV:Envelope>
     .startBody ' <SOAP-ENV:Body>
    
     .startElement "Instrument"
     .writeString "EUR/USD"
     .endElement ' input par
    
     .endBody ' </SOAP-ENV:Body>
     .endEnvelope ' </SOAP-ENV:Envelope>
     End With
    
    
     ' Send the SOAP message.
     objConn.EndMessage
    
     Set objRead = New MSSOAPLib.SoapReader
    
    
     ' Initialize the SOAP reader to the connector's output stream.
     objRead.Load objConn.OutputStream
    
    
     Debug.Print objRead.DOM.xml
    
     Set objResults = objRead.Body.childNodes
    
    
     For Each objNode In objResults
    
     Select Case objNode.nodeName
     Case "Quote"
     txtHigh.Text = objNode.selectSingleNode("High").nodeTypedValue 'show Today High price of quote
     txtLow.Text = objNode.selectSingleNode("Low").nodeTypedValue   'show Today Low of quote
     txtBid.Text = objNode.selectSingleNode("Bid").nodeTypedValue   'show Bid price of quote
     txtAsk.Text = objNode.selectSingleNode("Offer").nodeTypedValue 'show Offer of quote
     Case Else
     End Select
     Next objNode
    End Sub
    Last edited by kijkij; Apr 15th, 2010 at 08:02 AM.

  4. #4
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: How to infinite loops?

    A Do Loop should be fine, if you code the exit condition correctly. What's the code you are using?
    You can also use a Timer to do it.

    Edit: Beat me to it

  5. #5
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: How to infinite loops?

    I don't see that you close the " Do Until ss = False" Loop anywhere. And I'm pretty sure that trying to compile that will give you an error.

  6. #6

    Thread Starter
    New Member
    Join Date
    Apr 2010
    Posts
    7

    Re: How to infinite loops?

    Sorry I forgot to delete that line from the code as I deleted Loop line as I want something clear from you people. But I placed The Loop before the end of the sub but the problem is it hangs the code but without Do while or Do untill the code works best. So have you any solution?

  7. #7
    Addicted Member Optional's Avatar
    Join Date
    Jan 2010
    Location
    Rudimentary Space
    Posts
    214

    Re: How to infinite loops?

    What do you mean by "Hang" ?
    Does your application freeze ?

    Unless I'm missinterpeting this, it does sound like your loop is running alright but is hogging all the resources.

    Add the line DoEvent into the loop to free up resources. Using the Sleep API also helps to make sure you do a Sleep(100) at the end of the do loop.

    All this will make sure your resources are not only going to the loop but allow you to keep interacting with the application.

    Sorry if I missread the issue.

    Edit
    or as jcis said



    Kind Regards,
    Optional



    If you feel this post has helped in answering your question please return the favour and Rate this post.
    If your problem has been solved and your question has been answered mark the thread as [RESOLVED] by selecting the Thread Tools menu option at the top and clicking the Mark Thread Resolved menu item.


    VB6 - (DataGrid) Get the Row selected with the right mouse button



  8. #8
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    Re: How to infinite loops?

    I think a Timer would be a good idea for this. If for some reason you want to use a do / loop or while / wend then don't forget to place a DoEvents inside, else your Form will freeze and won't let events occur. The disadvantage of a loop like this is that it's harder to control the interval, without control it will run as fast as the CPU allows it to run and i might use 100&#37; CPU (looking from task manager).

  9. #9
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How to infinite loops?

    Quote Originally Posted by jcis View Post
    I think a Timer would be a good idea for this. If for some reason you want to use a do / loop or while / wend then don't forget to place a DoEvents inside, else your Form will freeze and won't let events occur.
    And to piggyback on jcis comments. DoEvents allow users to re-enter your form, they can click anything anytime while your loop is running; this means they can even try to close your form or start your loop again & again causing a potential nightmare for you. You should account for that and prevent re-entry if the loop is running, if desired.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  10. #10

    Thread Starter
    New Member
    Join Date
    Apr 2010
    Posts
    7

    Re: How to infinite loops?

    I also tried the Loops with Sleep(1000) function(API) but still it Freeze and I need to close it from task Manager.

  11. #11
    Addicted Member Optional's Avatar
    Join Date
    Jan 2010
    Location
    Rudimentary Space
    Posts
    214

    Re: How to infinite loops?

    If you run the application from within the VB6 code IDE.
    When it freesez, press the left CTRL Key + Pause/Break key, this will force-stop the code and show you where it is at, then using F8 you can keep following the code to check if there is anything executed which takes a long time.

    It could well be that the code is stuck awaiting the return of an external process, ie when it queries the wsdl service. In that case CTRL+Break is not going to stop the code either until the focus is back int eh application.

    Step through the code in debug mode and iterrate a few times throught the loop to check if you find anything not executing as expected.



    Kind Regards,
    Optional



    If you feel this post has helped in answering your question please return the favour and Rate this post.
    If your problem has been solved and your question has been answered mark the thread as [RESOLVED] by selecting the Thread Tools menu option at the top and clicking the Mark Thread Resolved menu item.


    VB6 - (DataGrid) Get the Row selected with the right mouse button



  12. #12
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: How to infinite loops?

    Using Sleep function will freeze the process. Like said, use DoEvents inside the Loop to keep other things going on. Or like I said in the begining, put the code you want to loop inside a Timer control, then just set it's Enabled property True/False using your Start/Stop buttons.

  13. #13

    Thread Starter
    New Member
    Join Date
    Apr 2010
    Posts
    7

    Thumbs up Re: How to infinite loops?

    Quote Originally Posted by baja_yu View Post
    Using Sleep function will freeze the process. Like said, use DoEvents inside the Loop to keep other things going on. Or like I said in the begining, put the code you want to loop inside a Timer control, then just set it's Enabled property True/False using your Start/Stop buttons.
    Thanks "baja_yu", Timer control works best as I want.

    Thanks to others who replied me. really helpful folks here.

  14. #14
    Next Of Kin baja_yu's Avatar
    Join Date
    Aug 2002
    Location
    /dev/root
    Posts
    5,989

    Re: How to infinite loops?

    No problem!

    Please take time to mark the thread Resolved by going to the Tread Tools menu on the right side, just above your original post.

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