PDA

View Full Version : NEED HELP ADJUSTING CODE -USING VBA WITH REFLECTION FOR UNIX DATABASE



KMDRAKE
09-24-2015, 10:48 AM
I am still fairly new to using VBA and have managed to figure out a lot but I have a code I am running that I have managed to adjust to work but it is not working as efficiently as I would like.

When running the code there are certain accounts that have prompts that not other accounts have. I have managed to make the code run but we have to manually answer the out of ordinary questions manually to get it to pick up again.

How do I adjust the code to make it so the system doesn't expect the string for everything but will automatically answer the question on its own if it does come up.

Here is the section of code that I am having issues with I still have it written into the macro but like I said when it appears with the account we have to answer the questions manually for it to pick back up.

Thanks in advance.


'.StatusBar = "Waiting for Prompt: Do you want to continue processing this patient record? No//"
'.WaitForString LF & "Do you want to continue processing this patient record? No// ", NEVER_TIME_OUT, rcAllowKeystrokes
'.StatusBar = ""
'.Transmit "Y"
'.StatusBar = "Waiting for Prompt: Do you want to continue processing this patient record? No// Y"
'.WaitForString "Y", NEVER_TIME_OUT, rcAllowKeystrokes
'.StatusBar = ""
' Press VtEnter (Simulate pressing the Enter key).
'.TransmitTerminalKey rcVtEnterKey

'.StatusBar = "Waiting for Prompt: Enter <RETURN> to continue."
'.WaitForString LF & "Enter <RETURN> to continue.", NEVER_TIME_OUT, rcAllowKeystrokes
'.StatusBar = ""
' Press VtEnter (Simulate pressing the Enter key).
'.TransmitTerminalKey rcVtEnterKey

' .StatusBar = "Waiting for Prompt: DO NOT TREAT OR SCHEDULE - MT REQUIRED! CALL X6769!"
' .WaitForString LF & " DO NOT TREAT OR SCHEDULE - MT REQUIRED! CALL X", NEVER_TIME_OUT, rcAllowKeystrokes
' .StatusBar = ""
' String omitted because it might change:
' .WaitForString "6769", NEVER_TIME_OUT, rcAllowKeystrokes
' .StatusBar = "Waiting for Prompt: DO NOT TREAT OR SCHEDULE - MT REQUIRED! CALL X6769!"
' .WaitForString "!", NEVER_TIME_OUT, rcAllowKeystrokes
' .StatusBar = ""
' Press VtEnter (Simulate pressing the Enter key).
'.TransmitTerminalKey rcVtEnterKey

SamT
09-24-2015, 12:08 PM
That is not code, it is just a block of comments. Even if it was code, we would need to see at least that entire procedure to have any idea what was going on. A little context about the use of the Procedure could help us help you.

KMDRAKE
09-24-2015, 01:15 PM
That is not code, it is just a block of comments. Even if it was code, we would need to see at least that entire procedure to have any idea what was going on. A little context about the use of the Procedure could help us help you.

This is the macro I am trying to run. I set that specific set referred to originally to "comments" because they don't show up for every account and it would continue entering the commands related to them when it wasn't needed and the rest of the macro would not run appropriately.

Sub DEBTORNOTEAGEDDEBTTEST()
' Generated by the Reflection Macro Recorder on 03-10-2015 13:20:00.19.
' Generated by Reflection for UNIX and OpenVMS 14.0.6.
On Error GoTo ErrorHandler
Const NEVER_TIME_OUT = 0
Dim LF As String ' Chr(rcLF) = Chr(10) = Control-J
Dim CR As String ' Chr(rcCR) = Chr(13) = Control-M
Dim ESC As String ' Chr(rcESC) = Chr(27) = Control-[
Dim excelAPP As Object

Dim z As Integer
z = 2

Set excelAPP = GetObject(, "excel.Application")
Set excelAPP = GetObject("D:\Users\vhacpwdrakek\Desktop\AGED DEBT TEMPLATE TEST.xlsx")

