0

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?

Wallenbees
  • 61
  • 8
  • Have you tried to switch to a ["GetString"](https://docs.attachmate.com/extra/x-treme/apis/com/getstringmethod_exa.htm) logic? NoDataChk = Sess0.GETSTRING(iRow, 1, 4). There is an old question that may be [useful](https://stackoverflow.com/questions/10309636/attachmate-data-scraping-macro-that-prints-pages-to-file) as well. Sometimes the screen may have hidden contents, thus, I'd strongly suggest to read by row, column and length logic. – Sgdva Aug 08 '22 at 21:33
  • @Sgdva I tried to use getstring and still couldn't make it work. I dont get an error, but it returns the same result whether correct or not. – Wallenbees Aug 08 '22 at 23:09
  • Then I would suggest looping through all the rows and columns and write that to a sheet so you look how the screen is being read, it would be impossible for us to replicate by being unable to access the screen (as I stated, even if you update sample data, Xtra sometimes is not read the same as shown and that is something that you only notice when debugging the real thing) – Sgdva Aug 09 '22 at 14:07

1 Answers1

0

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
Tim Williams
  • 154,628
  • 8
  • 97
  • 125
  • When I am doing that it is still returning not eligible even when there is data. That is why I was trying to skip. Im not GREAT at attachmate, so I am not sure if there is a better way to use nodatachk. – Wallenbees Aug 08 '22 at 18:19
  • `NoDataChk` really a single space `" "` when there's no eligibility, or is it an empty string `""` ? I've never used Attachmate so I can't offer anything specifically related to that platform. I don't see where the value of `iRow` gets populated? – Tim Williams Aug 08 '22 at 18:20
  • iRow is a component within Attachmate, the trouble is I am having to lean blindly on some older code that a former colleague had passed on to me. It seems like some of the folks around here have dabbled enough with Attachmate that sometimes I can get clarification. – Wallenbees Aug 08 '22 at 18:30