Form Select - out of order....

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • david@scene-double.co.uk

    #1

    Form Select - out of order....

    Hi,

    I have a form with 2 select objects which are not linked together in
    any way. The list exactly the same information.

    The code that generates the data is:

    _______________ _______________ ___________

    <SCRIPT language='vbscr ipt'>
    Sub Window_Onload
    Dim TheDate
    Dim Count
    Dim Options
    Dim Options2


    TheDate2 = Date + vbThursday - WeekDay(Date)
    TheDate = Date + vbTuesday - WeekDay(Date)


    If TheDate < Date Then TheDate = TheDate +7
    Set Options = Document.all.da te.Options
    Set Options2 = Document.all.to date.Options

    For Count = 1 To 20-1
    StrDate = "Tuesday " & Right("0" & Day(TheDate),2) & "/" &
    Right("0" & Month(TheDate), 2) & "/" & Year(TheDate)
    Options.Add Window.Option(S trDate,"from " & StrDate)
    Options2.Add Window.Option(S trDate,"to " & StrDate)
    TheDate = TheDate + 7

    StrDate2 = "Thursday " & Right("0" & Day(TheDate2),2 ) & "/" &
    Right("0" & Month(TheDate2) ,2) & "/" & Year(TheDate2)
    Options.Add Window.Option(S trDate2,"from " & StrDate2)
    Options2.Add Window.Option(S trDate2,"to " & StrDate2)
    TheDate2 = TheDate2 + 7
    Next
    End Sub

    </script>

    _______________ _______________ _______________ _

    The information is correct, except that every now and again the Tusdays
    & Thursdays are wrong way around depending on the current date, i.e.

    it should display:

    Thursday 03/02/2005
    Tuesday 08/02/2005

    looping continuously with Tuesdays & Thursdays in the correct date
    order.

    I seem to get

    Tuesday 08/02/2005
    Thursday 03/02/2005

    How can I correct this code so that no matter what the actual date is,
    the data is always in the correct order ?
    Appreciate your advice



    David.

  • Lee

    #2
    Re: Form Select - out of order....

    david@scene-double.co.uk said:[color=blue]
    >
    >Hi,
    >
    >I have a form with 2 select objects which are not linked together in
    >any way. The list exactly the same information.
    >
    >The code that generates the data is:
    >
    >______________ _______________ ____________
    >
    ><SCRIPT language='vbscr ipt'>[/color]
    [color=blue]
    >How can I correct this code so that no matter what the actual date is,
    >the data is always in the correct order ?
    >Appreciate your advice[/color]

    My advice is to ask in a vbscript group, rather than javascript.
    Sorry.

    Comment

    • Dr John Stockton

      #3
      Re: Form Select - out of order....

      JRS: In article <1107360215.722 045.70930@l41g2 000cwc.googlegr oups.com>,
      dated Wed, 2 Feb 2005 08:03:35, seen in news:comp.lang. javascript,
      david@scene-double.co.uk posted :
      [color=blue]
      >I have a form with 2 select objects which are not linked together in
      >any way.
      > The list exactly the same information.[/color]

      Meaning absent.
      [color=blue]
      >The code that generates the data is:
      >
      >______________ _______________ ____________
      >
      ><SCRIPT language='vbscr ipt'>[/color]

      Doubly deprecated. Should be <script type="text/javascript"> here
      [color=blue]
      >Sub Window_Onload
      >Dim TheDate
      >Dim Count
      >Dim Options
      >Dim Options2
      >
      >
      >TheDate2 = Date + vbThursday - WeekDay(Date)
      >TheDate = Date + vbTuesday - WeekDay(Date)
      >
      >
      >If TheDate < Date Then TheDate = TheDate +7
      >Set Options = Document.all.da te.Options
      >Set Options2 = Document.all.to date.Options
      >
      >For Count = 1 To 20-1
      >StrDate = "Tuesday " & Right("0" & Day(TheDate),2) & "/" &
      >Right("0" & Month(TheDate), 2) & "/" & Year(TheDate)
      >Options.Add Window.Option(S trDate,"from " & StrDate)
      >Options2.Add Window.Option(S trDate,"to " & StrDate)
      >TheDate = TheDate + 7
      >
      >StrDate2 = "Thursday " & Right("0" & Day(TheDate2),2 ) & "/" &
      >Right("0" & Month(TheDate2) ,2) & "/" & Year(TheDate2)
      >Options.Add Window.Option(S trDate2,"from " & StrDate2)
      >Options2.Add Window.Option(S trDate2,"to " & StrDate2)
      >TheDate2 = TheDate2 + 7
      >Next
      >End Sub
      >
      ></script>
      >
      >______________ _______________ _______________ __
      >
      >The information is correct, except that every now and again the Tusdays
      >& Thursdays are wrong way around depending on the current date, i.e.
      >
      >it should display:
      >
      >Thursday 03/02/2005
      >Tuesday 08/02/2005
      >
      >looping continuously with Tuesdays & Thursdays in the correct date
      >order.
      >
      >I seem to get
      >
      >Tuesday 08/02/2005
      >Thursday 03/02/2005
      >
      >How can I correct this code so that no matter what the actual date is,
      >the data is always in the correct order ?
      >Appreciate your advice[/color]


      Code should be written and posted with indentation to show the intended
      structure.

      Lines should not be allowed to be broken by the posting agent; you
      should present us with code that can be read and tested directly, with
      only the original faults.


      For Right("0" & Day(TheDate2),2 )
      Right(100+Day(T heDate2),2) ' is better, at least for me

      Date should be called only once; it is comparatively expensive, and can
      change.

      TheDate2 is not declared.

      Variable names should be short or meaningful, or both.

      My system does not believe document.all.da te .

      You seem to be saying that the first two dates (among others) are in the
      wrong order. So don't bother us with the loop.

      The following "Web page" suffices to show us what is needed to be shown
      :-


      <SCRIPT language='vbscr ipt'>

      Dim TheDate, TheDate2

      TheDate2 = Date + vbThursday - WeekDay(Date)
      TheDate = Date + vbTuesday - WeekDay(Date)

      If TheDate < Date Then TheDate = TheDate +7

      document.write TheDate, " ", TheDate2

      </script>


      The following transform is more illustrative :-


      <SCRIPT language='vbscr ipt'>

      Dim Tue, Thu, Dt

      Dt = Date
      for J = 0 to 15
      D = Dt + J
      Thu = D + vbThursday - WeekDay(D)
      Tue = D + vbTuesday - WeekDay(D)

      If Tue < D Then Tue = Tue +7 ' ###

      document.write D, " - ", Thu, " - ", Tue, "<br>"
      next
      </script>

      and the line marked ### looks implausible;
      if Tue < Thu makes more sense



      Now


      <SCRIPT language='vbscr ipt'>

      Dim Tue, Thu, Dt, SoW

      Dt = Date
      for J = 0 to 15
      D = Dt + J

      SoW = D - WeekDay(D)
      Thu = SoW + vbThursday
      Tue = SoW + vbTuesday
      If Tue < Thu Then Tue = Tue +7

      document.write D, " - ", Thu, " - ", Tue, "<br>"
      next
      </script>

      gives me

      2005-02-03 - 2005-02-03 - 2005-02-08
      2005-02-04 - 2005-02-03 - 2005-02-08
      2005-02-05 - 2005-02-03 - 2005-02-08
      2005-02-06 - 2005-02-10 - 2005-02-15
      2005-02-07 - 2005-02-10 - 2005-02-15
      2005-02-08 - 2005-02-10 - 2005-02-15
      2005-02-09 - 2005-02-10 - 2005-02-15
      2005-02-10 - 2005-02-10 - 2005-02-15
      2005-02-11 - 2005-02-10 - 2005-02-15
      2005-02-12 - 2005-02-10 - 2005-02-15
      2005-02-13 - 2005-02-17 - 2005-02-22
      2005-02-14 - 2005-02-17 - 2005-02-22
      2005-02-15 - 2005-02-17 - 2005-02-22
      2005-02-16 - 2005-02-17 - 2005-02-22
      2005-02-17 - 2005-02-17 - 2005-02-22
      2005-02-18 - 2005-02-17 - 2005-02-22



      You need to learn how to test misbehaving code - always simplify it,
      testing continually, until the solution is obvious (always keep the last
      failing version). Then, with the new understanding, the original can
      probably be fixed.

      --
      © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
      <URL:http://www.jibbering.c om/faq/> JL/RC: FAQ of news:comp.lang. javascript
      <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
      <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

      Comment

      Working...