我想我已经接近这个代码了,但可能需要一些帮助。我正在循环中运行一个函数,以检查帐户是否符合条件,这是基于Attachmate额外的返回。我试图使用的代码是:
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目前,这是返回合格的,即使返回没有数据。你知道我在这里做错什么了吗?
发布于 2022-08-08 18:11:25
如果您的代码击中了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, HostSettleTimehttps://stackoverflow.com/questions/73282095
复制相似问题