- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我偶然发现了一个编译错误,但不知道可能是什么问题。当试图将符号更改为输入变量( TickerID )时,我得到了错误,否则在输入例如“yhoo”作为雅虎股票名称时工作得很好。
代码
Private Sub CmdBtn_Add_Click()
'---------------------------------------------------------------------------------------'
' Checks that inputted ticker name is correct and calls import class after confirmation
'---------------------------------------------------------------------------------------'
' General Variables---------'
Dim TickerID As String: TickerID = UCase(Add_Instrument.TxtBox_Instrument.Value)
'--------------------------'
'Check if input field is not empty
If TickerID = "" Or Application.WorksheetFunction.IsText(TickerID) = False Then
MsgBox "Please provide a valid ticker ID"
Exit Sub
End If
Debug.Print TickerID
'Check Ticker name exists through YQLBuilder class
Dim YQLBuilder As YQLBuilder: Set YQLBuilder = New YQLBuilder
Call YQLBuilder.TickerCheck(TickerID)
' Call ImportData(TickerID)
' MsgBox "Please check the ticker name. It is in the wrong format"
End Sub
Public Sub TickerCheck(TickerID As String)
'---------------------------------------------------------------------------------------'
' Built 2014-11-05 Allows parsing of XML data through YAHOO API YQL
' 2014-12-21: Not fully built yet, see where it can be of use
'---------------------------------------------------------------------------------------'
' General Variables---------'
Const ConnStringStart As String = "http://query.yahooapis.com/v1/public/yql?q="
Const ConnStringLast As String = "&diagnostics=true&env=store://datatables.org/alltableswithkeys"
'---------------------------'
Const ConnStringInput As String = "select * from yahoo.finance.stocks where symbol='" _
& TickerID & "'" **<----- Error here!**
Debug.Print ConnStringStart & ConnStringInput & ConnStringLast
Dim YQLNodes As MSXML2.IXMLDOMNodeList
Dim YQLReq As MSXML2.DOMDocument60
Set YQLReq = New MSXML2.DOMDocument60
YQLReq.async = False
YQLReq.Load ConnStringStart & ConnStringInput & ConnStringLast
YQLReq.setProperty "SelectionNamespaces", "xmlns:f='http://www.yahooapis.com/v1/base.rng'"
Set YQLNodes = YQLReq.SelectNodes("//CompanyName")
Dim xNode As MSXML2.IXMLDOMNode
For Each xNode In YQLNodes
Debug.Print xNode.Text
Next xNode
Debug.Print YQLNodes.Length
End Sub
最佳答案
信息很明确。当你声明一个常量时,你给它的值也必须是常量。在这种情况下,它的一部分是参数 TickerId,它是可变的。不能用变量值声明常量。
要解决这个问题,我认为您可以使用 Dim
而不是 Const
并且根本不使 ConnStringInput 成为常量。
关于vba - 编译错误: Constant expression required,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27590606/
所以如果我在 C++ 中有这样的东西: char A_char = 'A'; char * myPtr = &A_char; const char * myPtr = &char_A; //point
我试图在我的 Perl 脚本中将魔数(Magic Number)声明为常量,如 perlsub 中所述。但是,我收到警告: $ cat foo.perl use warnings ; use stri
我想为 data Constant a b = Constant a 这是我的直接尝试: instance Foldable (Constant a) where foldr f b (Const
我在客户端和服务器端拆分了我的文件夹,但我没有从父文件夹工作,我表现得好像它们是 2 个不同的文件夹...现在我想部署到 Heroku 但我为此需要一个主文件夹,所以我想更改我的 webpack.co
当函数不修改对象参数时,我总是让它请求一个常量引用,即使引用的对象不是真正的常量。这是错误的吗? 对于包装类,我想这样写: template class Wrapper{ private: B*
核心常量表达式的定义取决于常量表达式的概念,如要点 (2.7.1) 和 (2.9.1) 所示N4140 的。 §5.19/2: A conditional-expression e is a core
我有以下代码片段,它按预期工作。其中 x 是一个变量 var myVariable = (x === 'A' || x=== 'B') ? 'sui' : 'pai'; 但是闭包编译器正在将它转换为
我是一个国际化应用程序。其中一部分在于菜单的国际化。没关系。 通过 GWT,我可以使用 Constants 接口(interface)。 现在我必须国际化该应用程序的帮助,其中包括一些涉及菜单的文本。
在 Bjarne Stroustrup 的 A Tour of C++ 中,每章末尾都列出了一些建议。在第一章的结尾,其中一个写道: Avoid ‘‘magic constants;’’ use sy
创建常量数组的常量数组的语法是什么? 我希望函数参数是常量 char* 字符串的常量数组。 最佳答案 您可以通过将 const 放在第一个星号的右侧来实现,例如 void f(const char *
我有一本带图书馆的 Chef Recipe ,例如库.rb。它包含一个 CONSTANT: CONSTANT = 'constant' 当我为这本 Recipe 编写单元测试时,它总是给我警告: (S
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicate: How to check for equals? (0 == i) or (i == 0) Why does
我有以下代码: constexpr unsigned long long power_function(const unsigned long long prime, const unsigned l
在一个页面上,我有几个 Angular 模块。我为每个模块定义了一个包含模块版本的常量。 var module1 = angular.module('module1').constant('versi
C++14 中的§5.19/3 定义了一个整型常量表达式和一个转换后的常量表达式: An integral constant expression is an expression of integr
如果您打开 R# 选项并转到代码编辑> C# > 命名样式,则有 2 个设置与我非常相似。本地常量和常量字段(私有(private))。一种是 lowerCaseCamel,另一种是 UpperCam
如何将恰好命名为 reverse 的以下方法重写为允许任何枚举类型的泛型方法。 public class TestX { enum Gender { male, female } pu
我和我的一位队友进行了一次有趣的谈话。 CONSTANT.equals(VARIABLE) 是否比 Java 中的 VARIABLE.equals(CONSTANT) 快? 我怀疑这是一个虚假陈述。但
我想在 c 程序中执行脚本 cmd,所以函数 SYSTEM(CONST CHAR) 可以执行它,但我想使用这个函数和 3 个不同的参数写入一次。谁能帮帮我,有没有那种功能。 最佳答案 如果我猜对了,您
VStudio 或 ReSharper 给我以下建议: constant 在这种情况下意味着什么?如果它是当前方法作用域中的一个常量,目的是什么?方法往往很小,因此与常规 var 相比,它不应该有任何
我是一名优秀的程序员,十分优秀!