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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ehlapi32.DLL - Interaction with Mainframe

Status
Not open for further replies.

jimlee

Programmer
Jan 27, 2001
213
GB
Hi,

I have a problem where I'm using a VBA macro to interact with mainframe database. Admittedly I did not write this macro, but amended values for it to work with my scenario. What it basically does is:

- takes a value from Excel
- pastes it into a screen position in the mainframe
- stores the returned value
- pastes the stored value back to Excel

However, when running the code from VBA, via PF8 (ie stepping through the code), it works fine. If I PF5 to run the run, it fails by loosing its place at position 1148.

Please, please, please can anyone help or explain why?
Thanks in advance!

VBA Code
-----
"
Declare Function WD_ConnectPS Lib "C:\Program Files\Rumba-52C\SYSTEM\Ehlapi32.DLL" (ByVal hInstance As Long, ByVal ShortName As String) As Integer
Declare Function WD_SendKey Lib "C:\Program Files\Rumba-52C\SYSTEM\Ehlapi32.DLL" (ByVal hInstance As Long, ByVal KeyData As String) As Integer
Declare Function WD_CopyPSToString Lib "C:\Program Files\Rumba-52C\SYSTEM\Ehlapi32.DLL" (ByVal hInstance As Long, ByVal Position As Integer, ByVal Buffer As String, ByVal length As Integer) As Integer
Declare Function WD_DisconnectPS Lib "C:\Program Files\Rumba-52C\SYSTEM\Ehlapi32.DLL" (ByVal hInstance As Long) As Integer
Declare Function WD_SetCursor Lib "C:\Program Files\Rumba-52C\SYSTEM\Ehlapi32.DLL" (ByVal hInstance As Long, ByVal Position As Integer) As Integer

Sub Rumba()

Dim retval As Integer
Dim screen As String

Dim Nom_S As String
Dim NSub_S As String

'Connects the REXX application program to the presentation space window
retval = WD_ConnectPS(100, "A")
If retval = 1 Then
MsgBox ("This will not run on a users own version of Rumba. Please launch from menu.")
End
End If

screen = String$(Val(7), 0) 'Set value
Do 'What screen
RV = WD_CopyPSToString(100, 16, screen, 7) 'Copy data from screen to dataset
Loop Until RV = 0 'What the above successful?
screen = Trim(screen)

If screen <> "Nom/Sub" Then
MsgBox ("Ensure you are in Nom/Sub Function and Restart")
WD_DisconnectPS (100)
End
End If

Sedol = ActiveCell

Do Until ActiveCell.Value = ""
'Cursor. First value always 100? Second value position in char accross screen

RV = WD_SetCursor(100, 1148)

'Send keystroke until successful
Do
RV = WD_SendKey(100, Sedol)
Loop Until RV = 0
Do 'Enter
RV = WD_SendKey(100, "@E")
Loop Until RV = 0

'Setup Field positions
Nom = 268
NSub = 828

'Retrieve fields values
screen = String$(Val(3), 0)
Do
RV = WD_CopyPSToString(100, Nom, screen, 3)
Loop Until RV = 0
Nom_S = Trim(screen)
Do
RV = WD_CopyPSToString(100, NSub, screen, 3)
Loop Until RV = 0
NSub_S = Trim(screen)

Do 'PF9
RV = WD_SendKey(100, "@9")
Loop Until RV = 0

'Paste field values into Excel
ActiveCell.Offset(0, 1) = Nom_S
ActiveCell.Offset(0, 2) = NSub_S

ActiveCell.Offset(1, 0).Activate
Loop

WD_DisconnectPS (100)
End Sub
"
-----

Mock of Mainframe screen
-----
"
Nominee Code... (Nom - Cursor Position 268)
Sub Account... (NSub - Cursor Position 828)
Sub-Account Ref... (Cursor Position 1148)


jimlad

"There's this thing called being so open-minded your brains drop out." - Richard Dawkins
 



Hi,

When you use "screen scraper" code, you must be aware of the delays that occur in the screen response process that are not in any way oconnected to your program. You need some means of checking the response from that system.

Check the Ehlapi help for some means of delay. I notice that you do have Do...Loop Until logic, but that may not be sufficient.

I don't use Ehlapi, but I do use AttachMate. Try doing a search on hllapi for more information.

Skip,

[glasses] [red]Be Advised![/red] A chicken, who would drag a wagon across the road for 2 cents, is…
POULTRY in motion to PULLET for a PALTRY amount! [tongue]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top