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
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