Reputation: 83
I think I am close on this code but could use some help. I am running a function inside of a loop to check to see if accounts are eligible based on a return from Attachmate Extra. The code I am trying to use is:
Function AccountEligible(Account) As String
Dim ws As Worksheet
Dim LastPageCheck As String
Dim AccountCheck As String
Dim AcctNumber As String
Dim iRow As Integer
Dim AcctType As String
Dim FromDate As String
Dim ToDate As String
Dim Cusip As String
Dim Sess0 As Object
Set ws = ThisWorkbook.Sheets("Starting Page") 'use an explicit worksheet reference
FromDate = ws.Range("I16").Value
ToDate = ws.Range("I17").Value
Cusip = ws.Range("I14").Value
' ******** set session to bluezone **********
Set Sess0 = CreateObject("BZWhll.WhllObj")
Sess0.Connect ("") 'Connect to bluezone session 1 - internally called A
HostSettleTime = 200 'set 200 milliseconds to wait for session to respond
Sess0.WaitReady 10, HostSettleTime
' ******** Navigate to LTXN and enter account number **********
Sess0.SendKeys ("<clear>")
Sess0.WaitReady 10, HostSettleTime
Sess0.SendKeys ("LTXN ") & Account
Sess0.SendKeys ("<Enter>")
Sess0.WaitReady 10, HostSettleTime
'*********This is the search filter for CUSIP *************
Sess0.SendKeys ("<Tab>")
Sess0.SendKeys ("<Tab>")
Sess0.SendKeys ("CUS")
Sess0.SendKeys Cusip
Sess0.SendKeys ("<Enter>")
Sess0.WaitReady 10, HostSettleTime
' ******** Add the date filter to LTXN **********
Sess0.SendKeys ("<F12>")
Sess0.WaitReady 10, HostSettleTime
Sess0.SendKeys ("<Tab>")
Sess0.WaitReady 10, HostSettleTime
Sess0.SendKeys ("<Tab>")
Sess0.WaitReady 10, HostSettleTime
Sess0.SendKeys ("<Tab>")
Sess0.WaitReady 10, HostSettleTime
Sess0.SendKeys ("<Tab>")
Sess0.WaitReady 10, HostSettleTime
Sess0.SendKeys ("<Tab>")
Sess0.SendKeys FromDate
Sess0.WaitReady 10, HostSettleTime
Sess0.SendKeys ToDate
Sess0.WaitReady 10, HostSettleTime
Sess0.SendKeys ("<Enter>")
Sess0.WaitReady 10, HostSettleTime
' ******** Check for Valid Class Action Data **********
Sess0.ReadScreen NoDataChk, 1, iRow, 4 'check for no data in at all
If NoDataChk = " " Then GoTo 1000 Else GoTo 1001 'return the result
1000
AccountEligible = "Not Eligible"
Sess0.WaitReady 10, HostSettleTime
1001
AccountEligible = "Eligible"
Sess0.WaitReady 10, HostSettleTime
End Function
Currently this is returning Eligible even if the return has no data. Any idea what I am doing wrong here?
Upvotes: 0
Views: 92
Reputation: 166755
If your code hits the Goto 1000
, it will execute the 2 lines below that label and then just continue into the code below the 1001
label...
If NoDataChk = " " Then GoTo 1000 Else GoTo 1001 'return the result
1000:
AccountEligible = "Not Eligible"
Sess0.WaitReady 10, HostSettleTime
1001:
AccountEligible = "Eligible"
Sess0.WaitReady 10, HostSettleTime
Goto
is not a good option for regular flow control though, except in certain use case, such as breaking out from nested loops.
This calls for just a regular If...Else
:
Sess0.ReadScreen NoDataChk, 1, iRow, 4 'check for no data in at all
If NoDataChk = " " Then
AccountEligible = "Not Eligible"
Else
AccountEligible = "Eligible"
End If
Sess0.WaitReady 10, HostSettleTime
Upvotes: 0