我想我已经接近这段代码了,但需要一些帮助。我正在循环中运行一个函数,根据Attachmate Extra的返回检查帐户是否符合条件。我尝试使用的代码是:
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
目前,即使报税表没有数据,也会返回"合格"。知道我在这里做错了什么吗?
如果您的代码命中Goto 1000
,它将执行该标签下方的2行,然后继续进入1001
标签下方的代码。。。
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
不是一个好的选择,除非在某些用例中,例如从嵌套循环中分离出来。
这只需要一个常规的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