date and external text files

  • brentjlaf
  • Student
  • Student
  • User avatar
  • Posts: 67

Post 3+ Months Ago

I am trying to get external text files to load depending on what day of the week it is,

Code: [ Select ]
var dateNow = new Date();

if (dateNow=!Sun) {
    myData = new LoadVars();
    myData.onLoad = function() {
        myText_txt.text = this.myVariable;
    };
    myData.load("sunday.txt");
}


if (dateNow=!Mon) {
    myData = new LoadVars();
    myData.onLoad = function() {
        myText_txt.text = this.myVariable;
    };
    myData.load("monday.txt");
}


if (dateNow=!Tue) {

    myData = new LoadVars();
    myData.onLoad = function() {
        myText_txt.text = this.myVariable;
    };
    myData.load("tuesday.txt");
}

if (dateNow=!Wed) {
    myData = new LoadVars();
    myData.onLoad = function() {
        myText_txt.text = this.myVariable;
    };
    myData.load("wednesday.txt");
}

if (dateNow=!Thu) {
    myData = new LoadVars();
    myData.onLoad = function() {
        myText_txt.text = this.myVariable;
    };
    myData.load("thursday.txt");
}


if (dateNow=!Fri) {
    myData = new LoadVars();
    myData.onLoad = function() {
        myText_txt.text = this.myVariable;
    };
    myData.load("friday.txt");
}

if (dateNow=!Sat) {
    myData = new LoadVars();
    myData.onLoad = function() {
        myText_txt.text = this.myVariable;
    };
    myData.load("saturday.txt");
}
  1. var dateNow = new Date();
  2. if (dateNow=!Sun) {
  3.     myData = new LoadVars();
  4.     myData.onLoad = function() {
  5.         myText_txt.text = this.myVariable;
  6.     };
  7.     myData.load("sunday.txt");
  8. }
  9. if (dateNow=!Mon) {
  10.     myData = new LoadVars();
  11.     myData.onLoad = function() {
  12.         myText_txt.text = this.myVariable;
  13.     };
  14.     myData.load("monday.txt");
  15. }
  16. if (dateNow=!Tue) {
  17.     myData = new LoadVars();
  18.     myData.onLoad = function() {
  19.         myText_txt.text = this.myVariable;
  20.     };
  21.     myData.load("tuesday.txt");
  22. }
  23. if (dateNow=!Wed) {
  24.     myData = new LoadVars();
  25.     myData.onLoad = function() {
  26.         myText_txt.text = this.myVariable;
  27.     };
  28.     myData.load("wednesday.txt");
  29. }
  30. if (dateNow=!Thu) {
  31.     myData = new LoadVars();
  32.     myData.onLoad = function() {
  33.         myText_txt.text = this.myVariable;
  34.     };
  35.     myData.load("thursday.txt");
  36. }
  37. if (dateNow=!Fri) {
  38.     myData = new LoadVars();
  39.     myData.onLoad = function() {
  40.         myText_txt.text = this.myVariable;
  41.     };
  42.     myData.load("friday.txt");
  43. }
  44. if (dateNow=!Sat) {
  45.     myData = new LoadVars();
  46.     myData.onLoad = function() {
  47.         myText_txt.text = this.myVariable;
  48.     };
  49.     myData.load("saturday.txt");
  50. }
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • graphixboy
  • Control + Z
  • Mastermind
  • User avatar
  • Posts: 1828
  • Loc: In the Great White North

Post 3+ Months Ago

well I see two problems off the top. First the Date object returns a number not text for the date so Sunday = 0, Monday = 1, etc. Second problem is that your if statements won't work. "=!" isn't valid for what you wrote you want "==" (is equal to) or "!=" (is not equal to). You'll probably have better luck with a case statement instead of a chain of if/else statements.

[code]
var currDate = New Date(); // get date from computer
var currDay = currDate.getDay(); // get day of week from date
var myData = new LoadVars(); // new load vars object

myData.onLoad = function(){
myText_txt.text = this.toString();
}

switch (currDay) {
case 0 :
myData.load("sunday.txt");
break;
case 1 :
myData.load("monday.txt");
break;
case 2 :
myData.load("tuesday.txt");
break;
case 3 :
myData.load("wednesday.txt");
break;
case 4 :
myData.load("thursday.txt");
break;
case 5 :
myData.load("friday.txt");
break;
case 6 :
myData.load("saturday.txt");
break;

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 4 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.