Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Infinite WaitFor

Status
Not open for further replies.

sentinel11011

Technical User
Aug 24, 2006
6
US
I need to do an infinite WaitFor for a script I'm writing. The problem is that putting it in a loop and waiting until the function returns 1 eats tons of CPU cycles. Is there a way to do an infinite WaitFor? For example
session.WaitFor(0, [something infinite here], "login:")

I tried just a really large amount of milliseconds (like an hour), but it overflows at 9999.

Thanks!
 
Hi there,

How about you tell us what you're trying to do in the end here. I think that would help. Also, what application, version, etc.

Regards,
Zack Barresse

Simplicity is the ultimate sophistication. What is a MS MVP? PODA
- Leonardo da Vinci
 
If you are waiting for a response from the user and want to halt the execution of your code in VBA (or VB) you can use a message box or an input box (if you asking for a login).

But firefytr is right this probably isn't code programming practive, VBA is meant to be event driven, so you should have your code execute off of a button that is pressed. But as you don't really explain what you are trying to do we can't advise you any further.

A,
 
sentinel11011,
[tt]WaitFor()[/tt]? Sounds like telnet. To echo firefytr, since we don't know what environment you working with you might take a look at the [tt]SetTimer()[/tt] and [tt]KillTimer()[/tt] API calls:
How To Create a Timer Event Using the Windows API Functions

CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
the only question I have is do you REALLY want a never ending loop, sounds like a bad idea, anyhow this code will continue to loop:

While True
'insert code here
Wend

I'm just not sure thats what you want to do, a little more information on the problemm and I may be able to give you a beter answer
 
Sorry,

It is using Acuterm, which is just a telnet terminal emulator that allows VBA scripts. There is a login prompt programmed into the server that asks for "login:" and "password"

The first "login:" and "password:" is the same for everyone in the company, and is used on the sales floor to ensure only employees can get in (they then enter an associate ID and associate password, but that part is no big deal). For PC users using Acuterm, there is no point in having the first login prompt, so we are writing scripts to automate that login... ie... wait for the prompt login: put in such and such, carriage return, line feed, wait for password, etc. The problem is that the system kicks you out after a while, and returns you to the first login prompt with "login:" It does this after 10 minutes of inactivity (so the actual time it takes will vary depending on the users usage.. IE, if the user just logs in and does nothing, it will only be 10 minutes, but if they are doing things for 10 minutes, then are idle for 10 minutes, it will take 20 for "login:" to return. I think you get the idea) On a PC, when "login" returns, I want the script waiting for it to automatically go through the login sequence again.

It works in an infinite loop very well, except for the fact that it eats up all the CPU cycles :(

If WaitFor just had an infinite argument that put the thread to sleep until "login:" retuned, that would be perfect, but so far I've only been able to get it to wait up to 9999 milliseconds, which is not long enough.

Thanks all.
 
This seems like it should be a rather easy script. Here is what I have that works, but uses too many CPU cycles:

Sub Main()

Dim user As String
user = "BLAH BLAH"

Dim pass As String
pass = "BLAH BLAH BLAH"

'THIS IS FOR THE INITIAL LOGIN, AND WORKS GREAT

ActiveSession.WriteText user
ActiveSession.WriteText vbCr
two = ActiveSession.WaitFor(0, 300, "Password:")
ActiveSession.WriteText pass
ActiveSession.WriteText vbCr


'THIS IS FOR THE TIMEOUT LOGIN, AND WORKS BUT EATS TOO MUCH CPU

While True

Do
three = ActiveSession.WaitFor(0, 9999, "login:")
Loop Until three = 1
ActiveSession.WriteText user
ActiveSession.WriteText vbCr
four = ActiveSession.WaitFor(0, 300, "Password:")
ActiveSession.WriteText pass
ActiveSession.WriteText vbCr

Wend

End Sub
 
I don't think WaitFor is what you want then. If this program supports VBA, try looking at it's object model or see if it has a VBEIDE of sorts. Where do you put your code for that program? Do they have any documentation of any kind? I'd be looking for an object for this login action.

Regards,
Zack Barresse

Simplicity is the ultimate sophistication. What is a MS MVP? PODA
- Leonardo da Vinci
 
The script is saved as an external file, and just run at startup of the Acuterm program. There is no local login object, as all of this is stored on the server. Pretty much it is a telnet session, and the acuterm program is smart enough to watch what is being returned to the screen (in strings). It would be the same as any telnet session. Acuterm just provides a scripting environment to accomplish common tasks. I pretty much just need a script that will always look for "login:" and when it finds it (in Acuterm, ActiveSession is the object that does this), run a script to feed it the username and password. If I can't use WaitFor, is there something else I can use to make it wait for a specific string?

Sorry. I usually only do VBA in access, and usually just to show and hide stuff :)

Thanks again.
 
No, there is no WaitFor, there is a Wait however, but it's the logic we're talking about here. I see the Pause, Sleep and WaitFor methods, but don't think that is the way to go. I would also look at the SSHAuuth, SSHKeepAlive and the TelnetKeepalive method of the Sessions object.

One way you might want to think about doing this is (if you don't open the session via code) to make an event for this.

Code:
Dim WithEvents objSession as Accutermclasses.Session

Some urls which may interest you..

Have you read the entire programming manual you linked for us?

NB: this posting is completely untested, I don't have the program to test with (nor will I pay $150 only to test), nor do I claim to fully know it's object model or best methods for utilizing such.

Regards,
Zack Barresse

Simplicity is the ultimate sophistication. What is a MS MVP? PODA
- Leonardo da Vinci
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top