Thread: Wrong Date

    #1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    Italy
    Posts
    63
    Rep Power
    11

    Red face Alternate Weeks - Please, help someone :(


    Hello, i just used this code:
    Code:
    procedure TForm1.TBXLink1Click(Sender: TObject);
    begin
    ListBox1.Clear;
    ListBox1.Items.Add(' English');
    ListBox1.Items.Add(' RE');
    ListBox1.Items.Add(' Geography');
    ListBox1.Items.Add(' Maths');
    ListBox1.Items.Add(' English');
    ListBox1.Items.Add(' Science');
    end;
    
    procedure TForm1.TBXLink2Click(Sender: TObject);
    begin
    ListBox1.Clear;
    ListBox1.Items.Add(' PE');
    ListBox1.Items.Add(' French');
    ListBox1.Items.Add(' Maths');
    ListBox1.Items.Add(' Tech');
    ListBox1.Items.Add(' Science');
    ListBox1.Items.Add(' Art');
    end;
    ...
    procedure TForm1.FormCreate(Sender: TObject);
    var
    C: HCURSOR;
    myDate : TDateTime;
    day    : array[1..7] of string;
    formattedDateTime: string;
    begin
    C := LoadCursor(0, IDC_HAND);
      if C <> 0 then Screen.Cursors[crHandPoint] := C;
    myDate := Date;
    
      day[1] := 'Monday';
      day[2] := 'Tuesday';
      day[3] := 'Wednesday';
      day[4] := 'Thursday';
      day[5] := 'Friday';
      day[6] := 'Saturday';
      day[7] := 'Sunday';
    
    DateTimeToString(formattedDateTime, 'dd/mm/yyyy', myDate);
    TBXLabel3.Caption := formattedDateTime;
    
    if (DayOfTheWeek(myDate)=1) then
    begin
    TBXLink1Click(Sender);
    ...
    ...
    end.
    To obtain the different items in the ListBox Each Day. now i need to make an alternate weeks, for example:

    Week 1 day 1 i got
    xxx
    xxx
    xxx
    ...
    Week1 day 5 i got
    xxx
    xxx
    ...
    now switching to the next week

    Week2 day 1 i got
    xxx
    xxx....
    till day5

    How is it possible? I mean How can i add an internal counter to the app that counta the weeks, so if the week 1 is finished, it begins to display the days of the week 2 and so on ?
    Last edited by ChromeX; May 2nd, 2004 at 11:38 AM.
  2. #2
  3. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,595
    Rep Power
    4207
    Yes. You forgot to initilialize myDate.
    Code:
    procedure TForm1.FormCreate(Sender: TObject);
    var
    myDate : TDateTime;
    day    : array[1..7] of string;
    formattedDateTime: string;
    begin
       myDate := Now;
       DateTimeToString(formattedDateTime, 'dddd d of mmmm yyyy', myDate);
      ShowMessage('dddd d of mmmm yyyy = '+formattedDateTime);
    ...
    ...
    end;
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    Italy
    Posts
    63
    Rep Power
    11
    Scorpions4ever: thank you for your reply, i dont it already, so i have modified my topic... could you help me with that one issue? read the 1st post
  6. #4
  7. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,595
    Rep Power
    4207
    I'm not certain exactly what you want here. Could you please explain what the output should look like.
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    Italy
    Posts
    63
    Rep Power
    11
    Originally Posted by Scorpions4ever
    I'm not certain exactly what you want here. Could you please explain what the output should look like.
    well, I got the app that has displays the different strings in the listbox each day for one week; when the 1st week will be finished, the 2nd week will be displayed items in the listbox but different from the ones from the 1st week; when the 2nd week will be finished, it will display again the items of the 1st week...Here is the screenshots:
    http://chrome.topcities.com/scr1.gif
    http://chrome.topcities.com/scr2.gif

    Could you understand me now?
  10. #6
  11. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,595
    Rep Power
    4207
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  12. #7
  13. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    Italy
    Posts
    63
    Rep Power
    11
    uhm, it's not exactly what i'm searchig for I meaned to use only 2 weeks every month for ex Week1 has the days (1-7 with any items in the listbox), then goes the Week2 with the same days but different items in the listbox, then again the Week1 and then the week2. Finished the month, new one begins and the Week1 starts again, the the Week2 etc... The example you gave me on the sites has just the week numbers for the whole year.
    In this list ( i need it for school)
    I have maths on monday, the week after on monday i might not have maths because its a different week for eg
    Monday Week 1:
    Maths, PE, Science etc
    Monday week 2:
    Art, georgraphy, ICT
    and it alternates like that.
    Here is the PAS unit if you'd like to see it:
    Attached Files
    Last edited by ChromeX; May 4th, 2004 at 09:44 AM.
  14. #8
  15. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,595
    Rep Power
    4207
    Ok, I think I'm beginning to understand what you need. The problem is very simple then. All you need to do is figure out the week number of the year and then do a modulo division by 2 on that number. This will give you either a 1 or a 0 depending on whether it is an odd or an even week number. You can use DecodeDateWeek and as a bonus, it also gives you the day of the week, so you don't need to call DayOfTheWeek multiple times.
    Code:
    private
        { Private declarations }
        myDate: TDateTime;
        AYear, AWeek, ADay, WeekNum : Word;
    ....
    ...
    
    procedure TForm1.FormCreate(Sender: TObject);
    begin
        ....
        myDate := Now;
        DecodeDateWeek(myDate, AYear, AWeek, ADay);
        WeekNum := AWeek Mod 2; // WeekNum is either 0 or 1
        ....
        if (ADay == 1) then
        begin
            TBXLink1Click(Sender);
            Form1.Caption := ver+' - '+day[DayOfTheWeek(myDate)];
            TBXLink1.Font.Color := clRed;
            TBXLink2.Font.Color := clHotLight;
             ....
        end
        else if (ADay = 2) then
        begin
        ....
        end
    end;
    
    procedure TForm1.TBXLink1Click(Sender: TObject);
    begin
      ListBox1.Clear;
      if (WeekNum = 0) then
      begin
        ListBox1.Items.Add(' English');
        ListBox1.Items.Add(' RE');
        ListBox1.Items.Add(' Geography');
        ListBox1.Items.Add(' Maths');
        ListBox1.Items.Add(' English');
        ListBox1.Items.Add(' Science');
      end
      else begin
        ListBox1.Items.Add(' Geography');
        ListBox1.Items.Add(' English');
        ListBox1.Items.Add(' English');
        ListBox1.Items.Add(' RE');
        ListBox1.Items.Add(' Science');
        ListBox1.Items.Add(' Maths');
      end
    end;
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  16. #9
  17. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    Italy
    Posts
    63
    Rep Power
    11
    thank you! that's what i was searching for!

IMN logo majestic logo threadwatch logo seochat tools logo