[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.
Re: How to infinite loops?
What's the code that you are using ?
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 :)
Re: How to infinite loops?
Quote:
Originally Posted by
akhileshbc
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
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.
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?
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% CPU (looking from task manager).
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 ;)
Re: How to infinite loops?
Quote:
Originally Posted by
jcis
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.
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.
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.
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.
Re: How to infinite loops?
Quote:
Originally Posted by
baja_yu
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.:thumb:
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.