Missing semicolon in JavaScript / JScript

1k views Asked by At

I have the following code that I am writing inside 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.

Anyway, I am getting syntax Script(line number) missing; before statement error on the following lines:

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.

2

There are 2 answers

8
gdoron On BEST ANSWER
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

  • Do isn't do
  • so as for alert instead of Alert
  • new instead of 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 = "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!

2
Scott Holtzman On

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. 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

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. So it should be written as:

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