- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个循环获取股票价格的 VBA 代码。
在此 API 源中找不到股票代码。这将导致这些股票出错。
我正在使用 On Error Resume Next
所以 VBA 代码将继续到下一个符号。
我的问题是错误的符号将返回最后一个没有错误的股票代码的股票价格。
我想将错误的股票代码的结果设为空白或零。
当前结果 - 斜体符号是错误的。
股票代码 价格
BDO 158.00
ABS 15.80
绿色 1.87
阿尔希 1.87
土地 1.87
可编程逻辑 Controller 0.57
磅值 0.57
0.57
期望的结果 - 错误的斜体符号将导致或返回 0
股票代码 价格
BDO 158.00
ABS 15.80
绿色 1.87
0
土地 0
可编程逻辑 Controller 0.57
低密度脂蛋白 0
曾经 0
Set myrequest = CreateObject("WinHttp.WinHttpRequest.5.1")
myrequest.Open "Get", "http://phisix-api.appspot.com/stocks/" & symbol & ".json"
myrequest.Send
Dim Json As Object
Set Json = JsonConverter.ParseJson(myrequest.ResponseText)
i = Json("stock")(1)("price")("amount")
ws.Range(Cells(n, 2), Cells(n, 2)) = i
n = n + 1
On Error Resume Next
Next X
ws.Columns("B").AutoFit
MsgBox ("Stock Quotes Refreshed.")
ws.Range("B4:B" & lastrow).HorizontalAlignment = xlGeneral
ws.Range("B4:B" & lastrow).NumberFormat = "#,##0.00"
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
最佳答案
您的代码设置 On Error Resume Next
在第一次循环结束时,从那时起忽略任何和所有错误。那很糟。
使用 OERN 的一般方法应该是
Other non error causing code
Optionally initialise variables in preparation for error trap
On Error Resume Next
Execute the instruction that might cause an error
On Error GoTo 0
If (test if instruction succeeded) Then
Process the result
Else
Optionally handle the error case
End If
关于excel - 当 'On Error Resume Next' 将先前的值留在变量中时,如何返回空白或零?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59550283/
我的应用将 SceneKit 内容的“页面”与图像和文本交替。当我从图像页面前进到新的 SceneKit 页面时,前一个 SceneKit 页面中的内容会短暂显示,然后被新内容替换。时髦。 我只使用一
我正在尝试处理(在 C# 中)包含一些数字数据的大型数据文件。给定一个整数数组,如何对其进行拆分/分组,以便如果下一个 n(两个或更多)是负数,则前一个 n 元素被分组。例如,在下面的数组中,应该使用
刚接触promises,研究过。所以我的代码和我的理解: sql.connect(config).then(function(connection) { return connection.req
目前我在 if (roobaf) block 中有一些代码,这取决于 foo 和 bar 是否为假。我可以在 block 内再次检查这些条件,但感觉像是不必要的代码重复。 if (foo) {
我是一名优秀的程序员,十分优秀!