Wrox Programmer Forums
|
Pro VB 6 For advanced Visual Basic coders working in version 6 (not .NET). Beginning-level questions will be redirected to other forums, including Beginning VB 6.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 10th, 2003, 12:49 PM
Authorized User
 
Join Date: Sep 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default Automation using VB

Hey everybody,
Anyone wishes to give me a hand here?
I've been trying to automate an application using visual basics. I've reached a wall! I know this is probably a really stupid error by me, but I'd appreciate if someone helps:

I am automating this program, which I need to selects a few tables and repairs them. After opening the application and sending some keystrokes, I have to wait till the application verifies the tables, and so since I don’t know how long this waiting time is, I decided to use a loop until a msgbox pops up on the screen that indicates verification is completed. Then I would need to click ok (send space key).
My problem is the loop section. I keep getting an infinite loop. Here is what I have so far:
Code:
Private Sub sendSpaceKey()
    ' checks until the specified window class pops up '
    ' retreive name of class on the active window     '
    ' wait for the next pop up box                    '
    Do While (className <> "TmoduleForm" Or className <> "TmessageForm")
        className = getClass(GetForegroundWindow)
    Loop
    ' send space key '
    Do While (className = "TmoduleForm" Or className = "TmessageForm")
        className = getClass(GetForegroundWindow)
        SendKeys "{pace}", True
    Loop
End Sub
I have tested all the other functions and everything works fine. Basically what happens here is that, I want to check for the active window and get the class name of that type of window. If it is the class im looking for then send a keystroke....

I'd appreciate if someone responded quickly!

Sam Gharnagh
Jr. Programmer Analyst at MOH
Comp Sci at UofW
__________________
Sam Gharnagh
Jr. Programmer Analyst at MOH
Comp Sci at UofW
 
Old November 10th, 2003, 02:15 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Your application is a too tigh loop.
Change the loop adding a timer, set the interval to few seconds and activate it when you start waiting. In the timer event add something like:

Timer1.Enabled = false 'no double entrance please
className = GetClass(GetForegroundWindow)
if classname = "tmoduleform" or classname = "tmessageform" then
  sendkeys {Space}, True
else
  TImer1.Enabled = True
endif

Hope this helps,
m.
 
Old November 10th, 2003, 02:31 PM
Authorized User
 
Join Date: Sep 2003
Posts: 35
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Wow, thanks for the quick response.
I'm trying the timer right now! thanks
I'm new to VB, and I didn't even know you can such a thing. I also had another problem with the code. Apparently you can't use OR to do a conditional statement for a DO WHILE, am i correct?
Code:
Do While (className <> "TmoduleForm" Or className <> "TmessageForm")
I know you can do stuff like that in java but i kept getting infinte loops.

Sam Gharnagh
Jr. Programmer Analyst at MOH
Comp Sci at UofW
 
Old November 10th, 2003, 02:40 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jlick
Default

The problem is in your statement. You can use or, but the way you are using it, one of the two will always be true.
  
Code:
classname = "tmoduleform" or classname = "tmessageform"

IF classname is tmoduleform, then it is not tmessageform. Therefor the second part is true.

I think the logic you want to use in this case is to use AND, not or.
  
Code:
do while classname = "tmoduleform" AND classname = "tmessageform"


You could also do:
  
Code:
do while not (classname = "tmoduleform" or classname = "tmessageform")



John R Lick
[email protected]
 
Old November 10th, 2003, 02:42 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jlick
Default

Sorry the and example should have been:
Code:
do while classname <> "tmoduleform" AND classname <> "tmessageform"


John R Lick
[email protected]





Similar Threads
Thread Thread Starter Forum Replies Last Post
VB.Net Word Automation deboe Pro Visual Basic 2005 0 November 26th, 2007 09:57 PM
Using VB DLL in ASP for Visio2003 Automation deepakkhopade Classic ASP Components 9 May 8th, 2006 04:31 AM
Excel VB Automation jeannief Excel VBA 3 June 14th, 2005 06:06 AM
Email automation through VB Anantsharma All Other Wrox Books 0 September 27th, 2004 05:24 AM
Word automation in VB bobshark VB How-To 1 June 13th, 2003 08:16 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.