Solved

Use of AppActivate with VB.NET

Posted on 2004-04-30
3
7,457 Views
Last Modified: 2013-11-14
The following piece of code in Button5  has been working to enter a much used application every day for the last year.

I initially had problems in gettting  the sendkeys to work but found that typing the AppActivate line twice fixed the problem.

I have now added an additional Button6  to my apllication with very little code in it  and have not altered the code in Button5 at all.

The problem is that external program gets to the point where the "Open Company" screen is active but my program does not sendkeys (the original problem before I typed the AppActivate line twice) and so it just waits at the correct screen but goes no further.

I cant understand how Button5 does not work anymore given that I have not altered the code for that Button at all.

If anyone can suggest whats wrong or give an alternative solution I'll be very grateful. I am using Windows 2000 Professional and VB.NET




'My Coding follows..
'I have this at the top of my program..

Option Strict Off
Option Explicit On
Imports VB = Microsoft.VisualBasic

'Other code follows here ...

'Then...

'Routine to open a third party program and enter predifined values into its User Name / Password screen and also enter a predefined date



 Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Dim i As Integer
        Dim strprodate As String
        Dim DUM As String
       

        Try

            'start the payroll program

            Shell("c:\Payroll Programs\payroll.exe", vbNormalFocus)

            ' next line to create a pause while the external program starts up

            DUM = InputBox("YOU MUST CLICK OK in this little box when Payroll  list appears... ", "CLICK OK ON THIS LITTLE BOX WHEN PAYROLL  LIST APPEARS", , 200, 50)



            ' get predefined value from external file


            FileOpen(1, "C:\STATUS\STATUS.CUR", OpenMode.Input)
            Input(1, DUM)
            Input(1, DUM)
            Input(1, DUM)
            Input(1, DUM)
            Input(1, strprodate)
            FileClose(1)


           ' set focus on the Open Company form... does not work unless statement is written twice... I dont know why...

            Microsoft.VisualBasic.Interaction.AppActivate("Open Company")
            Microsoft.VisualBasic.Interaction.AppActivate("Open Company")


            'send characters to the active form
 
            ' these tabs get me to the correct screen

            System.Windows.Forms.SendKeys.Send("{tab}{tab}{tab}{tab}{tab}")

           ' I always want to start on the third line down so I go up to the top of the form and then down three lines            

            For i = 1 To 5
                System.Windows.Forms.SendKeys.Send("{Up}")
            Next

            For i = 1 To 3
                System.Windows.Forms.SendKeys.Send("{Down}")
            Next

            System.Windows.Forms.SendKeys.SendWait("{Enter}MANAGER{tab}{tab}")
           
            System.Windows.Forms.SendKeys.SendWait(strprodate)

           ' password is blank so just hit enter

            System.Windows.Forms.SendKeys.SendWait("{enter}")
       
 Finally


 End Try

 End Sub
0
Comment
Question by:GREEBA
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 48

Accepted Solution

by:
AlexFM earned 250 total points
ID: 10963463
Replace
Shell("c:\Payroll Programs\payroll.exe", vbNormalFocus)

with Process.Start function:

Dim p as Process
p = Process.Start("c:\Payroll Programs\payroll.exe")
p.WaitForInputIdle()
' now you can send keys


http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdiagnosticsprocessclassstarttopic3.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdiagnosticsprocessclasswaitforinputidletopic1.asp
0
 

Author Comment

by:GREEBA
ID: 10984887
Thanks for your reply.

Half way there as the program works in Debug mode when I am in VB.Net but when I build it into a .MSI file and install it
it freezes at the same point as it did before I used the Process.Start function.

I seem to missing something still.


Jim
0
 

Author Comment

by:GREEBA
ID: 11007276
I have found the problem. I has increased the size of my form to accomodate Button6. This form was used to activate the external program that was freezing up and not accepting the SendKeys statements. I reduced the size of my form back to its original size and it now works fine with Button6 squashed in on it. So it seems that the size of overlapping forms can affect the SendKeys command even though the form I am sending the Sendkeys commands to is the highlighted active form.

Both the Shell command and the Process.Start work if the form is its original size. Wierd.

As AlexFM was the only respondent I give all the points to you and thanks for you interest.

Jim
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Monitor input from a computer is usually nothing special.  In this instance it prevented anyone from using the computer.  This was a preconfiguration that didn't work.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question