简体   繁体   English

JavaScript / JScript中缺少分号

[英]Missing semicolon in JavaScript / JScript

I have the following code that I am writing inside BRIO (Hyperion Interactive Reporting Studio). 我在BRIO(Hyperion Interactive Reporting Studio)中编写了以下代码。 The code is either in JavaScript or JScript, though I am not sure which as I am just learning the syntax and am not sure how they differ. 代码不是JavaScript就是JScript,尽管我不确定是哪一种语言,因为我只是在学习语法,也不知道它们之间的区别。

Anyway, I am getting syntax Script(line number) missing; before statement 无论如何,我越来越Script(line number) missing; before statement语法Script(line number) missing; before statement Script(line number) missing; before statement error on the following lines: 以下行中的Script(line number) missing; before statement错误:

if (xYear == 2012 && yMonth == 10) {stopIt = "Yes"} else (yMonth == 12) {stopIt = "Yes"}

and

var myDate = New Date(xYear, yMonth, 1)

in the code below. 在下面的代码中。

var xYear
var yMonth

for (j = 2009; j =  2012; j++)

{ 

    xYear = j

    if (xYear == 2009) {yMonth = 7} else {yMonth = 1}

    var StopIt = "No"

    Do 

    {
    var myDate = New Date(xYear, yMonth, 1)
    Alert (myDate)

    //var myQuery = ActiveDocument.Sections["qry_billing"]

    //myQuery.Limits["Accounting Year Month"].CustomValues.RemoveAll()
    //myQuery.Limits["Accounting Year Month"].CustomValues.Add(myDate)
    //myQuery.Limits["Accounting Year Month"].SelectedValues.Add(myDate)

    //myQuery.Process()

    //var Path = "W:\\Major Accounts\\Alliance Process\\AAA\\reference_files\\Results"
    //var File = "Results" + "_" + xYear + "_" +  yMonth+ " .txt"

    //ActiveDocument.Sections["Results"].Export(Path + "\\" + File,bqExportFormatText,true)

    yMonth = yMonth + 1

    if (xYear == 2012 && yMonth == 10) {stopIt = "Yes"} else if (yMonth == 12) {stopIt = "Yes"}
    }

    While (stopIt != "Yes")

}

Can someone please help me fix this issue, as I don't understand why it's asking me for the ; 有人可以帮我解决这个问题,因为我不明白为什么它要我提供; , as I thought it wasn't even needed in BRIO document scripts. ,因为我认为BRIO文档脚本中甚至不需要它。

else (yMonth == 12)

Should be: 应该:

else if (yMonth == 12)

And when you indent the code properly, it's easy to notice this error: 当您正确缩进代码时,很容易注意到此错误:

if (xYear == 2012 && yMonth == 10) {
    stopIt = "Yes"
} 
else (yMonth == 12) { // shoule be: else if (yMonth == 12) {
    stopIt = "Yes"
}

Notes: javascript is case sensitive which means 注意:javascript 区分大小写 ,这意味着

  • Do isn't do Do不是do
  • so as for alert instead of Alert 因此对于alert而不是Alert
  • new instead of New new而不是New

But semicolons are not mandatory, you can use them or use not, as you wish. 但是分号不是强制性的,您可以根据需要使用它们,也可以不使用。

Update: 更新:

From looking at the full code you posted, man, it has lots of weird things. 看完您发布的完整代码,伙计,它有很多奇怪的东西。

for (j = 2009; j =  2012; j++)

Should be something like: 应该是这样的:

for (var j = 2009; j <= 2012; j++)
...

You define a variable: 您定义一个变量:

var StopIt = "No"

But use stopIt instead: 但是使用stopIt代替:

stopIt = "Yes"

You should take a javascript course\\tutorial, it's not that difficult to learn, but your code in it's current state is totally broken! 您应该参加javascript课程\\教程,这并不难学习,但是处于当前状态的代码已完全损坏!

For clarity sake, the answer to my question was two-fold, based on gdoron's very helpful and informative answer and Teemu's comment under my original post. 为了清楚起见,我的问题的答案是双重的,基于gdoron的非常有用和翔实的答案以及Teemu在我的原始帖子下的评论。 To sum up the answer I've answered my own question below: 总结一下答案,我已经在下面回答了我自己的问题:

The error in this statement 此语句中的错误

if (xYear == 2012 && yMonth == 10) {stopIt = "Yes"} else (yMonth == 12) {stopIt = "Yes"}

is that is was missing if after the else ifelse之后丢失了

So it should look like this: 所以它应该看起来像这样:

if (xYear == 2012 && yMonth == 10) {
    stopIt = "Yes"
}
else if (yMonth == 12) {
    stopIt = "Yes"
}

The error in this statement 此语句中的错误

var myDate = New Date(xYear, yMonth, 1)

was that New should not have been capitailized. 就是不应该对New进行大写。 So it should be written as: 因此,应将其写为:

var myDate = new Date(xYear, yMonth, 1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM