473,396 Members | 1,767 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Convert from VBScript...

Hi,

I have a script in one of my .asp pages which I think is written in
VBScript (I did not write it). I would like to know how to do the
following in Javascript.

Have a combo on my page which basically lists all the following
Tusdays & Thursdays dates, up to a set qty, i.e. 20 in the list.

E.g. todays date is 2nd August, so the combo would list 20 lines of:

Tusday 3rd August
Thursday 5th August
Tusday 10th August
Thursday 12 August

and so on for another 16 lines...

How is this possible ?

__________________________________________

The code I have at the mo has been tweeked by myself, but I can only
get the combo to list the Tuesdays first, then all the Thursdays, not
all in date order.

________________

<SCRIPT language='vbscript'>
Sub Window_Onload
Dim TheDate
Dim Count
Dim Options
TheDate = Date + vbTuesday - WeekDay(Date)
TheDate2 = Date + vbThursday - WeekDay(Date)
If TheDate < Date Then TheDate = TheDate + 7
Set Options = Document.All.Date.Options
For Count = 1 To 20
StrDate = "Tuesday " & Right("0" & Day(TheDate),2) & "/" &
Right("0" &_
Month(TheDate),2) & "/" & Year(TheDate)
Options.Add Window.Option(StrDate,"for " & StrDate)
TheDate = TheDate + 7
Next

If TheDate2 < Date Then TheDate2 = TheDate2 + 7
Set Options = Document.All.Date.Options
For Count = 1 To 20
StrDate2 = "Thursday " & Right("0" & Day(TheDate2),2) & "/" &
Right("0" &_
Month(TheDate2),2) & "/" & Year(TheDate2)
Options.Add Window.Option(StrDate2,"for " & StrDate2)
TheDate2 = TheDate2 + 7
Next
End Sub
</script>

_______________________________

Hope you can help ?
David
Jul 23 '05 #1
6 3073
In article <c1**************************@posting.google.com >, david@scene-
double.co.uk enlightened us with...
Hi,

I have a script in one of my .asp pages which I think is written in
VBScript (I did not write it). I would like to know how to do the
following in Javascript.

Have a combo on my page which basically lists all the following
Tusdays & Thursdays dates, up to a set qty, i.e. 20 in the list.
<snip>

The code is also IE only.

The code I have at the mo has been tweeked by myself, but I can only
get the combo to list the Tuesdays first, then all the Thursdays, not
all in date order.


I checked this in IE. Should work in Netscape, too. Check other browsers as
needed. Watch for word-wrap.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title> New Document </title>
<script type="text/javascript" language="javascript">
function formatDate(t_date, format)
{
/* t_date is expected to be a Date() and format is a string */

var r_date = null; /* string to return */

/* add more formats as desired */
switch (format)
{
case ("mm/dd/yyyy"):
tmp = t_date.getMonth()+1;
tmp = tmp<10?"0"+tmp:tmp;
r_date = tmp+"/";
tmp = t_date.getDate();
tmp = tmp<10?"0"+tmp:tmp;
r_date += tmp+"/"+t_date.getFullYear();
break;
default:
alert("That is not a valid format");
}
return r_date;
}

function addDays(t_date,days)
{
return new Date(t_date.getTime() + days*24*60*60*1000);
}

function fillIt()
{
var s = document.forms["f1"].elements["date"];
var o;
var theDate = new Date();
var i;

for (i=0; i<20; i++)
{
/* if this is a Tuesday (2) or Thursday (4), put in option, else add a
day and check again */
while (theDate.getDay() != 2 && theDate.getDay() != 4)
theDate = addDays(theDate,1);
/* we get here, it's either Tursday or Thursday - write option,
increment, and loop */
tmp = formatDate(theDate, "mm/dd/yyyy");
o = new Option(tmp, tmp);
s.options[i] = o;
theDate = addDays(theDate,1);
}
}
</script>
</head>

<body onLoad = "fillIt()">
<form name="f1" id="f1">
<select name="date" id="date"></select>
</form>
</body>
</html>

--
--
~kaeli~
When you choke a smurf, what color does it turn?
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2
ben
david, try something like:
<script>

function FillThemDateOptions()
{
var dateSelector = document.form2.JSDate;
var maxOptions = 20;
var today = new Date();

for(var i=0;i<((maxOptions*7)/2);i+=7)
{
var tueDate =
new Date(today.getYear(), today.getMonth(),
today.getDate()+i+1);
var thuDate =
new Date(today.getYear(), today.getMonth(),
today.getDate()+i+3);

dateSelector.options.add(FormatTheDateAsASelectOpt ionThing(tueDate));
dateSelector.options.add(FormatTheDateAsASelectOpt ionThing(thuDate));
}
}

function FormatTheDateAsASelectOptionThing(d)
{
var aWeekDayNames =
new Array('Sunday','Monday','Tuesday','Wednesday','Thu rsday','Friday','Saturday');

var sText =
aWeekDayNames[d.getDay()] +
' ' +
((d.getDate()<10)?'0':'') +
d.getDate() +
'/' +
((d.getMonth()<10)?'0':'') +
d.getMonth() +
'/' +
d.getFullYear();

var sValue = 'for ' + sText;

return new Option(sText, sValue);
}

window.onload = FillThemDateOptions;

</script>

irt.org have a load of FAQs on javascript:
http://developer.irt.org/script/date.htm give them a try for some
ideas.

ben
Jul 23 '05 #3
JRS: In article <MP************************@nntp.lucent.com>, dated
Mon, 2 Aug 2004 11:32:31, seen in news:comp.lang.javascript, kaeli
<ti******@NOSPAM.comcast.net> posted :
In article <c1**************************@posting.google.com >, david@scene-
double.co.uk enlightened us with...
I have a script in one of my .asp pages which I think is written in
VBScript (I did not write it). I would like to know how to do the
following in Javascript.

Have a combo on my page which basically lists all the following
Tusdays & Thursdays dates, up to a set qty, i.e. 20 in the list.


You've not specified what happens if today is Tue or Thu, unless we take
"following" literally.

If the number is always to be even, one can take advantage of the fact
that the duration will always be a little over 10 weeks.

I checked this in IE. Should work in Netscape, too. Check other browsers as
needed. Watch for word-wrap.
But did you check it in February or September at sensitive times of day?
Ten weeks from now it is still Summer.

function addDays(t_date,days)
{
return new Date(t_date.getTime() + days*24*60*60*1000);
}

There are circumstances in which that can be correct; except that
there's no point in typing 24*60*60*1000 when 864e5 will suffice. That
code may be one of them; but if a Sunday were wanted a special one would
ISTM be missed or duplicated.
function fillIt() var theDate = new Date(); theDate = addDays(theDate,1);

In late Winter, if the code is started late enough in the day, a day
will be missed; and vice versa for early Summer morning.

Function addDays could be

function addDays(t_date, days) { // but alters t_date
t_date.setDate(t_date.getDate() + days ) }

Alternatively, use setHours(12) early on.


The following will write the desired dates :-
D = new Date() ; K = 20 ;
while (K) {
D.setDate(D.getDate()+1) // AddADay
X = D.getDay()
if ( X==2 || X==4 ) document.write(D, ' ', K--, '<br>')
}

If speed matters, however, find today's day-of-week, calculate the
offset to the Tue/Thu before the next, add it, then add 2 & 5
appropriately 20 times.

Otherwise, if the dates are to be used in ISO-8601 form such as
"2004-08-02 Mon" then one can stick first the Tuesdays then the
Thursdays in an array, and sort it.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> JL / RC : FAQ for 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 #4
Ben,

Thanks for that, but I cannot get your script working with a form....

</script>
</head>

<body onLoad = "FillThemDateOptions()">
<form name="form2" id="form2">
<select name="JSDate" id="JSDate"></select>
</form>
</body>
</html>
I know this simple, but I must be missing a trick here ?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #5
Hi,

Just to let you know that I suddenly had a brainwave with my original
code and changed it to:

<SCRIPT language='vbscript'>
Sub Window_Onload
Dim TheDate
Dim Count
Dim Options
TheDate = Date + vbTuesday - WeekDay(Date)
TheDate2 = Date + vbThursday - WeekDay(Date)
If TheDate < Date Then TheDate = TheDate + 7
Set Options = Document.All.Date.Options
For Count = 1 To 20
StrDate = "Tuesday " & Right("0" & Day(TheDate),2) & "/" &
Right("0" &_
Month(TheDate),2) & "/" & Year(TheDate)
Options.Add Window.Option(StrDate,"for " & StrDate)
TheDate = TheDate + 7
StrDate2 = "Thursday " & Right("0" & Day(TheDate2),2) & "/" & Right("0"
&_
Month(TheDate2),2) & "/" & Year(TheDate2)
Options.Add Window.Option(StrDate2,"for " & StrDate2)
TheDate2 = TheDate2 + 7
Next

End Sub
</script>

Thanks again for all your help and code. I'm testing your different
versions now.

David.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 23 '05 #6
JRS: In article <41*********************@news.newsgroups.ws>, dated
Tue, 3 Aug 2004 15:45:00, seen in news:comp.lang.javascript, David
Gordon <da***@scene-double.co.uk> posted :
Hi,

Just to let you know that I suddenly had a brainwave with my original
code and changed it to:

<SCRIPT language='vbscript'>
Sub Window_Onload
Dim TheDate
Dim Count
Dim Options
TheDate = Date + vbTuesday - WeekDay(Date)
TheDate2 = Date + vbThursday - WeekDay(Date)
In principle, one should call only one of Date, Time, Now on any given
page (unless one wishes to show the passage of time), since they are not
constant functions. In this case, that's unlikely to matter.
If TheDate < Date Then TheDate = TheDate + 7
If TheDate2 < Date ... ' also?

Alternatively, Date + (7 + vbTuesday - WeekDay(Date)) mod 7
or Date + (6 + vbTuesday - WeekDay(Date)) mod 7 + 1
Set Options = Document.All.Date.Options
For Count = 1 To 20
Twice as many as I thought you wanted.
StrDate = "Tuesday " & Right("0" & Day(TheDate),2) & "/" &
or Right(100 + Day(TheDate), 2) . IMHO,
that should be made a function, for legibility and modularity.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


And how do you propose to transfer that reward to those who answer your
questions? <URL:http://www.merlyn.demon.co.uk/index.htm#Spon>.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> JL / RC : FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/vb-dates.htm> VB maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Bill | last post by:
I need to convert a variable, nNum, into a two-character string. nNum is always less than 100. If nNum is 0, the string needs to be "00", if it's 1, it needs to be "01", if it's 34, it needs to...
4
by: Dean G | last post by:
I need to compare two values. one from a text field 'bid' and the other from a field in an sql server database 'maxbid'. The problem is the column in the database has decimal as its data type...
2
by: davidgordon | last post by:
Hi, I have some pages with this VBScript code, which obviously does not work in Firefox. How can I convert this to Javascript in order for my web page to work in Firefox ? It basically fills a...
5
by: Mike | last post by:
I have an outlook application that I'm thinking about converting to VB.NET. Would it be easier to convert the code over or just re-write the application? thanks
4
by: CJ | last post by:
Hi I'm trying to send email via a c# app, and I've come across various ways to do it, but the way that seems best given my constraints is this little vbscript: Dim theApp, theNameSpace,...
28
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
2
by: LostnCode | last post by:
Hi, Can anyone help, I need to convert his code from vbscript to sharp C# for use with ASP.Net2.0? This is my first time using a forum. I don't know anything about either coding language so...
2
by: teecee99 | last post by:
This may be a dumb question but here goes. I have a retail web-site and back end order processing system built with vbscript that is currently hosted on GoDaddy on a shared hosting platform (i.e....
0
by: pyar | last post by:
Hi guys, I am trying since so long to resolve my query as how to convert VBScript to DLL(.NET DLL).I browsed thru net but no use.So please could anyone of you guys help me out by giving a sample...
1
by: pyar | last post by:
Hi guys, I am trying since so long to resolve my query as how to Convert VBScript to DLL(.NET DLL).I browsed thru net but no use.So please could anyone of you guys help me out by giving a sample...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.