Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

yet another VB question from Bolox

Posted on 2002-05-29
12
Medium Priority
?
143 Views
Last Modified: 2010-05-02
this one seems a bit trickier.........(i think)

I am in a travel agency, i want my VB database of discounted fares to communicate to another programme.

they will click on a button on my form i made, and it will pass the text AUTOMATICALLY to another programme they have open, called Sabre, it will type in :

1abc123def1200

and then press enter for them

Any ideas, i know how to do a copy to clip board, and then for them to paste it in to the programme, but i want to be even lazier.

Also,

If it is not too much bother, i want on the Sabre screen for the keys ALT and ENTER pressing befor the text is entered.

Thanx Experts

Bolox


0
Comment
Question by:bolox
[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
  • 7
  • 5
12 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 7041338
You can use SendKeys to achieve this or DDE or even an API solution. Let us try sending keystrokes first:

SendKeys "%{ENTER}" & Text1.Text & "{ENTER}"

where % is the ALT key modifier and Text1.Text contains the information to send.

Of course before you do this you need to activate the sabre application. You could use

AppActivate "SABRE"

Assuming that the title of the window of the sabre application starts with "SABRE" if not then use whatever it does start with.
0
 
LVL 1

Author Comment

by:bolox
ID: 7041343
ALT key modifier??????
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 7041354
Pressing ALT + ENTER at the same time, the Ctrl, Alt & Shift keys are generally referred to as modifiers because they are not keypresses in their own right but modify the way the other keys pressed at the same time behave.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:bolox
ID: 7041360
the method......

appActive "Sabre"

what if Sabre is not open on screen, this causes an error and crashes,

what is the best way to do this....

if appactive "sabre" then
sendkeys........
else
msgbox"Sabre is not open"
end if
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 400 total points
ID: 7041368
Then that is a bit more tricky. The AppActivate statement doesn't return whether or not it worked. However it does generate an error if no window is found that matches the name specified so:

On Error Resume Next
Err.Clear
AppActivate "sabre"
If Err.Number = 0 Then
 'It was activated successfully
Else
 'It doesn't exist so lets launch it:
 SabreApp = Shell("c:\program files\sabre\sabre.exe",vbNormalFocus)
 AppActivate SabreApp
End If
'Then use sendkeys as appropriate. You may want to automate logging in etc in the same way if you have had to launch the sabre application.

There are always other ways of course, including API calls which can make this much more reliable a method but you have to balance complexity and results.
0
 
LVL 1

Author Comment

by:bolox
ID: 7041643
for some reason this does not work on this programme???

I have made a notpad called Sabre.txt opened that and that eworks great???

Maybe i should try your API ?

Any ideas?

It just kept up coming with your error,
Sabre is not loaded???

0
 
LVL 1

Author Comment

by:bolox
ID: 7041646
is there a way of saying..

open active window which has the textr "Sabre" in it somewhere????

B
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 7041681
Well you could use API solutions to enumerate all top level windows and find one that has the word sabre in it somewhere. Then set this window to have the focus.

Paste this code into a module:

Private strTitle As String
Declare Function EnumWindows Lib "user32" (ByVal lpEnumFunc As Long, ByVal lParam As Long) As Boolean
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Declare Function Putfocus Lib "user32" Alias "SetFocus" (ByVal hwnd As Long) As Long
Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long

Public Function EnumWindowsProc(ByVal hwnd As Long, ByVal lParam As Long) As Boolean
    Dim sSave As String, Ret As Long
    Ret = GetWindowTextLength(hwnd)
    sSave = Space(Ret)
    GetWindowText hwnd, sSave, Ret + 1
    If UCase(sSave) Like "*" & UCase(strTitle) & "*" Then
        SetForegroundWindow hwnd
        Putfocus hwnd
        EnumWindowsProc = False
    End If
    Debug.Print Str$(hwnd) + " " + sSave
    EnumWindowsProc = True
End Function

Public Sub ShowWindow(ByVal WindowTitle As String)
    strTitle = WindowTitle
    EnumWindows AddressOf EnumWindowsProc, ByVal 0&
End Sub

Then call the ShowWindow Method like this:

Private Sub Command1_Click()
  ShowWindow "Sabre"
End Sub

The first window matching this name will be made the foreground window on the system.
0
 
LVL 1

Author Comment

by:bolox
ID: 7041693
Excellent yet again Tim,

You are my mentor

B
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 7041704
You are welcome bolox, any time.
0
 
LVL 1

Author Comment

by:bolox
ID: 7041710
Not for a while, no points left again
0
 
LVL 1

Author Comment

by:bolox
ID: 7351702
I know it has been a while, but i am just about to use this again.

If the window sare is not open, it goes into an infinite loop, trying to press the enterkey, (it only stopps if i press the windows key hence allowing the system to press enter)

Any ideas?

B
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

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