11 Replies - 783 Views - Last Post: 09 July 2012 - 10:50 PM

#1 plasticmonkey007  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 17-February 11

question: How do I get the number of day and month

Posted 27 June 2012 - 02:37 PM

I am trying to create a script that will take the day and month and change my website's asp.net theme to match the time of year or holiday when someone loads the page. I know how to grab the entire date time but how do i just grab the day/month? here is my code so far its small but this is just after an hour of fiddling around. I have searched the web but can't seem to f ind info on how to exactly do this.
function string themeChange() { 
    strMonth = System.DateTime.Month.ToString();

    if ((c >= 4) && (System.DateTime.Month <= 6)) 
    {
        document.Page.Theme = Spring;
    }
    else if ((strMonth >= 6) && (strMonth <= 9)) 
    {
        document.Page.Theme = Summer;
    }
    else if ((str.Month >= 9) && (strMonth <= 11)) 
    {
        document.Page.Theme = Fall;
    }
    else if ((strMonth >= 11) && (strMonth <= 3)) 
    {
        document.Page.Theme = Winter;
    }
    Else 
    {
        page.theme = default;
    }
    
}


for line 1 i get an error " ( expected" but there is one.
on line 2 i get an error " ; expected" again there is one.
line 22 i get expression expected

when i try to run my webpage i get the error message..
"error CS1519: Invalid token 'string' in class, struct, or interface member declaration"
for line 1.

Is This A Good Question/Topic? 0
  • +

Replies To: question: How do I get the number of day and month

#2 Atli  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3718
  • View blog
  • Posts: 5,990
  • Joined: 08-June 10

Re: question: How do I get the number of day and month

Posted 27 June 2012 - 03:09 PM

I'm confused. Is this supposed to be Javascript? Looks kind of like you copied a C# snippet and just replaced the method visibility keyword with function.