LF = Chr(Reflection2.ControlCodes.rcLF)
CR = Chr(Reflection2.ControlCodes.rcCR)
ESC = Chr(Reflection2.ControlCodes.rcESC)
With Session
.Transmit "^DEBTOR COMMENT LOG" & CR
.StatusBar = "Waiting for Prompt: Select AR DEBTOR:"
.WaitForString LF & "Select AR DEBTOR: ", NEVER_TIME_OUT, rcAllowKeystrokes
Do
z = z + 1
A = excelAPP.ACTIVESHEET.Range("B" & z)
B = excelAPP.ACTIVESHEET.Range("Q" & 3)
C = excelAPP.ACTIVESHEET.Range("P" & 5)

.Transmit A

'.StatusBar = "Waiting for Prompt: Enter <RETURN> to continue."
'.WaitForString LF & "Enter <RETURN> to continue.", NEVER_TIME_OUT, rcAllowKeystrokes
'.StatusBar = ""
' Press VtEnter (Simulate pressing the Enter key).
'.TransmitTerminalKey rcVtEnterKey
'.StatusBar = "Waiting for Prompt: Do you want to continue processing this patient record? No//"
'.WaitForString LF & "Do you want to continue processing this patient record? No// ", NEVER_TIME_OUT, rcAllowKeystrokes
'.StatusBar = ""
'.Transmit "Y"
'.StatusBar = "Waiting for Prompt: Do you want to continue processing this patient record? No// Y"
'.WaitForString "Y", NEVER_TIME_OUT, rcAllowKeystrokes
'.StatusBar = ""
' Press VtEnter (Simulate pressing the Enter key).
'.TransmitTerminalKey rcVtEnterKey

'.StatusBar = "Waiting for Prompt: Enter <RETURN> to continue."
'.WaitForString LF & "Enter <RETURN> to continue.", NEVER_TIME_OUT, rcAllowKeystrokes
'.StatusBar = ""
' Press VtEnter (Simulate pressing the Enter key).
'.TransmitTerminalKey rcVtEnterKey

' .StatusBar = "Waiting for Prompt: DO NOT TREAT OR SCHEDULE - MT REQUIRED! CALL X6769!"
' .WaitForString LF & " DO NOT TREAT OR SCHEDULE - MT REQUIRED! CALL X", NEVER_TIME_OUT, rcAllowKeystrokes
' .StatusBar = ""
' String omitted because it might change:
' .WaitForString "6769", NEVER_TIME_OUT, rcAllowKeystrokes
' .StatusBar = "Waiting for Prompt: DO NOT TREAT OR SCHEDULE - MT REQUIRED! CALL X6769!"
' .WaitForString "!", NEVER_TIME_OUT, rcAllowKeystrokes
' .StatusBar = ""
' Press VtEnter (Simulate pressing the Enter key).
'.TransmitTerminalKey rcVtEnterKey

.StatusBar = "Waiting for Prompt: ...OK? Yes//"
.WaitForString LF & " ...OK? Yes// ", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""
' Press VtEnter (Simulate pressing the Enter key).
.TransmitTerminalKey rcVtEnterKey
.StatusBar = "Waiting for Prompt: Date of Contact: MAR 10,2015//"
.WaitForString LF & "Date of Contact: ", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""
' String omitted because it might change:
' .WaitForString "MAR 10,2015", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = "Waiting for Prompt: Date of Contact: MAR 10,2015//"
.WaitForString "// ", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""
' Press VtEnter (Simulate pressing the Enter key).
.TransmitTerminalKey rcVtEnterKey
.StatusBar = "Waiting for Prompt: Brief Comment:"
.WaitForString LF & "Brief Comment: ", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""
' Press EditPaste (Insert the Clipboard contents at the cursor position).
' Reflection has recorded the record-time contents of the clipboard.
' If you want to use the playback-time contents of the clipboard,
' Uncomment the following line and delete the appropriate record-time data.
' .Paste
.Transmit "AGED DEBT RPT/FIS TERM"
.StatusBar = "Waiting for Prompt: Brief Comment: AGED DEBT RPT/FIS TERM"
.WaitForString "AGED DEBT RPT/FIS TERM", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""
' Press VtEnter (Simulate pressing the Enter key).
.TransmitTerminalKey rcVtEnterKey
.StatusBar = "Waiting for Prompt: Edit? NO//"
.WaitForString LF & " Edit? NO// ", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""
.Transmit "Y"
.StatusBar = "Waiting for Prompt: Edit? NO// Y"
.WaitForString "Y", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""
' Press VtEnter (Simulate pressing the Enter key).
.TransmitTerminalKey rcVtEnterKey
.WaitForString ESC & "[3;1H", NEVER_TIME_OUT, rcAllowKeystrokes
.Transmit "ACCOUNT REVIEWED, TOP/DMC ACTIVE,DEBT IS OVER SIX YEARS, WRITE-OFF PACKET PREPARED AND SENT TO CFO, FISCAL TERMINATED ALL BILLS OVER 6 YEARS OLD"
.TransmitTerminalKey rcVtPF1Key
.Transmit "E"

