Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 编译错误:需要常量表达式_Vba_Excel - Fatal编程技术网

Vba 编译错误:需要常量表达式

Vba 编译错误:需要常量表达式,vba,excel,Vba,Excel,我偶然发现了一个编译错误,但我不知道这是什么问题。当尝试将符号更改为输入变量TickerID时,我得到了错误,否则在输入例如yahoo ticker name时,效果非常好 代码 信息是明确的。当你声明一个常量时,你给它的值也必须是常量。在这种情况下,它的一部分是参数TickerId,它是可变的。不能用变量值声明常量 要解决这个问题,我认为您可以使用Dim而不是Const,并且根本不将ConnStringInput设置为常量。信息很清楚。当你声明一个常量时,你给它的值也必须是常量。在这种情况下,

我偶然发现了一个编译错误,但我不知道这是什么问题。当尝试将符号更改为输入变量TickerID时,我得到了错误,否则在输入例如yahoo ticker name时,效果非常好

代码


信息是明确的。当你声明一个常量时,你给它的值也必须是常量。在这种情况下,它的一部分是参数TickerId,它是可变的。不能用变量值声明常量


要解决这个问题,我认为您可以使用Dim而不是Const,并且根本不将ConnStringInput设置为常量。

信息很清楚。当你声明一个常量时,你给它的值也必须是常量。在这种情况下,它的一部分是参数TickerId,它是可变的。不能用变量值声明常量

为了解决这个问题,我认为您可以使用Dim而不是Const,并且根本不将ConnStringInput设置为常量

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