Either way, here are a few things that apply to both:

  • They are case-sensitive. There is a difference between else and Else. (And the latter is incorrect.)

  • On line #4 you use a c variable, but it doesn't seem to exist in that scope. (Is it a global Javascript variable, or a C# class attribute?)

  • On line #12 you use str.Month where I assume you mean strMonth.

  • In all you else if conditionals you compare strMonth to a number, but on line #2 you clearly assign it a string value.

  • In all of your conditional clauses - with the exception of the last else clause - you assign a word to the document.Page.Theme. However they are not quoted, which indicates that they are in fact variables. - What are hey supposed to be? Strings? Variables? If they are variables, where are they defined?

  • In the aforementioned else clause you assign default to page.theme. First of all, the default keyword is reserved. You can not use it as a variable name, and thus can not assign it to variables. (It's used in switch statements.) - Also, why do you set page.theme this time, instead of document.Page.Theme like in the others?

This post has been edited by Atli: 27 June 2012 - 03:12 PM
Reason for edit:: Finished the first sentence.

Was This Post Helpful? 0
  • +
  • -

#3 plasticmonkey007  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 17-February 11

Re: question: How do I get the number of day and month

Posted 27 June 2012 - 03:36 PM

yah i its suppose to be java script and i kept getting an error saying i had no return type listed so i added the public string and its stopped. i caught the the types like the c and the period. I removed the last else. here is the newest version of what i am trying.
public void ChangeTheme()
        {

            if ((intMonth >= 4) && (intMonth <= 6))
            {
                Page.Theme = "Spring";
            }
            else if ((intMonth >= 6) && (intMonth <= 9))
            {
                Page.Theme = "Summer";
            }
            else if ((intMonth >= 9) && (intMonth <= 11))
            {
                Page.Theme = "Fall";
            }
            else if ((intMonth >= 11) && (intMonth <= 3))
            {
                Page.Theme = "Winter";
            }
        }

and it runs and it loads the site but it stays at the default.
Was This Post Helpful? 0
  • +
  • -

#4 plasticmonkey007  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 17-February 11

Re: question: How do I get the number of day and month

Posted 27 June 2012 - 03:43 PM

Sigh i wish i could edit my posts here is the code i am using not what i posted above sorry for the mix up.

public void ChangeTheme()
        {
            intMonth = System.DateTime.Today.Month;

            if ((intMonth >= 4) && (intMonth <= 6))
            {
                Theme = "Spring";
                
            }
            else if ((intMonth >= 6) && (intMonth <= 9))
            {
                Theme = "Summer";
            }
            else if ((intMonth >= 9) && (intMonth <= 11))
            {
                Theme = "Fall";
            }
            else if ((intMonth >= 11) && (intMonth <= 3))
            {
                Theme = "Winter";
            }
        }



I have tried the latter code posted with both Theme and Page.Theme
Was This Post Helpful? 0
  • +
  • -

#5 BetaWar  Icon User is offline

  • #include "soul.h"
  • member icon

Reputation: 1148
  • View blog
  • Posts: 7,143
  • Joined: 07-September 06

Re: question: How do I get the number of day and month

Posted 27 June 2012 - 03:45 PM

Moved to Java.
Was This Post Helpful? 0
  • +
  • -

#6 Atli  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3718
  • View blog
  • Posts: 5,990
  • Joined: 08-June 10

Re: question: How do I get the number of day and month

Posted 27 June 2012 - 04:06 PM

View Postplasticmonkey007, on 27 June 2012 - 10:36 PM, said:

yah i its suppose to be java script and i kept getting an error saying i had no return type listed so i added the public string and its stopped.

OK, I think you are confusing Java and Javascript. Those are two very different things. In Java you need to define return types for methods, but not in Javascript. I don't know what IDE you are using to code this, but if it complains about missing return types and then quiets down when you make that adjustment, you are more than likely using a Java IDE. That won't help you at all when writing Javascript code.

View Postplasticmonkey007, on 27 June 2012 - 10:36 PM, said:

here is the newest version of what i am trying.

That is clearly Java or C# code, not Javascript.

View Postplasticmonkey007, on 27 June 2012 - 10:36 PM, said:

Sigh i wish i could edit my posts

Only members with 16 posts and more are able to edit their posts.
Was This Post Helpful? 0
  • +
  • -

#7 plasticmonkey007  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 17-February 11

Re: question: How do I get the number of day and month

Posted 27 June 2012 - 05:14 PM

*grumbles softly to himself*

The file is a javascript.JS file its not java and its not C#. Apparently instead of helping me with my "Java Script" issue they decided to change what I was talking about, assume I must have been dumb, then re-categorize and move my forum post.

I am creating a "Javascript" file for an ASP.Net webpage that will , on loading, change the sites theme to one matching the season or holiday.

I reiterate it isn't a java file its a Javascript file.

P.S. to be precise the file's name is JScript1.js.
Was This Post Helpful? 0
  • +
  • -

#8 plasticmonkey007  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 17-February 11

Re: question: How do I get the number of day and month

Posted 27 June 2012 - 05:19 PM

I'm Using Visual Studio 2010.
Was This Post Helpful? 0
  • +
  • -

#9 Atli  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3718
  • View blog
  • Posts: 5,990
  • Joined: 08-June 10

Re: question: How do I get the number of day and month

Posted 27 June 2012 - 05:38 PM

View Postplasticmonkey007, on 28 June 2012 - 12:14 AM, said:

Apparently instead of helping me with my "Java Script" issue they decided to change what I was talking about, assume I must have been dumb, then re-categorize and move my forum post.

A lot of people confuse Java and Javascript based on the names. It's an easy mistake to make. Judging by your code examples - which look very much like C# and/or Java - it was the most rational conclusion. - Even if I had been right, I wouldn't have assumed you were dumb, only that you were new to these concepts.

As to why the thread was moved here. BetaWar must have misread your post and assumed you accidentally posted a Java question in the Javascript section. It happens all the time. I'll move it back, now that we are positive that this is indeed Javascript we're dealing with.

View Postplasticmonkey007, on 28 June 2012 - 12:14 AM, said:

I reiterate it isn't a java file its a Javascript file.

P.S. to be precise the file's name is JScript1.js.

OK, so your problem is that you are using incorrect Javascript syntax. I don't know how well VS2010 supports Javascript, but judging by your previous posts it seems it's either overly sensitive to non-errors (like missing return statements from functions, which is in fact entirely optional) or simply trying to parse it like C#. Either way, I suggest you don't rely on it to much.

Javascript functions are defined like this:
function functionName() {
    // Do stuff here.
    // You can return things, or not. There is no need to
    // change the syntax of the function either way.
}


There are no visibility or type keywords used, only the function keyword.


Also, this line in your code seems out of place:
intMonth = System.DateTime.Today.Month;


The System.DateTime type is a part of the .NET framework and is not available to Javascript code. The Javascript Date function provides similar functionality for Javascript code.
Was This Post Helpful? 0
  • +
  • -

#10 plasticmonkey007  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 17-February 11

Re: question: How do I get the number of day and month

Posted 27 June 2012 - 05:48 PM

okay here is the newer code.
function ChangeTheme() 
{
    var Month = System.Date.Today.Month;
    var config = '<%=ConfigurationManager.AppSettings["Theme"] %>'
    if ((intMonth >= 4) && (intMonth <= 6))
        page.theme = 'Spring';
    else if ((intMonth >= 6) && (intMonth <= 9))
        page.theme = 'Summer';
    else if ((intMonth >= 9) && (intMonth <= 11))
        config = 'Fall';
    else if ((intMonth >= 11) && (intMonth <= 3))
        config = 'Winter';
}



during school they were a bit chaotic in the order of languages they taught us and only touched on Javascript briefly. I did get my syntax confused because i must have took too much of a break from coding and it got mixed up in my head. The thing is that in my second post to this topic in the first sentence i state that "I am using java script"

ignore the line that reads "var config = '<%=ConfigurationManager.AppSettings["Theme"] %>'
I was attempting to experiment with some information I got on another site.
Was This Post Helpful? 0
  • +
  • -

#11 Atli  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3718
  • View blog
  • Posts: 5,990
  • Joined: 08-June 10

Re: question: How do I get the number of day and month

Posted 27 June 2012 - 06:18 PM

OK, this would be valid Javascript code. The main problems there are the var Month declaration, as I mentioned before, and the seemingly undefined variables you are using.

Do you define the variables outside the function you posted? The intMonth number and the page object aren't set in the function.


I'm also not very familiar with ASP.NET, so the I'm not sure exactly how you intend to actually change the theme. How does that work? - The Javascript code is executed long after the server-side ASP.NET page has completed it's execution, so affecting changes to that won't work. You'd have to make changes to the client-side code, like setting CSS values or just swapping entire CSS files.


View Postplasticmonkey007, on 28 June 2012 - 12:48 AM, said:

The thing is that in my second post to this topic in the first sentence i state that "I am using java script"

That's true, but that isn't always reliable. People new to Java sometimes don't realize that Javascript is a separate language. They say "java script" when they in fact mean "java code". Separating the words -- "java script" rather than "Javascript" -- tends to be an indication of this.
Was This Post Helpful? 1
  • +
  • -

#12 ahmad_511  Icon User is offline

  • MSX
  • member icon

Reputation: 131
  • View blog
  • Posts: 722
  • Joined: 28-April 07

Re: question: How do I get the number of day and month

Posted 09 July 2012 - 10:50 PM

Hi,
actually all you have to do two things
first is to print the System.Date.Today.Month to the response the same way you did for the ConfigurationManager.AppSettings["Theme"]

second is to assign returned value to the intMonth not to the Month as Atli mentioned before
so, when the server reads this page it will parse and execute the asp tags and output the month value, after that the client will receive the page with the new changes and the intMonth will be assigned the value generated by the server as if it was hard coded

var intMonth = <%= System.Date.Today.Month %>;


note:
the(=) sign after the asp opening tag is a shorthand for response.write()

hope it helps
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1