.StatusBar = "Waiting for Prompt: Follow-up Date:"
.WaitForString LF & "Follow-up Date: ", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""
' Press VtEnter (Simulate pressing the Enter key).
.TransmitTerminalKey rcVtEnterKey
.StatusBar = "Waiting for Prompt: Is this OK? YES//"
.WaitForString LF & "Is this OK? YES// ", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""
' Press VtEnter (Simulate pressing the Enter key).
.TransmitTerminalKey rcVtEnterKey
' .WaitForString LF & "Select Account Management Option: ", NEVER_TIME_OUT, rcAllowKeystrokes

.Transmit "^DEBTOR COMMENT LOG" & CR
.StatusBar = "Waiting for Prompt: Select AR DEBTOR:"
.WaitForString LF & "Select AR DEBTOR: ", NEVER_TIME_OUT, rcAllowKeystrokes

Loop

End With
Exit Sub
ErrorHandler:
Session.MsgBox Err.description, vbExclamation + vbOKOnly
' Recording stopped at 13:22:44.84.
End Sub

SamT
09-24-2015, 03:29 PM
That is not Microsoft VBA code

In broad terms, what are you wanting the code to do?

Reflection Terminal Emulator VBA reference links:
http://support.attachmate.com/product/?prod=R2014
http://support.attachmate.com/techdocs/index/R2014.html#Programming_and_Development
http://docs.attachmate.com/reflection/2014/r1/help/en/vba_guide/#topic1.html
http://docs.attachmate.com/reflection/2014/r1/help/en/vba-reference/
Reflection 14.x Visual Basic (http://docs.attachmate.com/reflection/14.0/vbug.pdf) (PDF - 1.05 MB)

Here is the code you posted re-commented with State comments

Option Explicit

Sub DEBTORNOTEAGEDDEBTTEST()
' Generated by the Reflection Macro Recorder on 03-10-2015 13:20:00.19.
' Generated by Reflection for UNIX and OpenVMS 14.0.6.
On Error GoTo ErrorHandler
Const NEVER_TIME_OUT = 0
Dim LF As String ' Chr(rcLF) = Chr(10) = Control-J
Dim CR As String ' Chr(rcCR) = Chr(13) = Control-M
Dim ESC As String ' Chr(rcESC) = Chr(27) = Control-[
Dim excelAPP As Object

Dim z As Integer
z = 2

Set excelAPP = GetObject(, "excel.Application")
Set excelAPP = GetObject("D:\Users\vhacpwdrakek\Desktop\AGED DEBT TEMPLATE TEST.xlsx")

LF = Chr(Reflection2.ControlCodes.rcLF)
CR = Chr(Reflection2.ControlCodes.rcCR)
ESC = Chr(Reflection2.ControlCodes.rcESC)
With Session
.Transmit "^DEBTOR COMMENT LOG" & CR
.StatusBar = "Waiting for Prompt: Select AR DEBTOR:"
.WaitForString LF & "Select AR DEBTOR: ", NEVER_TIME_OUT, rcAllowKeystrokes
Do
z = z + 1
A = excelAPP.ActiveSheet.Range("B" & z)
B = excelAPP.ActiveSheet.Range("Q" & 3)
C = excelAPP.ActiveSheet.Range("P" & 5)

''''Transmit A = Range("B" & z)
.Transmit A

''''Waiting for Response
.StatusBar = "Waiting for Prompt: ...OK? Yes//"
.WaitForString LF & " ...OK? Yes// ", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""
''''Simulate pressing the Enter key.
.TransmitTerminalKey rcVtEnterKey

''''Waiting for Response
.StatusBar = "Waiting for Prompt: Date of Contact: MAR 10,2015//"
.WaitForString LF & "Date of Contact: ", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""

''''Waiting for Response
.StatusBar = "Waiting for Prompt: Date of Contact: MAR 10,2015//"
.WaitForString "// ", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""
'''''Simulate pressing the Enter key.
.TransmitTerminalKey rcVtEnterKey

''''Waiting for Response
.StatusBar = "Waiting for Prompt: Brief Comment:"
.WaitForString LF & "Brief Comment: ", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""

' Press EditPaste (Insert the Clipboard contents at the cursor position).
' Reflection has recorded the record-time contents of the clipboard.
' If you want to use the playback-time contents of the clipboard,
' Uncomment the following line and delete the appropriate record-time data.
' .Paste

''''Transmit UD String
.Transmit "AGED DEBT RPT/FIS TERM"
.StatusBar = "Waiting for Prompt: Brief Comment: AGED DEBT RPT/FIS TERM"

''''Waiting for Response
.WaitForString "AGED DEBT RPT/FIS TERM", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""
'''''Simulate pressing the Enter key.
.TransmitTerminalKey rcVtEnterKey

''''Waiting for Response
.StatusBar = "Waiting for Prompt: Edit? NO//"
.WaitForString LF & " Edit? NO// ", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""
''''TRansmit UD Strin
.Transmit "Y"

''''Waiting for Response
.StatusBar = "Waiting for Prompt: Edit? NO// Y"
.WaitForString "Y", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""
'''''Simulate pressing the Enter key.
.TransmitTerminalKey rcVtEnterKey

''''Waiting for Response
.WaitForString ESC & "[3;1H", NEVER_TIME_OUT, rcAllowKeystrokes

''''Transmit UD String
.Transmit "ACCOUNT REVIEWED, TOP/DMC ACTIVE,DEBT IS OVER SIX YEARS, WRITE-OFF PACKET PREPARED AND SENT TO CFO, FISCAL TERMINATED ALL BILLS OVER 6 YEARS OLD"
.TransmitTerminalKey rcVtPF1Key


''''Transmit UD String
.Transmit "E"
.StatusBar = "Waiting for Prompt: Follow-up Date:"
''''Waiting for Response .WaitForString LF & "Follow-up Date: ", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""
'''''Simulate pressing the Enter key.
.TransmitTerminalKey rcVtEnterKey

''''Waiting for Response
.StatusBar = "Waiting for Prompt: Is this OK? YES//"
.WaitForString LF & "Is this OK? YES// ", NEVER_TIME_OUT, rcAllowKeystrokes
.StatusBar = ""
.TransmitTerminalKey rcVtEnterKey

''''Transmit UDString
.Transmit "^DEBTOR COMMENT LOG" & CR
.StatusBar = "Waiting for Prompt: Select AR DEBTOR:"
.WaitForString LF & "Select AR DEBTOR: ", NEVER_TIME_OUT, rcAllowKeystrokes

Loop

End With
Exit Sub
ErrorHandler:
Session.MsgBox Err.Description, vbExclamation + vbOKOnly
' Recording stopped at 13:22:44.84.
End Sub
The question is, if this version works for some of your accounts, how many distinct versions would you need to work with all the accounts? Or maybe; Better to ask: How many "Transmit" options would you need.

If you start with the basic "No Options" code, then use MS VBA If...Then...ElseIF statements To set the appropriate Transmit String ...

What happens if the Transmit String is empty (= "")? Wuld you have to use a GoTo label instead?