By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,747 Members | 1,533 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,747 IT Pros & Developers. It's quick & easy.

Form Select - out of order....

P: n/a
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='vbscript'>
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.date.Options
Set Options2 = Document.all.todate.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(StrDate,"from " & StrDate)
Options2.Add Window.Option(StrDate,"to " & StrDate)
TheDate = TheDate + 7

StrDate2 = "Thursday " & Right("0" & Day(TheDate2),2) & "/" &
Right("0" & Month(TheDate2),2) & "/" & Year(TheDate2)
Options.Add Window.Option(StrDate2,"from " & StrDate2)
Options2.Add Window.Option(StrDate2,"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.

Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Lee
da***@scene-double.co.uk said:

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='vbscript'> 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


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

Jul 23 '05 #2

P: n/a
JRS: In article <11*********************@l41g2000cwc.googlegroups. com>,
dated Wed, 2 Feb 2005 08:03:35, seen in news:comp.lang.javascript,
da***@scene-double.co.uk posted :
I have a form with 2 select objects which are not linked together in
any way.
The list exactly the same information.
Meaning absent.
The code that generates the data is:

_________________________________________

<SCRIPT language='vbscript'>
Doubly deprecated. Should be <script type="text/javascript"> here
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.date.Options
Set Options2 = Document.all.todate.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(StrDate,"from " & StrDate)
Options2.Add Window.Option(StrDate,"to " & StrDate)
TheDate = TheDate + 7

StrDate2 = "Thursday " & Right("0" & Day(TheDate2),2) & "/" &
Right("0" & Month(TheDate2),2) & "/" & Year(TheDate2)
Options.Add Window.Option(StrDate2,"from " & StrDate2)
Options2.Add Window.Option(StrDate2,"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

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(TheDate2),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.date .

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='vbscript'>

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='vbscript'>

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='vbscript'>

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.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.